Documentation ¶
Overview ¶
Package keyValue implements the basic key/value file format as described in desktop-entry-spec version 1.5. At the moment, these files can only be read from and not written to. The specification can be read at: https://specifications.freedesktop.org/desktop-entry-spec/1.5/
Index ¶
- Constants
- func ParseBoolean(value string) (bool, error)
- func ParseIconString(value string) (string, error)
- func ParseInteger(value string) (int, error)
- func ParseLocaleString(value string) (string, error)
- func ParseMultiple[T any](parser func(string) (T, error), value string, sep rune) ([]T, error)
- func ParseNumeric(value string) (float64, error)
- func ParseString(value string) (string, error)
- type Entry
- type File
- type Group
Constants ¶
const ( // ErrUnexpectedRune indicates an unexpected rune was encountered. ErrUnexpectedRune = keyValueError("unexpected rune") // ErrInvalidGroupHeader indicates a wrongly formatted group header was // encountered. ErrInvalidGroupHeader = keyValueError("invalid group header") // ErrInvalidEntry indicates a wrongly formatted key/value entry was // encountered. ErrInvalidEntry = keyValueError("invalid entry") // ErrDuplicateGroup indicates that two or more groups with the same // name were found. ErrDuplicateGroup = keyValueError("duplicate group name") // ErrDuplicateEntry indicates that two or more keys with the same name // were found. ErrDuplicateEntry = keyValueError("duplicate entry name") // ErrDuplicateLocalization indicates that two or more localized values // with the same locale were provided for the same entry. ErrDuplicateLocalization = keyValueError("duplicate localization") // ErrNoDefaultValue indicates that localized values were provided for // an entry with no default value. ErrNoDefaultValue = keyValueError("no default value") // ErrEntryOutsideGroup indicates that an entry was found. ErrEntryOutsideGroup = keyValueError("entry outside group") // ErrUnsupportedEscape indicates that an unsupported escape sequence // was found. ErrUnsupportedEscape = keyValueError("unsupported escape") // ErrStringNotASCII indicates that a string or iconstring value was not // found to contain valid ASCII text. ErrStringNotASCII = keyValueError("string not ascii") // ErrBooleanNotTrueOrFalse indicates that a boolean value was not found // to equal "true" or "false". ErrBooleanNotTrueOrFalse = keyValueError("boolean not true or false") )
Variables ¶
This section is empty.
Functions ¶
func ParseBoolean ¶
ParseBoolean parses a value of type boolean. Values of type boolean must either be the string true or false.
func ParseIconString ¶
ParseIconString parses a value of type iconstring. Values of type iconstring are the names of icons; these may be absolute paths, or symbolic names for icons located using the algorithm described in the Icon Theme Specification. Such values are not user-displayable, and are encoded in UTF-8. The escape sequences \s, \n, \t, \r, and \\ are supported, meaning ASCII space, newline, tab, carriage return, and backslash, respectively.
func ParseInteger ¶
ParseInteger parses a value of type integer. The geniuses at freedesktop never explained this type at all, or how it should be parsed.
func ParseLocaleString ¶
ParseLocaleString parses a value of type localestring. Values of type localestring are user displayable, and are encoded in UTF-8. The escape sequences \s, \n, \t, \r, and \\ are supported, meaning ASCII space, newline, tab, carriage return, and backslash, respectively.
func ParseMultiple ¶
ParseMultiple parses multiple of a value type. Any value parsing function can be specified. The multiple values should be separated by a separator and the input string may be optionally terminated by a separator. Trailing empty strings must always be terminated with a separator. Separators in these values need to be escaped using \<sep>.
func ParseNumeric ¶
ParseNumeric parses a value of type numeric. Values of type numeric must be a valid floating point number as recognized by the %f specifier for scanf in the C locale.
func ParseString ¶
ParseString parses a value of type string. Values of type string may contain all ASCII characters except for control characters. The escape sequences \s, \n, \t, \r, and \\ are supported, meaning ASCII space, newline, tab, carriage return, and backslash, respectively.
Types ¶
type Entry ¶
Entry represents an entry in a group.
func (Entry) Localize ¶
Localize returns a localized value matching the specified locale, which should be LC_MESSAGES for a system-localized value.
The matching is done as follows. If locale is of the form lang_COUNTRY.ENCODING@MODIFIER, then it will match a key of the form lang_COUNTRY@MODIFIER. If such a key does not exist, it will attempt to match lang_COUNTRY followed by lang@MODIFIER. Then, a match against lang by itself will be attempted. Finally, if no matching key is found the required key without a locale specified is used. The encoding from the locale value is ignored when matching.