16 |
16 |
17 // Package ini provides INI file read and write functionality in Go. |
17 // Package ini provides INI file read and write functionality in Go. |
18 package ini |
18 package ini |
19 |
19 |
20 import ( |
20 import ( |
|
21 "os" |
21 "regexp" |
22 "regexp" |
22 "runtime" |
23 "runtime" |
|
24 "strings" |
23 ) |
25 ) |
24 |
26 |
25 const ( |
27 const ( |
26 // DefaultSection is the name of default section. You can use this constant or the string literal. |
28 // DefaultSection is the name of default section. You can use this constant or the string literal. |
27 // In most of cases, an empty string is all you need to access the section. |
29 // In most of cases, an empty string is all you need to access the section. |
28 DefaultSection = "DEFAULT" |
30 DefaultSection = "DEFAULT" |
29 |
31 |
30 // Maximum allowed depth when recursively substituing variable names. |
32 // Maximum allowed depth when recursively substituing variable names. |
31 depthValues = 99 |
33 depthValues = 99 |
32 version = "1.52.0" |
|
33 ) |
34 ) |
34 |
|
35 // Version returns current package version literal. |
|
36 func Version() string { |
|
37 return version |
|
38 } |
|
39 |
35 |
40 var ( |
36 var ( |
41 // LineBreak is the delimiter to determine or compose a new line. |
37 // LineBreak is the delimiter to determine or compose a new line. |
42 // This variable will be changed to "\r\n" automatically on Windows at package init time. |
38 // This variable will be changed to "\r\n" automatically on Windows at package init time. |
43 LineBreak = "\n" |
39 LineBreak = "\n" |
59 DefaultFormatLeft = "" |
55 DefaultFormatLeft = "" |
60 // DefaultFormatRight places custom spaces on the right when PrettyFormat and PrettyEqual are both disabled. |
56 // DefaultFormatRight places custom spaces on the right when PrettyFormat and PrettyEqual are both disabled. |
61 DefaultFormatRight = "" |
57 DefaultFormatRight = "" |
62 ) |
58 ) |
63 |
59 |
|
60 var inTest = len(os.Args) > 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test") |
|
61 |
64 func init() { |
62 func init() { |
65 if runtime.GOOS == "windows" { |
63 if runtime.GOOS == "windows" && !inTest { |
66 LineBreak = "\r\n" |
64 LineBreak = "\r\n" |
67 } |
65 } |
68 } |
66 } |
69 |
67 |
70 // LoadOptions contains all customized options used for load data source(s). |
68 // LoadOptions contains all customized options used for load data source(s). |
71 type LoadOptions struct { |
69 type LoadOptions struct { |
72 // Loose indicates whether the parser should ignore nonexistent files or return error. |
70 // Loose indicates whether the parser should ignore nonexistent files or return error. |
73 Loose bool |
71 Loose bool |
74 // Insensitive indicates whether the parser forces all section and key names to lowercase. |
72 // Insensitive indicates whether the parser forces all section and key names to lowercase. |
75 Insensitive bool |
73 Insensitive bool |
|
74 // InsensitiveSections indicates whether the parser forces all section to lowercase. |
|
75 InsensitiveSections bool |
|
76 // InsensitiveKeys indicates whether the parser forces all key names to lowercase. |
|
77 InsensitiveKeys bool |
76 // IgnoreContinuation indicates whether to ignore continuation lines while parsing. |
78 // IgnoreContinuation indicates whether to ignore continuation lines while parsing. |
77 IgnoreContinuation bool |
79 IgnoreContinuation bool |
78 // IgnoreInlineComment indicates whether to ignore comments at the end of value and treat it as part of value. |
80 // IgnoreInlineComment indicates whether to ignore comments at the end of value and treat it as part of value. |
79 IgnoreInlineComment bool |
81 IgnoreInlineComment bool |
80 // SkipUnrecognizableLines indicates whether to skip unrecognizable lines that do not conform to key/value pairs. |
82 // SkipUnrecognizableLines indicates whether to skip unrecognizable lines that do not conform to key/value pairs. |
81 SkipUnrecognizableLines bool |
83 SkipUnrecognizableLines bool |
|
84 // ShortCircuit indicates whether to ignore other configuration sources after loaded the first available configuration source. |
|
85 ShortCircuit bool |
82 // AllowBooleanKeys indicates whether to allow boolean type keys or treat as value is missing. |
86 // AllowBooleanKeys indicates whether to allow boolean type keys or treat as value is missing. |
83 // This type of keys are mostly used in my.cnf. |
87 // This type of keys are mostly used in my.cnf. |
84 AllowBooleanKeys bool |
88 AllowBooleanKeys bool |
85 // AllowShadows indicates whether to keep track of keys with same name under same section. |
89 // AllowShadows indicates whether to keep track of keys with same name under same section. |
86 AllowShadows bool |
90 AllowShadows bool |
107 // UnparseableSections stores a list of blocks that are allowed with raw content which do not otherwise |
111 // UnparseableSections stores a list of blocks that are allowed with raw content which do not otherwise |
108 // conform to key/value pairs. Specify the names of those blocks here. |
112 // conform to key/value pairs. Specify the names of those blocks here. |
109 UnparseableSections []string |
113 UnparseableSections []string |
110 // KeyValueDelimiters is the sequence of delimiters that are used to separate key and value. By default, it is "=:". |
114 // KeyValueDelimiters is the sequence of delimiters that are used to separate key and value. By default, it is "=:". |
111 KeyValueDelimiters string |
115 KeyValueDelimiters string |
|
116 // KeyValueDelimiterOnWrite is the delimiter that are used to separate key and value output. By default, it is "=". |
|
117 KeyValueDelimiterOnWrite string |
|
118 // ChildSectionDelimiter is the delimiter that is used to separate child sections. By default, it is ".". |
|
119 ChildSectionDelimiter string |
112 // PreserveSurroundedQuote indicates whether to preserve surrounded quote (single and double quotes). |
120 // PreserveSurroundedQuote indicates whether to preserve surrounded quote (single and double quotes). |
113 PreserveSurroundedQuote bool |
121 PreserveSurroundedQuote bool |
114 // DebugFunc is called to collect debug information (currently only useful to debug parsing Python-style multiline values). |
122 // DebugFunc is called to collect debug information (currently only useful to debug parsing Python-style multiline values). |
115 DebugFunc DebugFunc |
123 DebugFunc DebugFunc |
116 // ReaderBufferSize is the buffer size of the reader in bytes. |
124 // ReaderBufferSize is the buffer size of the reader in bytes. |
117 ReaderBufferSize int |
125 ReaderBufferSize int |
|
126 // AllowNonUniqueSections indicates whether to allow sections with the same name multiple times. |
|
127 AllowNonUniqueSections bool |
118 } |
128 } |
119 |
129 |
120 // DebugFunc is the type of function called to log parse events. |
130 // DebugFunc is the type of function called to log parse events. |
121 type DebugFunc func(message string) |
131 type DebugFunc func(message string) |
122 |
132 |