Revert "fix for null terminator not accessable in strings anymore"

This reverts commit 07c59e2d2d90b3123973814ebc9cf974a0bf4baf.
This commit is contained in:
Vindaar 2018-10-11 14:33:03 +02:00 committed by flyx
parent d26a57fe93
commit 3eb006be2d
1 changed files with 4 additions and 14 deletions

View File

@ -140,10 +140,7 @@ template lexLF(lex: YamlLexer, t: typedesc[StringSource]) =
lex.sSource.pos.inc() lex.sSource.pos.inc()
lex.sSource.lineStart = lex.sSource.pos lex.sSource.lineStart = lex.sSource.pos
lex.sSource.line.inc() lex.sSource.line.inc()
if lex.sSource.pos < lex.sSource.src.len: lex.c = lex.sSource.src[lex.sSource.pos]
lex.c = lex.sSource.src[lex.sSource.pos]
else:
lex.c = '\0'
template lineNumber(lex: YamlLexer, t: typedesc[BaseLexer]): int = template lineNumber(lex: YamlLexer, t: typedesc[BaseLexer]): int =
lex.blSource.lineNumber lex.blSource.lineNumber
@ -190,10 +187,7 @@ proc at(lex: YamlLexer, t: typedesc[BaseLexer], pos: int): char {.inline.} =
lex.blSource.buf[pos] lex.blSource.buf[pos]
proc at(lex: YamlLexer, t: typedesc[StringSource], pos: int): char {.inline.} = proc at(lex: YamlLexer, t: typedesc[StringSource], pos: int): char {.inline.} =
if lex.sSource.src.len == pos: lex.sSource.src[pos]
'\0'
else:
lex.sSource.src[pos]
proc mark(lex: YamlLexer, t: typedesc[BaseLexer]): int = lex.blSource.bufpos proc mark(lex: YamlLexer, t: typedesc[BaseLexer]): int = lex.blSource.bufpos
proc mark(lex: YamlLexer, t: typedesc[StringSource]): int = lex.sSource.pos proc mark(lex: YamlLexer, t: typedesc[StringSource]): int = lex.sSource.pos
@ -1180,15 +1174,11 @@ proc newYamlLexer*(source: string, startAt: int = 0): YamlLexer
new(result, proc(x: ref YamlLexerObj) {.nimcall.} = new(result, proc(x: ref YamlLexerObj) {.nimcall.} =
GC_unref(cast[ref StringSource](x.source)) GC_unref(cast[ref StringSource](x.source))
) )
var sChar = '\0'
# append a `\0` at the very end to work around null terminator being # append a `\0` at the very end to work around null terminator being
# inaccessible # inaccessible
sSource.src.add sChar sSource.src.add '\0'
if source.len > 0:
sChar = sSource.src[startAt]
result[] = YamlLexerObj(buf: "", source: cast[pointer](sSource), result[] = YamlLexerObj(buf: "", source: cast[pointer](sSource),
inFlow: false, c: sChar, newlines: 0, folded: true) inFlow: false, c: sSource.src[startAt], newlines: 0, folded: true)
init[StringSource](result) init[StringSource](result)
proc next*(lex: YamlLexer) = proc next*(lex: YamlLexer) =