Skip to content

Commit 668b8a1

Browse files
committed
LIST, MERGE, DELETE: Split only at lines starting with numbers
1 parent 61e8abb commit 668b8a1

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

Controller.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,32 @@ Controller.prototype = {
561561
}
562562
},
563563

564+
splitLines: function (input) {
565+
var lines = [],
566+
lineParts = input.split(/^(\s*\d+)/m), // get numbers starting at the beginning of a line
567+
i, number, content;
568+
569+
if (lineParts[0] === "") {
570+
lineParts.shift(); // remove first empty item
571+
}
572+
573+
for (i = 0; i < lineParts.length; i += 2) {
574+
number = lineParts[i];
575+
content = lineParts[i + 1];
576+
577+
if (content.endsWith("\n")) {
578+
content = content.substring(0, content.length - 1);
579+
}
580+
lines.push(number + content);
581+
}
582+
583+
return lines;
584+
},
585+
564586
// merge two scripts with sorted line numbers, lines from script2 overwrite lines from script1
565587
mergeScripts: function (sScript1, sScript2) {
566-
var aLines1 = sScript1.trimEnd().split("\n"),
567-
aLines2 = sScript2.trimEnd().split("\n"),
588+
var aLines1 = this.splitLines(sScript1.trimEnd()),
589+
aLines2 = this.splitLines(sScript2.trimEnd()),
568590
aResult = [],
569591
iLine1, sLine2, iLine2, sResult;
570592

@@ -599,7 +621,7 @@ Controller.prototype = {
599621

600622
// get line range from a script with sorted line numbers
601623
fnGetLinesInRange: function (sScript, iFirstLine, iLastLine) {
602-
var aLines = sScript ? sScript.split("\n") : [];
624+
var aLines = sScript ? this.splitLines(sScript) : [];
603625

604626
while (aLines.length && parseInt(aLines[0], 10) < iFirstLine) {
605627
aLines.shift();

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<link rel="stylesheet" href="cpcbasic.css" />
7-
<title id="title">CPC Basic v0.10.11</title>
7+
<title id="title">CPC Basic v0.10.12</title>
88
</head>
99

1010
<body id="pageBody">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cpcbasic",
3-
"version": "0.10.11",
3+
"version": "0.10.12",
44
"description": "# CPCBasic - Run CPC BASIC in a Browser",
55
"main": "cpcbasic.js",
66
"directories": {

0 commit comments

Comments
 (0)