aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-05-25 01:10:31 +0700
committerShulhan <ms@kilabit.info>2019-05-25 01:13:35 +0700
commit3df89617c363d3dc89b3afdd59c11324fd0174c5 (patch)
tree1db45b74c7e758621916102bac91eb73383832c9
parentca2ea5f79bef932b058fc3d9882d435dcc312967 (diff)
downloadpakakeh.go-3df89617c363d3dc89b3afdd59c11324fd0174c5.tar.xz
ini: reorder all methods by name
-rw-r--r--lib/ini/ini.go128
1 files changed, 64 insertions, 64 deletions
diff --git a/lib/ini/ini.go b/lib/ini/ini.go
index 354c8f56..69fe21e1 100644
--- a/lib/ini/ini.go
+++ b/lib/ini/ini.go
@@ -48,6 +48,22 @@ func Parse(text []byte) (in *Ini, err error) {
}
//
+// AddSection append the new section to the list.
+//
+func (in *Ini) AddSection(sec *Section) {
+ if sec == nil {
+ return
+ }
+ if sec.mode != varModeEmpty && len(sec.Name) == 0 {
+ return
+ }
+
+ sec.NameLower = strings.ToLower(sec.Name)
+
+ in.secs = append(in.secs, sec)
+}
+
+//
// AsMap return the INI contents as mapping of
// (section-name ":" subsection-name ":" variable-name) as key
// and the variable's values as slice of string.
@@ -97,57 +113,6 @@ func (in *Ini) AsMap() (out map[string][]string) {
}
//
-// Save the current parsed Ini into file `filename`. It will overwrite the
-// destination file if it's exist.
-//
-func (in *Ini) Save(filename string) (err error) {
- f, err := os.Create(filename)
- if err != nil {
- return
- }
-
- err = in.Write(f)
-
- errClose := f.Close()
- if errClose != nil {
- println("ini.Save:", errClose)
- }
-
- return
-}
-
-//
-// Write the current parsed Ini into writer `w`.
-//
-func (in *Ini) Write(w io.Writer) (err error) {
- for x := 0; x < len(in.secs); x++ {
- fmt.Fprint(w, in.secs[x])
-
- for _, v := range in.secs[x].Vars {
- fmt.Fprint(w, v)
- }
- }
-
- return
-}
-
-//
-// AddSection append the new section to the list.
-//
-func (in *Ini) AddSection(sec *Section) {
- if sec == nil {
- return
- }
- if sec.mode != varModeEmpty && len(sec.Name) == 0 {
- return
- }
-
- sec.NameLower = strings.ToLower(sec.Name)
-
- in.secs = append(in.secs, sec)
-}
-
-//
// Get the last key on section and/or subsection (if not empty).
//
// If section, subsection, and key found it will return key's value and true;
@@ -180,6 +145,19 @@ func (in *Ini) Get(section, subsection, key string) (val string, ok bool) {
}
//
+// GetBool return key's value as boolean. If no key found it will return
+// default value.
+//
+func (in *Ini) GetBool(section, subsection, key string, def bool) bool {
+ out, ok := in.Get(section, subsection, key)
+ if !ok {
+ return def
+ }
+
+ return IsValueBoolTrue(out)
+}
+
+//
// GetSection return the last section that match with section name and/or
// subsection name.
// If section name is empty or no match found it will return nil.
@@ -225,19 +203,6 @@ func (in *Ini) GetSections(name string) (secs []*Section) {
}
//
-// GetBool return key's value as boolean. If no key found it will return
-// default value.
-//
-func (in *Ini) GetBool(section, subsection, key string, def bool) bool {
- out, ok := in.Get(section, subsection, key)
- if !ok {
- return def
- }
-
- return IsValueBoolTrue(out)
-}
-
-//
// GetString return key's value as string. if no key found it will return
// default value.
//
@@ -275,3 +240,38 @@ func (in *Ini) Gets(section, subsection, key string) (out []string) {
}
return
}
+
+//
+// Save the current parsed Ini into file `filename`. It will overwrite the
+// destination file if it's exist.
+//
+func (in *Ini) Save(filename string) (err error) {
+ f, err := os.Create(filename)
+ if err != nil {
+ return
+ }
+
+ err = in.Write(f)
+
+ errClose := f.Close()
+ if errClose != nil {
+ println("ini.Save:", errClose)
+ }
+
+ return
+}
+
+//
+// Write the current parsed Ini into writer `w`.
+//
+func (in *Ini) Write(w io.Writer) (err error) {
+ for x := 0; x < len(in.secs); x++ {
+ fmt.Fprint(w, in.secs[x])
+
+ for _, v := range in.secs[x].Vars {
+ fmt.Fprint(w, v)
+ }
+ }
+
+ return
+}