append null terminator to source when creating `StringSource`

This makes editing the lexer unnecessary.
This commit is contained in:
Vindaar 2018-10-11 14:21:38 +02:00 committed by flyx
parent ba06599b7d
commit d26a57fe93
1 changed files with 3 additions and 0 deletions

View File

@ -1181,6 +1181,9 @@ proc newYamlLexer*(source: string, startAt: int = 0): YamlLexer
GC_unref(cast[ref StringSource](x.source))
)
var sChar = '\0'
# append a `\0` at the very end to work around null terminator being
# inaccessible
sSource.src.add sChar
if source.len > 0:
sChar = sSource.src[startAt]
result[] = YamlLexerObj(buf: "", source: cast[pointer](sSource),