rm push/pop
This commit is contained in:
16
toml.cm
16
toml.cm
@@ -127,7 +127,7 @@ function parse_key_path(str) {
|
||||
} else if (c == '.' && !in_quote) {
|
||||
piece = trim(current)
|
||||
if (piece == null) piece = trim(current)
|
||||
push(parts, parse_key(piece))
|
||||
parts[] = parse_key(piece)
|
||||
current = ''
|
||||
continue
|
||||
}
|
||||
@@ -136,7 +136,7 @@ function parse_key_path(str) {
|
||||
|
||||
var tail = trim(current)
|
||||
if (tail == null) tail = trim(current)
|
||||
if (length(tail) > 0) push(parts, parse_key(tail))
|
||||
if (length(tail) > 0) parts[] = parse_key(tail)
|
||||
|
||||
return parts
|
||||
}
|
||||
@@ -165,7 +165,7 @@ function parse_array(str) {
|
||||
} else if (ch == ',' && !in_quotes) {
|
||||
piece = trim(current)
|
||||
if (piece == null) piece = trim(current)
|
||||
push(items, parse_value(piece))
|
||||
items[] = parse_value(piece)
|
||||
current = ''
|
||||
} else {
|
||||
current = current + ch
|
||||
@@ -174,7 +174,7 @@ function parse_array(str) {
|
||||
|
||||
var last = trim(current)
|
||||
if (last == null) last = trim(current)
|
||||
if (last) push(items, parse_value(last))
|
||||
if (last) items[] = parse_value(last)
|
||||
|
||||
return items
|
||||
}
|
||||
@@ -204,7 +204,7 @@ function encode_toml(obj) {
|
||||
if (is_number(value)) return text(value)
|
||||
if (is_array(value)) {
|
||||
items = []
|
||||
for (i = 0; i < length(value); i++) push(items, encode_value(value[i]))
|
||||
for (i = 0; i < length(value); i++) items[] = encode_value(value[i])
|
||||
return '[' + text(items, ', ') + ']'
|
||||
}
|
||||
return text(value)
|
||||
@@ -230,7 +230,7 @@ function encode_toml(obj) {
|
||||
for (i = 0; i < length(keys); i++) {
|
||||
key = keys[i]
|
||||
value = obj[key]
|
||||
if (!is_object(value)) push(result, quote_key(key) + ' = ' + encode_value(value))
|
||||
if (!is_object(value)) result[] = quote_key(key) + ' = ' + encode_value(value)
|
||||
}
|
||||
|
||||
// Second pass: encode nested objects
|
||||
@@ -252,14 +252,14 @@ function encode_toml(obj) {
|
||||
if (is_object(value)) {
|
||||
quoted = quote_key(key)
|
||||
section_path = path ? path + '.' + quoted : quoted
|
||||
push(result, '[' + section_path + ']')
|
||||
result[] = '[' + section_path + ']'
|
||||
|
||||
// Direct properties
|
||||
section_keys = array(value)
|
||||
for (j = 0; j < length(section_keys); j++) {
|
||||
sk = section_keys[j]
|
||||
sv = value[sk]
|
||||
if (!is_object(sv)) push(result, quote_key(sk) + ' = ' + encode_value(sv))
|
||||
if (!is_object(sv)) result[] = quote_key(sk) + ' = ' + encode_value(sv)
|
||||
}
|
||||
|
||||
// Nested sections
|
||||
|
||||
Reference in New Issue
Block a user