mirror of
https://github.com/scratchfoundation/scratch-flash.git
synced 2024-12-04 21:21:06 -05:00
Fixed importing files with CRLF or CR line endings
Also added final LF to exported file. This is the convention.
This commit is contained in:
parent
b858d029dc
commit
ff6be6a5d1
1 changed files with 4 additions and 9 deletions
|
@ -139,9 +139,7 @@ public class ListWatcher extends Sprite {
|
|||
}
|
||||
function fileLoadHandler(event:Event):void {
|
||||
var s:String = file.data.readUTFBytes(file.data.length);
|
||||
var delimiter:String = '\n';
|
||||
if (s.indexOf(delimiter) < 0) delimiter = '\r';
|
||||
importLines(removeTrailingEmptyLines(s.split(delimiter)));
|
||||
importLines(removeTrailingEmptyLines(s.split(/\r\n|[\r\n]/)));
|
||||
}
|
||||
var fileList:FileReferenceList = new FileReferenceList();
|
||||
var file:FileReference;
|
||||
|
@ -154,9 +152,7 @@ public class ListWatcher extends Sprite {
|
|||
|
||||
private function exportList():void {
|
||||
var file:FileReference = new FileReference();
|
||||
var s:String = '';
|
||||
for each (var el:* in contents) s += el + '\n';
|
||||
if (s.length > 0) s = s.slice(0, s.length - 1); // remove final '\n'
|
||||
var s:String = contents.join('\n') + '\n';
|
||||
file.save(s, listName + '.txt');
|
||||
}
|
||||
|
||||
|
@ -167,9 +163,8 @@ public class ListWatcher extends Sprite {
|
|||
//------------------------------
|
||||
|
||||
private function removeTrailingEmptyLines(lines:Array):Array {
|
||||
var i:int = lines.length - 1;
|
||||
while ((i > 0) && (lines[i].length == 0)) i--;
|
||||
return lines.slice(0, i + 1);
|
||||
while (lines.length && !lines[lines.length - 1]) lines.pop();
|
||||
return lines;
|
||||
}
|
||||
|
||||
private function importLines(lines:Array):void {
|
||||
|
|
Loading…
Reference in a new issue