keyfile

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: BSD-3-Clause Imports: 8 Imported by: 8

Documentation

Overview

Package keyfile implements the ini file format that is used in many of the xdg specs.

WARNING: This package is meant for internal use and the API may change without warning.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid               = errors.New("invalid keyfile format")
	ErrBadEscapeSequence     = errors.New("bad escape sequence")
	ErrUnexpectedEndOfString = errors.New("unexpected end of string")
)

These errors can be returned if there is a problem processing a keyfile's contents.

View Source
var ErrBadLocaleFormat = errors.New("bad locale format")

ErrBadLocaleFormat is returned by ParseLocale when the given string is not formatted properly (for example, missing the lang component).

Functions

This section is empty.

Types

type KeyFile

type KeyFile struct {
	// contains filtered or unexported fields
}

KeyFile is an implementation of the keyfile format used by several FreeDesktop.org (xdg) specs. The key values without a header section can be accessed using an empty string as the group.

func New

func New(r io.Reader) (*KeyFile, error)

New creates a new KeyFile and returns it.

func (*KeyFile) Bool

func (kf *KeyFile) Bool(g, k string) (bool, error)

Bool returns the value for group 'g' and key 'k' as a bool.

func (*KeyFile) GroupExists

func (kf *KeyFile) GroupExists(g string) bool

GroupExists returns a bool indicating whether the given group 'g' exists.

func (*KeyFile) Groups

func (kf *KeyFile) Groups() []string

Groups returns a slice of groups that exist for the KeyFile.

func (*KeyFile) KeyExists

func (kf *KeyFile) KeyExists(g, k string) bool

KeyExists returns a bool indicating whether the given group 'g' and key 'k' exists.

func (*KeyFile) Keys

func (kf *KeyFile) Keys(g string) []string

Keys returns a slice of keys that exist for the given group 'g'.

func (*KeyFile) LocaleString

func (kf *KeyFile) LocaleString(g, k string) (string, error)

LocaleString returns the value for group 'g' and key 'k' using the system's locale.

func (*KeyFile) LocaleStringList

func (kf *KeyFile) LocaleStringList(g, k string) ([]string, error)

LocaleStringList returns a slice of strings for group 'g' and key 'k'.

func (*KeyFile) LocaleStringListWithLocale

func (kf *KeyFile) LocaleStringListWithLocale(g, k string, l Locale) ([]string, error)

LocaleStringListWithLocale returns a slice of strings for group 'g', key 'k', and locale 'l'.

func (*KeyFile) LocaleStringWithLocale

func (kf *KeyFile) LocaleStringWithLocale(g, k string, l Locale) (string, error)

LocaleStringWithLocale returns the value for group 'g', key 'k', and locale 'l'.

func (*KeyFile) Number

func (kf *KeyFile) Number(g, k string) (float64, error)

Number returns the value for group 'g' and key 'k' as a float64.

func (*KeyFile) String

func (kf *KeyFile) String(g, k string) (string, error)

String returns the value for group 'g' and key 'k' as a string. String will return a blank string if the key doesn't exist; use GroupExists or KeyExists to if you need to treat a missing value differently then a blank value.

func (*KeyFile) StringList

func (kf *KeyFile) StringList(g, k string) ([]string, error)

StringList returns a slice of strings for group 'g' and key 'k'. StringList will return an empty slice if the key doesn't exist; use GroupExists or KeyExists to if you need to treat a missing value differently then a blank value.

func (*KeyFile) Value

func (kf *KeyFile) Value(g, k string) string

Value returns the raw string for group 'g' and key 'k'. Value will return a blank string if the key doesn't exist; use GroupExists or KeyExists to if you need to treat a missing value differently then a blank value.

func (*KeyFile) ValueList

func (kf *KeyFile) ValueList(g, k string) ([]string, error)

ValueList returns a slice of raw strings for group 'g' and key 'k'. ValueList will return an empty slice if the key doesn't exist; use GroupExists or KeyExists to if you need to treat a missing value differently then a blank value.

type Locale

type Locale struct {
	// contains filtered or unexported fields
}

Locale represents a locale for use in parsing translatable strings.

func DefaultLocale

func DefaultLocale() Locale

DefaultLocale returns the locale specified by the environment.

func ParseLocale

func ParseLocale(s string) (Locale, error)

ParseLocale parses a locale in the format

lang_COUNTRY.ENCODING@MODIFIER

where "_COUNTRY", ".ENCODING", and "@MODIFIER" can be omitted. A blank string, "C", and "POSIX" are special cases that evaluate to a blank Locale.

func (Locale) String

func (l Locale) String() string

String returns the given locale as a formatted string. The returned string is in the same format expected by ParseLocale.

func (Locale) Variants

func (l Locale) Variants() []Locale

Variants returns a sorted slice of Locales that should be checked for when resolving a localestring.

Jump to

Keyboard shortcuts

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