txtparser

package
v0.0.0-...-883cb22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperatorLessThan      = "<"
	OperatorLessThanEqual = "<="
	OperatorMoreThan      = ">"
	OperatorMoreThanEqual = ">="
	OperatorEqual         = "="
)

Operator definitions

Variables

View Source
var RegexKeyOperatorValue = regexp.MustCompile(`([\w.+_-]+)\s*([<=>]+)\s*["']*(.*?)["']*$`)

RegexKeyOperatorValue breaks up a line into key, operator, value.

Functions

func GetINIFileDescriptiveName

func GetINIFileDescriptiveName(fileName string) string

GetINIFileDescriptiveName return the descriptive name of the Note

func GetINIFileVersionSectionEntry

func GetINIFileVersionSectionEntry(fileName, entryName string) string

GetINIFileVersionSectionEntry returns the field 'entryName' from the version section of the Note configuration file

Types

type INIEntry

type INIEntry struct {
	Section  string
	Key      string
	Operator Operator
	Value    string
}

INIEntry contains a single key-value pair in INI file.

type INIFile

type INIFile struct {
	AllValues []INIEntry
	KeyValue  map[string]map[string]INIEntry
}

INIFile contains all key-value pairs of an INI file.

func ParseINI

func ParseINI(input string) *INIFile

ParseINI parse the content of the configuration file

func ParseINIFile

func ParseINIFile(fileName string, autoCreate bool) (*INIFile, error)

ParseINIFile read the content of the configuration file

type Operator

type Operator string

Operator is the comparison or assignment operator used in an INI file entry

type Sysconfig

type Sysconfig struct {
	AllValues []*SysconfigEntry // All key-value pairs in the orignal order.
	KeyValue  map[string]*SysconfigEntry
}

Sysconfig contains key-value pairs of a sysconfig file. It is able to convert back to original text in the original key order.

func ParseSysconfig

func ParseSysconfig(input string) (*Sysconfig, error)

ParseSysconfig read sysconfig text and parse the text into memory structures.

func ParseSysconfigFile

func ParseSysconfigFile(fileName string, autoCreate bool) (*Sysconfig, error)

ParseSysconfigFile read sysconfig file and parse the file content into memory structures.

func (*Sysconfig) GetBool

func (conf *Sysconfig) GetBool(key string, defaultValue bool) bool

GetBool return bool value that belongs to the key, or the default value if key does not exist. True values are "yes" or "true".

func (*Sysconfig) GetInt

func (conf *Sysconfig) GetInt(key string, defaultValue int) int

GetInt return integer value that belongs to the key, or the default value if the key does not exist or value is not an integer.

func (*Sysconfig) GetIntArray

func (conf *Sysconfig) GetIntArray(key string, defaultValue []int) (ret []int)

GetIntArray assume the key carries a space-separated array of integers, return the array. Discard malformed integers.

func (*Sysconfig) GetString

func (conf *Sysconfig) GetString(key, defaultValue string) string

GetString return string value that belongs to the key, or the default value if the key does not exist.

func (*Sysconfig) GetStringArray

func (conf *Sysconfig) GetStringArray(key string, defaultValue []string) (ret []string)

GetStringArray assume the key carries a space-separated array value, return the value array.

func (*Sysconfig) GetUint64

func (conf *Sysconfig) GetUint64(key string, defaultValue uint64) uint64

GetUint64 return uint64 value that belongs to the key, or the default value if the key does not exist or value is not an integer.

func (*Sysconfig) Set

func (conf *Sysconfig) Set(key string, value interface{})

Set value for a key. If the key does not yet exist, it is created.

func (*Sysconfig) SetIntArray

func (conf *Sysconfig) SetIntArray(key string, values []int)

SetIntArray give a space-separated integer array value to a key. If the key does not yet exist, it is created.

func (*Sysconfig) SetStrArray

func (conf *Sysconfig) SetStrArray(key string, values []string)

SetStrArray give a space-separated string array value to a key. If the key does not yet exist, it is created.

func (*Sysconfig) ToText

func (conf *Sysconfig) ToText() string

ToText convert key-value pairs back into text. Values are always surrounded by double-quotes.

type SysconfigEntry

type SysconfigEntry struct {
	LeadingComments []string // The comment lines leading to the key-value pair, including prefix '#', excluding end-of-line.
	Key             string   // The key.
	Value           string   // The value, excluding '=' character and double-quotes. Values will always come in double-quotes when converted to text.
}

SysconfigEntry contains a single key-value pair in sysconfig file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL