1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

toml: small refactor, move all json functionality to submodule (#12502)

This commit is contained in:
Larpon
2021-11-18 12:27:59 +01:00
committed by GitHub
parent 5bf28c5287
commit 7ec70d5477
17 changed files with 223 additions and 200 deletions

View File

@@ -25,44 +25,3 @@ pub fn is_illegal_ascii_control_character(byte_char byte) bool {
pub fn printdbg(id string, message string) {
eprintln(id + ' ' + message)
}
// parse_dotted_key converts `key` string to an array of strings.
// parse_dotted_key preserves strings delimited by both `"` and `'`.
pub fn parse_dotted_key(key string) ?[]string {
mut out := []string{}
mut buf := ''
mut in_string := false
mut delim := byte(` `)
for ch in key {
if ch in [`"`, `'`] {
if !in_string {
delim = ch
}
in_string = !in_string && ch == delim
if !in_string {
if buf != '' && buf != ' ' {
out << buf
}
buf = ''
delim = ` `
}
continue
}
buf += ch.ascii_str()
if !in_string && ch == `.` {
if buf != '' && buf != ' ' {
out << buf[..buf.len - 1]
}
buf = ''
continue
}
}
if buf != '' && buf != ' ' {
out << buf
}
if in_string {
return error(@FN +
': could not parse key, missing closing string delimiter `$delim.ascii_str()`')
}
return out
}