@@ -33,9 +33,13 @@ func GetConf(data []byte) (Conf, error) {
3333 TrimPrefixes : GetStringArrayItem (parsedConf , "trimPrefixes" ),
3434 Cplusplus : GetBoolItem (parsedConf , "cplusplus" ),
3535 Mix : GetBoolItem (parsedConf , "mix" ),
36- SymMap : GetStringArrayItem (parsedConf , "symMap" ),
36+ SymMap : GetMapItem [ string ] (parsedConf , "symMap" ),
3737 }
3838
39+ //cannot use GetMapItem[string](parsedConf, "symMap")
40+ // (value of type MapType[string]) as []string value
41+ // in struct literal (compile)
42+
3943 return Conf {
4044 JSON : parsedConf ,
4145 Config : config ,
@@ -55,6 +59,50 @@ func GetStringItem(obj *cjson.JSON, key string, defval string) (value string) {
5559 return GetString (item )
5660}
5761
62+ func GetItemValue (item * cjson.JSON ) (any , bool ) {
63+ if item .IsArray () != 0 {
64+ return item , false
65+ } else if item .IsBool () != 0 {
66+ if item .IsTrue () != 0 {
67+ return true , true
68+ }
69+ return false , true
70+ } else if item .IsNumber () != 0 {
71+ return float64 (item .GetNumberValue ()), true
72+ } else if item .IsObject () != 0 {
73+ return item , false
74+ } else if item .IsNull () != 0 {
75+ return nil , false
76+ } else if item .IsInvalid () != 0 {
77+ return nil , false
78+ } else if item .IsRaw () != 0 {
79+ return item , false
80+ } else if item .IsString () != 0 {
81+ return GetString (item ), true
82+ }
83+ return nil , false
84+ }
85+
86+ func GetMapItem [ValueType any ](obj * cjson.JSON , mapItemKey string ) map [string ]ValueType {
87+ cStrOfMapItemKey := c .AllocaCStr (mapItemKey )
88+ mapObj := obj .GetObjectItem (cStrOfMapItemKey )
89+ if mapObj == nil {
90+ return nil
91+ }
92+ m := make (map [string ]ValueType )
93+ for child := mapObj .Child ; child != nil ; child = child .Next {
94+ key := c .GoString (child .String )
95+ value , ok := GetItemValue (child )
96+ if ok {
97+ tValue , ok := value .(ValueType )
98+ if ok {
99+ m [key ] = tValue
100+ }
101+ }
102+ }
103+ return m
104+ }
105+
58106func GetStringArrayItem (obj * cjson.JSON , key string ) (value []string ) {
59107 item := obj .GetObjectItemCaseSensitive (c .AllocaCStr (key ))
60108 if item == nil {
0 commit comments