update logic for check ini comments
Showing
1 changed file
with
11 additions
and
10 deletions
| ... | @@ -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 { | ... | ... |
-
Please register or sign in to post a comment