Add OmitEmpty and String operation for indent vm

This commit is contained in:
Masaaki Goshima 2021-05-07 00:12:59 +09:00
parent 56dabe2da4
commit 7d7a5163c4
4 changed files with 1936 additions and 416 deletions

View File

@ -75,3 +75,19 @@ func appendNull(b []byte) []byte {
func appendComma(b []byte) []byte {
return append(b, ',', '\n')
}
func appendStructEndSkipLast(ctx *encoder.RuntimeContext, b []byte, code *encoder.Opcode) []byte {
last := len(b) - 1
if b[last-1] == '{' {
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = appendIndent(ctx, b, code.Indent-1)
b = append(b, '}')
}
return appendComma(b)
}

File diff suppressed because it is too large Load Diff

View File

@ -75,3 +75,19 @@ func appendNull(b []byte) []byte {
func appendComma(b []byte) []byte {
return append(b, ',', '\n')
}
func appendStructEndSkipLast(ctx *encoder.RuntimeContext, b []byte, code *encoder.Opcode) []byte {
last := len(b) - 1
if b[last-1] == '{' {
b[last] = '}'
} else {
if b[last] == '\n' {
// to remove ',' and '\n' characters
b = b[:len(b)-2]
}
b = append(b, '\n')
b = appendIndent(ctx, b, code.Indent-1)
b = append(b, '}')
}
return appendComma(b)
}

File diff suppressed because it is too large Load Diff