text dictionary: added support for non-name (#??) strings

This commit is contained in:
M. Sz 2021-02-28 16:29:05 +01:00
parent 287fb2bf4d
commit 4104d9d9ae
2 changed files with 16 additions and 3 deletions

View File

@ -224,7 +224,13 @@ func (td *TextDictionary) Marshal() []byte {
sw.PushUint32(0)
sw.PushUint32(uint32(dataPos))
dataPos += len(key) + 1
if key[0] == '#' {
// 1 for X, and 1 for separator
dataPos += 2
} else {
dataPos += len(key) + 1
}
sw.PushUint32(uint32(dataPos))
dataPos += len(value) + 1
@ -236,6 +242,10 @@ func (td *TextDictionary) Marshal() []byte {
for _, key := range keys {
value := (*td)[key]
if key[0] == '#' {
key = "x"
}
for _, i := range key {
sw.PushBytes(byte(i))
}

View File

@ -6,8 +6,11 @@ import (
func exampleData() *TextDictionary {
result := &TextDictionary{
"abc": "def",
"someStr": "Some long string",
"abc": "def",
"someStr": "Some long string",
// #2 is non-named (X: OK)
// so 2 is an index in map
"#2": "OK",
"teststring": "TeStxwsas123 long strin122*8:wq",
}