throw in applyToText and not in applyToAText

pull/2518/head
webzwo0i 2015-02-16 06:27:18 +01:00
parent 59328aa33a
commit c9a5167b41
1 changed files with 5 additions and 10 deletions

View File

@ -915,7 +915,6 @@ exports.applyToText = function (cs, str) {
var csIter = exports.opIterator(unpacked.ops); var csIter = exports.opIterator(unpacked.ops);
var bankIter = exports.stringIterator(unpacked.charBank); var bankIter = exports.stringIterator(unpacked.charBank);
var strIter = exports.stringIterator(str); var strIter = exports.stringIterator(str);
var newlinefail = false;
var assem = exports.stringAssembler(); var assem = exports.stringAssembler();
while (csIter.hasNext()) { while (csIter.hasNext()) {
var op = csIter.next(); var op = csIter.next();
@ -924,7 +923,7 @@ exports.applyToText = function (cs, str) {
//op is + and op.lines 0: no newlines must be in op.chars //op is + and op.lines 0: no newlines must be in op.chars
//op is + and op.lines >0: op.chars must include op.lines newlines //op is + and op.lines >0: op.chars must include op.lines newlines
if(op.lines != bankIter.peek(op.chars).split("\n").length - 1){ if(op.lines != bankIter.peek(op.chars).split("\n").length - 1){
newlinefail = true; throw new Error("newline count is wrong in op +; cs:"+cs+" and text:"+str);
} }
assem.append(bankIter.take(op.chars)); assem.append(bankIter.take(op.chars));
break; break;
@ -932,7 +931,7 @@ exports.applyToText = function (cs, str) {
//op is - and op.lines 0: no newlines must be in the deleted string //op is - and op.lines 0: no newlines must be in the deleted string
//op is - and op.lines >0: op.lines newlines must be in the deleted string //op is - and op.lines >0: op.lines newlines must be in the deleted string
if(op.lines != strIter.peek(op.chars).split("\n").length - 1){ if(op.lines != strIter.peek(op.chars).split("\n").length - 1){
newlinefail = true; throw new Error("newline count is wrong in op -; cs:"+cs+" and text:"+str);
} }
strIter.skip(op.chars); strIter.skip(op.chars);
break; break;
@ -940,14 +939,14 @@ exports.applyToText = function (cs, str) {
//op is = and op.lines 0: no newlines must be in the copied string //op is = and op.lines 0: no newlines must be in the copied string
//op is = and op.lines >0: op.lines newlines must be in the copied string //op is = and op.lines >0: op.lines newlines must be in the copied string
if(op.lines != strIter.peek(op.chars).split("\n").length - 1){ if(op.lines != strIter.peek(op.chars).split("\n").length - 1){
newlinefail = true; throw new Error("newline count is wrong in op =; cs:"+cs+" and text:"+str);
} }
assem.append(strIter.take(op.chars)); assem.append(strIter.take(op.chars));
break; break;
} }
} }
assem.append(strIter.take(strIter.remaining())); assem.append(strIter.take(strIter.remaining()));
return [assem.toString(),newlinefail]; return assem.toString();
}; };
/** /**
@ -1618,12 +1617,8 @@ exports.makeAText = function (text, attribs) {
* @param pool {AttribPool} Attribute Pool to add to * @param pool {AttribPool} Attribute Pool to add to
*/ */
exports.applyToAText = function (cs, atext, pool) { exports.applyToAText = function (cs, atext, pool) {
var text = exports.applyToText(cs, atext.text)
if(text[1]){
throw new Error("newline count is wrong, cs:"+cs+" and text:"+atext.text);
}
return { return {
text: text[0], text: exports.applyToText(cs, atext.text),
attribs: exports.applyToAttribution(cs, atext.attribs, pool) attribs: exports.applyToAttribution(cs, atext.attribs, pool)
}; };
}; };