mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 09:30:56 +00:00
update logic for check ini comments
This commit is contained in:
parent
9cc2e7237b
commit
23ff7af0b7
@ -14,8 +14,8 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
DEFAULT_SECTION = "DEFAULT"
|
DEFAULT_SECTION = "DEFAULT"
|
||||||
bComment = []byte{'#'}
|
bNumComment = []byte{'#'} // number sign
|
||||||
alterComment = []byte{';'}
|
bSemComment = []byte{';'} // semicolon
|
||||||
bEmpty = []byte{}
|
bEmpty = []byte{}
|
||||||
bEqual = []byte{'='}
|
bEqual = []byte{'='}
|
||||||
bDQuote = []byte{'"'}
|
bDQuote = []byte{'"'}
|
||||||
@ -58,20 +58,21 @@ func (ini *IniConfig) Parse(name string) (ConfigContainer, error) {
|
|||||||
}
|
}
|
||||||
line = bytes.TrimSpace(line)
|
line = bytes.TrimSpace(line)
|
||||||
|
|
||||||
if bytes.HasPrefix(line, bComment) {
|
var bComment []byte
|
||||||
line = bytes.TrimLeft(line, "#")
|
switch {
|
||||||
line = bytes.TrimLeftFunc(line, unicode.IsSpace)
|
case bytes.HasPrefix(line, bNumComment):
|
||||||
comment.Write(line)
|
bComment = bNumComment
|
||||||
comment.WriteByte('\n')
|
case bytes.HasPrefix(line, bSemComment):
|
||||||
continue
|
bComment = bSemComment
|
||||||
}
|
}
|
||||||
if bytes.HasPrefix(line, alterComment) {
|
if bComment != nil {
|
||||||
line = bytes.TrimLeft(line, ";")
|
line = bytes.TrimLeft(line, string(bComment))
|
||||||
line = bytes.TrimLeftFunc(line, unicode.IsSpace)
|
line = bytes.TrimLeftFunc(line, unicode.IsSpace)
|
||||||
comment.Write(line)
|
comment.Write(line)
|
||||||
comment.WriteByte('\n')
|
comment.WriteByte('\n')
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.HasPrefix(line, sectionStart) && bytes.HasSuffix(line, sectionEnd) {
|
if bytes.HasPrefix(line, sectionStart) && bytes.HasSuffix(line, sectionEnd) {
|
||||||
section = string(line[1 : len(line)-1])
|
section = string(line[1 : len(line)-1])
|
||||||
if comment.Len() > 0 {
|
if comment.Len() > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user