From 251a75346d8672b17f5168e9e1eb6bae66a3257a Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 14 Dec 2014 17:48:19 +0100 Subject: [PATCH 1/3] make stringIterator aware of newlines --- src/static/js/Changeset.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 366ad15f..629cf759 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -507,6 +507,10 @@ exports.opAssembler = function () { */ exports.stringIterator = function (str) { var curIndex = 0; + var newLines = str.split("\n").length - 1 + function getnewLines(){ + return newLines + } function assertRemaining(n) { exports.assert(n <= remaining(), "!(", n, " <= ", remaining(), ")"); @@ -515,6 +519,7 @@ exports.stringIterator = function (str) { function take(n) { assertRemaining(n); var s = str.substr(curIndex, n); + newLines -= s.split("\n").length - 1 curIndex += n; return s; } @@ -537,7 +542,8 @@ exports.stringIterator = function (str) { take: take, skip: skip, remaining: remaining, - peek: peek + peek: peek, + newlines: getnewLines }; }; From 51c14d994756e60333b0b60eccb7255cf0c86461 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 14 Dec 2014 17:51:34 +0100 Subject: [PATCH 2/3] check if op.lines is in sync with atext-newlines Conflicts: src/static/js/Changeset.js --- src/static/js/Changeset.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 629cf759..acb59cc3 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -916,6 +916,8 @@ exports.applyToText = function (cs, str) { var csIter = exports.opIterator(unpacked.ops); var bankIter = exports.stringIterator(unpacked.charBank); var strIter = exports.stringIterator(str); + var newlines = 0 + var newlinefail = false var assem = exports.stringAssembler(); while (csIter.hasNext()) { var op = csIter.next(); @@ -925,16 +927,24 @@ exports.applyToText = function (cs, str) { break; case '-': removedLines += op.lines; + newlines = strIter.newlines() strIter.skip(op.chars); + if(!(newlines - strIter.newlines() == op.lines)){ + newlinefail = true + } break; case '=': + newlines = strIter.newlines() assem.append(strIter.take(op.chars)); + if(!(newlines - strIter.newlines() == op.lines)){ + newlinefail = true + } break; } } exports.assert(totalNrOfLines >= removedLines,"cannot remove ", removedLines, " lines from text with ", totalNrOfLines, " lines"); assem.append(strIter.take(strIter.remaining())); - return assem.toString(); + return [assem.toString(),newlinefail]; }; /** @@ -1605,8 +1615,12 @@ exports.makeAText = function (text, attribs) { * @param pool {AttribPool} Attribute Pool to add to */ exports.applyToAText = function (cs, atext, pool) { + var text = exports.applyToText(cs, atext.text) + if(text[1]){ + throw new Error() + } return { - text: exports.applyToText(cs, atext.text), + text: text[0], attribs: exports.applyToAttribution(cs, atext.attribs, pool) }; }; From 3354b9406b94e1a04b5eee1c0152914dde73ba89 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Tue, 16 Dec 2014 12:29:33 +0100 Subject: [PATCH 3/3] op is ok, if it doesnt include newlines. op is ok, if op.lines is equal to newlines in op.chars --- src/static/js/Changeset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index acb59cc3..32da887d 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -929,7 +929,7 @@ exports.applyToText = function (cs, str) { removedLines += op.lines; newlines = strIter.newlines() strIter.skip(op.chars); - if(!(newlines - strIter.newlines() == op.lines)){ + if(!(newlines - strIter.newlines() == 0) && (newlines - strIter.newlines() != op.lines)){ newlinefail = true } break;