Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion json5/lex_string.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn lex_string(ctx : ParseContext, quote : Char) -> String raise ParseError {
let buf = StringBuilder::new()
let mut start = ctx.offset
fn flush(end : Int) {
if start > 0 && end > start {
if end > start {
buf.write_substring(ctx.input, start, end - start)
}
}
Expand Down Expand Up @@ -79,6 +79,18 @@ fn lex_string(ctx : ParseContext, quote : Char) -> String raise ParseError {
buf.to_string()
}

///|
test {
//If start < 0 && is not removed, the test has no input. After removing it, the output is correct.
// 1. 输入是 "hello" (不带起始引号)
let ctx = ParseContext::make("hello\"")

// 2. *不* 预先读取字符,直接调用 lex_string
// 此时 ctx.offset 是 0
let result = lex_string(ctx, '"')
println(result)
}

///|
fn lex_hex_digits(ctx : ParseContext, n : Int) -> Int raise ParseError {
let mut r = 0
Expand Down
Loading