@nogc scanBlockScalarBreaks/scanBlockScalarIndentation.

This commit is contained in:
Ferdinand Majerech 2014-07-25 23:40:18 +02:00
parent 3cf56c8061
commit 45468bff68

View file

@ -1148,7 +1148,7 @@ final class Scanner
} }
///Scan a block scalar token with specified style. ///Scan a block scalar token with specified style.
Token scanBlockScalar(const ScalarStyle style) @safe pure Token scanBlockScalar(const ScalarStyle style) @trusted pure
{ {
const startMark = reader_.mark; const startMark = reader_.mark;
@ -1165,7 +1165,7 @@ final class Scanner
//Determine the indentation level and go to the first non-empty line. //Determine the indentation level and go to the first non-empty line.
Mark endMark; Mark endMark;
dchar[] breaks; dstring breaks;
uint indent = max(1, indent_ + 1); uint indent = max(1, indent_ + 1);
if(increment == int.min) if(increment == int.min)
{ {
@ -1196,7 +1196,7 @@ final class Scanner
lineBreak = [scanLineBreak()]; lineBreak = [scanLineBreak()];
auto scalarBreaks = scanBlockScalarBreaks(indent); auto scalarBreaks = scanBlockScalarBreaks(indent);
breaks = scalarBreaks[0]; breaks = scalarBreaks[0];
endMark = scalarBreaks[1]; endMark = scalarBreaks[1];
if(reader_.column == indent && reader_.peek() != '\0') if(reader_.column == indent && reader_.peek() != '\0')
@ -1332,10 +1332,11 @@ final class Scanner
scanLineBreak(); scanLineBreak();
} }
///Scan indentation in a block scalar, returning line breaks, max indent and end mark. /// Scan indentation in a block scalar, returning line breaks, max indent and end mark.
Tuple!(dchar[], uint, Mark) scanBlockScalarIndentation() @safe pure nothrow Tuple!(dstring, uint, Mark) scanBlockScalarIndentation()
@system pure nothrow @nogc
{ {
dchar[] chunks; reader_.sliceBuilder.begin();
uint maxIndent; uint maxIndent;
Mark endMark = reader_.mark; Mark endMark = reader_.mark;
@ -1343,7 +1344,7 @@ final class Scanner
{ {
if(reader_.peek() != ' ') if(reader_.peek() != ' ')
{ {
chunks ~= scanLineBreak(); reader_.sliceBuilder.write(scanLineBreak());
endMark = reader_.mark; endMark = reader_.mark;
continue; continue;
} }
@ -1351,25 +1352,25 @@ final class Scanner
maxIndent = max(reader_.column, maxIndent); maxIndent = max(reader_.column, maxIndent);
} }
return tuple(chunks, maxIndent, endMark); return tuple(reader_.sliceBuilder.finish(), maxIndent, endMark);
} }
///Scan line breaks at lower or specified indentation in a block scalar. /// Scan line breaks at lower or specified indentation in a block scalar.
Tuple!(dchar[], Mark) scanBlockScalarBreaks(const uint indent) Tuple!(dstring, Mark) scanBlockScalarBreaks(const uint indent)
@safe pure nothrow @trusted pure nothrow @nogc
{ {
dchar[] chunks; reader_.sliceBuilder.begin();
Mark endMark = reader_.mark; Mark endMark = reader_.mark;
for(;;) for(;;)
{ {
while(reader_.column < indent && reader_.peek() == ' '){reader_.forward();} while(reader_.column < indent && reader_.peek() == ' ') { reader_.forward(); }
if(!"\n\r\u0085\u2028\u2029"d.canFind(reader_.peek())){break;} if(!"\n\r\u0085\u2028\u2029"d.canFind(reader_.peek())) { break; }
chunks ~= scanLineBreak(); reader_.sliceBuilder.write(scanLineBreak());
endMark = reader_.mark; endMark = reader_.mark;
} }
return tuple(chunks, endMark); return tuple(reader_.sliceBuilder.finish(), endMark);
} }
/// Scan a qouted flow scalar token with specified quotes. /// Scan a qouted flow scalar token with specified quotes.