fix issue #704, replacing variables in gcode file damaging line around offset 2048

I verified #704 and tested my fix. It's not as fast as the 2048 byte variant, but I think it shouldn't be a problem with current hardware (enough ram to read the whole file and fast cpus).
Can someone tell me how big really large gcode file can be?
I have no experience with very big models.