LineBreaks, newline and AJAX

Bugs will be moved here once resolved.

Post » Tue Jun 26, 2012 8:01 pm

Hi,

To find linebreaks (newline) on a project file I called via the AJAX object, I had to modify the plugin this way:

[code]     Exps.prototype.LastData = function (ret)
     {
    var str = this.lastData.replace(/\r?\n|\r/g,"\n");
          ret.set_string(str);
     };[/code]
Dunno if I did it well enough but it seems that newline is only an alias of the js "\n"
But in windows I think linebreaks are a "\r\n" and the tokencount function gave me an extra character from the same string when I loaded it from a project file.
Yann2012-06-26 20:01:43
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu Jun 28, 2012 5:20 pm

Hmm... I'm worried this could subtly break other things. I've implemented the fix for the next build though, we'll see how it goes.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue Jul 03, 2012 5:23 am

hmm I think you didn't implement it completely.
doing data.replace("\r\n","\n"); only replace the first occurence.
it seems you need the g flag for a global replacement as specified here
data.replace(/\r\n/g,"\n"); works
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Jul 03, 2012 11:31 am

Huh, that's crazy. I didn't know Javascript's replace() only did the first occurrence when you use strings. Fixed for next build (won't changelog since it's very minor)
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 3 guests