a83a92cd by astaxie

Merge pull request #321 from smallfish/master

update logic for check ini comments
2 parents 9cc2e723 23ff7af0
...@@ -14,8 +14,8 @@ import ( ...@@ -14,8 +14,8 @@ import (
14 14
15 var ( 15 var (
16 DEFAULT_SECTION = "DEFAULT" 16 DEFAULT_SECTION = "DEFAULT"
17 bComment = []byte{'#'} 17 bNumComment = []byte{'#'} // number sign
18 alterComment = []byte{';'} 18 bSemComment = []byte{';'} // semicolon
19 bEmpty = []byte{} 19 bEmpty = []byte{}
20 bEqual = []byte{'='} 20 bEqual = []byte{'='}
21 bDQuote = []byte{'"'} 21 bDQuote = []byte{'"'}
...@@ -58,20 +58,21 @@ func (ini *IniConfig) Parse(name string) (ConfigContainer, error) { ...@@ -58,20 +58,21 @@ func (ini *IniConfig) Parse(name string) (ConfigContainer, error) {
58 } 58 }
59 line = bytes.TrimSpace(line) 59 line = bytes.TrimSpace(line)
60 60
61 if bytes.HasPrefix(line, bComment) { 61 var bComment []byte
62 line = bytes.TrimLeft(line, "#") 62 switch {
63 line = bytes.TrimLeftFunc(line, unicode.IsSpace) 63 case bytes.HasPrefix(line, bNumComment):
64 comment.Write(line) 64 bComment = bNumComment
65 comment.WriteByte('\n') 65 case bytes.HasPrefix(line, bSemComment):
66 continue 66 bComment = bSemComment
67 } 67 }
68 if bytes.HasPrefix(line, alterComment) { 68 if bComment != nil {
69 line = bytes.TrimLeft(line, ";") 69 line = bytes.TrimLeft(line, string(bComment))
70 line = bytes.TrimLeftFunc(line, unicode.IsSpace) 70 line = bytes.TrimLeftFunc(line, unicode.IsSpace)
71 comment.Write(line) 71 comment.Write(line)
72 comment.WriteByte('\n') 72 comment.WriteByte('\n')
73 continue 73 continue
74 } 74 }
75
75 if bytes.HasPrefix(line, sectionStart) && bytes.HasSuffix(line, sectionEnd) { 76 if bytes.HasPrefix(line, sectionStart) && bytes.HasSuffix(line, sectionEnd) {
76 section = string(line[1 : len(line)-1]) 77 section = string(line[1 : len(line)-1])
77 if comment.Len() > 0 { 78 if comment.Len() > 0 {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!