@@ -16,10 +16,11 @@ type propertiesDecoder struct {
1616 reader io.Reader
1717 finished bool
1818 d DataTreeNavigator
19+ prefs PropertiesPreferences
1920}
2021
2122func NewPropertiesDecoder () Decoder {
22- return & propertiesDecoder {d : NewDataTreeNavigator (), finished : false }
23+ return & propertiesDecoder {d : NewDataTreeNavigator (), finished : false , prefs : ConfiguredPropertiesPreferences . Copy () }
2324}
2425
2526func (dec * propertiesDecoder ) Init (reader io.Reader ) error {
@@ -28,20 +29,56 @@ func (dec *propertiesDecoder) Init(reader io.Reader) error {
2829 return nil
2930}
3031
31- func parsePropKey (key string ) []interface {} {
32+ func parsePropKey (key string , prefs PropertiesPreferences ) []interface {} {
3233 pathStrArray := strings .Split (key , "." )
33- path := make ([]interface {}, len (pathStrArray ))
34- for i , pathStr := range pathStrArray {
35- num , err := strconv .ParseInt (pathStr , 10 , 32 )
36- if err == nil {
37- path [i ] = num
38- } else {
39- path [i ] = pathStr
40- }
34+ path := make ([]interface {}, 0 , len (pathStrArray ))
35+ for _ , pathStr := range pathStrArray {
36+ path = appendPropKeySegment (path , pathStr , prefs .UseArrayBrackets )
4137 }
4238 return path
4339}
4440
41+ func appendPropKeySegment (path []interface {}, segment string , useArrayBrackets bool ) []interface {} {
42+ if useArrayBrackets && strings .Contains (segment , "[" ) {
43+ bracketPath , ok := parsePropKeyArrayBracketSegment (segment )
44+ if ok {
45+ return append (path , bracketPath ... )
46+ }
47+ }
48+
49+ num , err := strconv .ParseInt (segment , 10 , 32 )
50+ if err == nil {
51+ return append (path , num )
52+ }
53+ return append (path , segment )
54+ }
55+
56+ func parsePropKeyArrayBracketSegment (segment string ) ([]interface {}, bool ) {
57+ path := []interface {}{}
58+ bracketIndex := strings .Index (segment , "[" )
59+ if bracketIndex > 0 {
60+ path = append (path , segment [:bracketIndex ])
61+ }
62+
63+ remaining := segment [bracketIndex :]
64+ for remaining != "" {
65+ if ! strings .HasPrefix (remaining , "[" ) {
66+ return nil , false
67+ }
68+ closingBracket := strings .Index (remaining , "]" )
69+ if closingBracket < 0 {
70+ return nil , false
71+ }
72+ arrayIndex , err := strconv .ParseInt (remaining [1 :closingBracket ], 10 , 32 )
73+ if err != nil {
74+ return nil , false
75+ }
76+ path = append (path , arrayIndex )
77+ remaining = remaining [closingBracket + 1 :]
78+ }
79+ return path , true
80+ }
81+
4582func (dec * propertiesDecoder ) processComment (c string ) string {
4683 if c == "" {
4784 return ""
@@ -75,7 +112,7 @@ func (dec *propertiesDecoder) applyPropertyComments(context Context, path []inte
75112
76113func (dec * propertiesDecoder ) applyProperty (context Context , properties * properties.Properties , key string ) error {
77114 value , _ := properties .Get (key )
78- path := parsePropKey (key )
115+ path := parsePropKey (key , dec . prefs )
79116
80117 propertyComments := properties .GetComments (key )
81118 if len (propertyComments ) > 0 {
0 commit comments