lineBreak is a dchar instead of an array now.

This commit is contained in:
Ferdinand Majerech 2014-07-26 02:41:42 +02:00
parent 701b01dd20
commit 0ce9dc0b3a

View file

@ -1202,7 +1202,8 @@ final class Scanner
} }
size_t endLen = reader_.sliceBuilder.length; size_t endLen = reader_.sliceBuilder.length;
dchar[] lineBreak = ""d.dup; // dchar.max means there's no line break.
dchar lineBreak = dchar.max;
// Scan the inner part of the block scalar. // Scan the inner part of the block scalar.
@ -1212,14 +1213,14 @@ final class Scanner
const bool leadingNonSpace = !" \t"d.canFind(reader_.peek()); const bool leadingNonSpace = !" \t"d.canFind(reader_.peek());
// This is where the 'interesting' non-whitespace data gets read. // This is where the 'interesting' non-whitespace data gets read.
scanToNextBreakToSlice(); scanToNextBreakToSlice();
lineBreak = [scanLineBreak()]; lineBreak = scanLineBreak();
// This transaction serves to rollback data read in the // This transaction serves to rollback data read in the
// scanBlockScalarBreaksToSlice() call. // scanBlockScalarBreaksToSlice() call.
breaksTransaction = Transaction(reader_.sliceBuilder); breaksTransaction = Transaction(reader_.sliceBuilder);
startLen = reader_.sliceBuilder.length; startLen = reader_.sliceBuilder.length;
// The line breaks should actually be written _after_ the if() block // The line breaks should actually be written _after_ the if() block
// below. We work around that by inserting // below. We work around that by inserting
endMark = scanBlockScalarBreaksToSlice(indent); endMark = scanBlockScalarBreaksToSlice(indent);
endLen = reader_.sliceBuilder.length; endLen = reader_.sliceBuilder.length;
@ -1231,7 +1232,7 @@ final class Scanner
// Unfortunately, folding rules are ambiguous. // Unfortunately, folding rules are ambiguous.
// This is the folding according to the specification: // This is the folding according to the specification:
if(style == ScalarStyle.Folded && lineBreak == "\n" && if(style == ScalarStyle.Folded && lineBreak == '\n' &&
leadingNonSpace && !" \t"d.canFind(reader_.peek())) leadingNonSpace && !" \t"d.canFind(reader_.peek()))
{ {
// No breaks were scanned; no need to insert the space in the // No breaks were scanned; no need to insert the space in the
@ -1245,13 +1246,13 @@ final class Scanner
{ {
// We need to insert in the middle of the slice in case any line // We need to insert in the middle of the slice in case any line
// breaks were scanned. // breaks were scanned.
reader_.sliceBuilder.insertBack(lineBreak[0], endLen - startLen); reader_.sliceBuilder.insertBack(lineBreak, endLen - startLen);
} }
////this is Clark Evans's interpretation (also in the spec ////this is Clark Evans's interpretation (also in the spec
////examples): ////examples):
// //
//if(style == ScalarStyle.Folded && lineBreak == "\n"d) //if(style == ScalarStyle.Folded && lineBreak == '\n')
//{ //{
// if(startLen == endLen) // if(startLen == endLen)
// { // {
@ -1261,13 +1262,13 @@ final class Scanner
// } // }
// else // else
// { // {
// chunks ~= lineBreak[0]; // chunks ~= lineBreak;
// } // }
// } // }
//} //}
//else //else
//{ //{
// reader_.sliceBuilder.insertBack(lineBreak[0], endLen - startLen); // reader_.sliceBuilder.insertBack(lineBreak, endLen - startLen);
//} //}
} }
else else
@ -1281,21 +1282,21 @@ final class Scanner
// transaction). // transaction).
if(chomping == Chomping.Keep) { breaksTransaction.commit(); } if(chomping == Chomping.Keep) { breaksTransaction.commit(); }
else { breaksTransaction.__dtor(); } else { breaksTransaction.__dtor(); }
if(chomping != Chomping.Strip && !lineBreak.empty) if(chomping != Chomping.Strip && lineBreak != dchar.max)
{ {
// If chomping is Keep, we keep the line break but the first line break // If chomping is Keep, we keep the line break but the first line break
// that isn't stripped (since chomping isn't Strip in this branch) must // that isn't stripped (since chomping isn't Strip in this branch) must
// be inserted _before_ the other line breaks. // be inserted _before_ the other line breaks.
if(chomping == Chomping.Keep) if(chomping == Chomping.Keep)
{ {
reader_.sliceBuilder.insertBack(lineBreak[0], endLen - startLen); reader_.sliceBuilder.insertBack(lineBreak, endLen - startLen);
} }
// If chomping is not Keep, breaksTransaction was cancelled so we can // If chomping is not Keep, breaksTransaction was cancelled so we can
// directly write the first line break (as it isn't stripped - chomping // directly write the first line break (as it isn't stripped - chomping
// is not Strip) // is not Strip)
else else
{ {
reader_.sliceBuilder.write(lineBreak[0]); reader_.sliceBuilder.write(lineBreak);
} }
} }