keyValue

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

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

View Source
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

func ParseBoolean(value string) (bool, error)

ParseBoolean parses a value of type boolean. Values of type boolean must either be the string true or false.

func ParseIconString

func ParseIconString(value string) (string, error)

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

func ParseInteger(value string) (int, error)

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

func ParseLocaleString(value string) (string, error)

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

func ParseMultiple[T any](parser func(string) (T, error), value string, sep rune) ([]T, error)

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

func ParseNumeric(value string) (float64, error)

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

func ParseString(value string) (string, error)

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

type Entry struct {
	Value     string
	Localized map[locale.Locale]string
}

Entry represents an entry in a group.

func (Entry) Localize

func (entry Entry) Localize(locale locale.Locale) string

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.

func (Entry) Unescape

func (entry Entry) Unescape() (Entry, error)

Unescape returns a new copy of this entry with its main value parsed and unescaped as a string, and its localized values parsed and unescaped as localestrings.

type File

type File map[string]Group

File represents a key/value file.

func Parse

func Parse(reader io.Reader) (File, error)

Parse parses a key/value file from a Reader.

func (File) String

func (file File) String() string

String returns a string representation of the file.

type Group

type Group map[string]Entry

Group represents a group of entries.

Jump to

Keyboard shortcuts

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