Documentation
¶
Index ¶
- Constants
- func AppendEscape(buf []byte, str string) []byte
- func AppendEscapeByte(buf []byte, c byte) []byte
- func AppendEscapeRune(buf []byte, r rune) []byte
- func AppendQuoteByte(buf []byte, c byte) []byte
- func ContainsDoubleQuote(s string) bool
- func ContainsSpaceOrTab(s string) bool
- func IsSafeASCII(str string) bool
- type Args
- func (a *Args) AsNumber() bool
- func (a *Args) AsQuotedASCII() bool
- func (a *Args) AsQuotedText() bool
- func (a *Args) AsText() bool
- func (a *Args) Logfmt() bool
- func (a *Args) NoMethod() bool
- func (a *Args) SetAsNumber()
- func (a *Args) SetAsQuotedASCII()
- func (a *Args) SetAsQuotedText()
- func (a *Args) SetAsText()
- func (a *Args) SetLogfmt()
- func (a *Args) SetNoMethod()
- func (a *Args) SetWithType()
- func (a *Args) UnsetAsNumber()
- func (a *Args) UnsetAsQuotedASCII()
- func (a *Args) UnsetAsQuotedText()
- func (a *Args) UnsetAsText()
- func (a *Args) UnsetLogfmt()
- func (a *Args) UnsetNoMethod()
- func (a *Args) UnsetWithType()
- func (a *Args) WithType() bool
- type ComplexArgs
- type FloatArgs
- type FormatFunc
- type Formattable
- type Formatter
- type IntArgs
- type State
- type Stringer
Constants ¶
const ( // TypeMask when set in argument flags // indicates that type information of // the passed value, and all nested types, // should be included in formatted output. TypeMask = uint64(1) << 0 // LogfmtMask when set in argument flags // indicates that strings should be escaped // and quoted only where necessary. i.e. if // it contains any unsafe ASCII chars or double // quotes it will be quoted and escaped, if it // contains any spaces it will be quoted, and // all else will be printed as-is. This proves // particularly well readable in key-value types. LogfmtMask = uint64(1) << 1 // NumberMask when set in argument flags // indicates that where possible value // types should be formatted as numbers, // i.e. byte or rune types. NumberMask = uint64(1) << 2 // TextMask when set in argument flags // indicates that where possible value // types should be formatted as text, // i.e. []byte or []rune types. TextMask = uint64(1) << 3 // QuotedTextMask when set in argument flags // indicates that text should always be quoted. QuotedTextMask = uint64(1) << 4 // QuotedAsciiMask when set in argument flags // indicates that text should always be quoted, // and escaped as ASCII characters where needed. QuotedAsciiMask = uint64(1) << 5 // NoMethodMask when set in argument flags // indicates that where a type supports a // known method, (e.g. Error() or String()), // this should not be used for formatting // instead treating as a method-less type. // e.g. printing the entire struct value of // a &url.URL{} without calling String(). NoMethodMask = uint64(1) << 6 )
const ( // SingleTermLine: beyond a certain length of string, all of the // extra checks to handle quoting/not-quoting add a significant // amount of extra processing time. Quoting in this manner only really // effects readability on a single line, so a max string length that // encompasses the maximum number of columns on *most* terminals was // selected. This was chosen using the metric that 1080p is one of the // most common display resolutions, and that a relatively small font size // of 7 requires 223 columns. So 256 should be >= $COLUMNS (fullscreen) // in 99% of usecases (these figures all pulled out of my ass). SingleTermLine = 256 )
Variables ¶
This section is empty.
Functions ¶
func AppendEscape ¶
AppendEscape will append 's' to 'buf' and escape any double quotes. EXPECTS ASCII.
func ContainsDoubleQuote ¶
ContainsDoubleQuote checks if "s" contains a double quote. EXPECTS ASCII.
func ContainsSpaceOrTab ¶
ContainsSpaceOrTab checks if "s" contains space or tabs. EXPECTS ASCII.
func IsSafeASCII ¶
IsSafeASCII checks whether string is printable (i.e. non-control char) ASCII text.
Types ¶
type Args ¶
type Args struct {
// Boolean argument
// flags as bit-field.
Flags uint64
// Integer
// arguments.
// i.e. for:
// - int
// - int8
// - int16
// - int32 (treated as rune char, number with NumberMask)
// - int64
Int IntArgs
// Unsigned
// integer
// arguments.
// i.e. for:
// - uint
// - uint8 (treated as byte char, number with NumberMask)
// - uint16
// - uint32
// - uint64
Uint IntArgs
// Float
// arguments.
// i.e. for:
// - float32
// - float64
Float FloatArgs
// Complex
// arguments.
// i.e. for:
// - complex64
// - complex128
Complex ComplexArgs
}
Args contains arguments for a call to a FormatFunc.
func (*Args) AsQuotedASCII ¶
AsQuotedASCII returns if QuotedAsciiMask is set.
func (*Args) AsQuotedText ¶
AsQuotedText returns if QuotedTextMask is set.
func (*Args) SetAsQuotedASCII ¶
func (a *Args) SetAsQuotedASCII()
SetAsQuotedASCII sets the QuotedAsciiMask bit.
func (*Args) SetAsQuotedText ¶
func (a *Args) SetAsQuotedText()
SetAsQuotedText sets the QuotedTextMask bit.
func (*Args) UnsetAsNumber ¶
func (a *Args) UnsetAsNumber()
UnsetAsNumber unsets the NumberMask bit.
func (*Args) UnsetAsQuotedASCII ¶
func (a *Args) UnsetAsQuotedASCII()
UnsetAsQuotedASCII unsets the QuotedAsciiMask bit.
func (*Args) UnsetAsQuotedText ¶
func (a *Args) UnsetAsQuotedText()
UnsetAsQuotedText unsets the QuotedTextMask bit.
func (*Args) UnsetNoMethod ¶
func (a *Args) UnsetNoMethod()
UnsetNoMethod unsets the NoMethodMask bit.
type ComplexArgs ¶
ComplexArgs provides a set of arguments for customizing complex number serialization, as real and imaginary float number parts.
type FormatFunc ¶
type FormatFunc func(*State)
FormatFunc defines a function capable of formatting the value contained in State{}.P, based on args in State{}.A, storing the result in buffer State{}.B.
type Formattable ¶ added in v2.0.6
type Formattable interface{ Format(*State) }
type Formatter ¶
type Formatter struct {
// Defaults defines the default
// set of arguments to use when
// none are supplied to calls to
// Append() and AppendState().
Defaults Args
// contains filtered or unexported fields
}
Formatter provides access to value formatting provided by this library. It encompasses a set of configurable default arguments for when none are set, and an internal concurrency-safe cache of FormatFuncs to passed value type.
var Global Formatter
Global formatter instance.
func (*Formatter) Append ¶
Append calls AppendState() with a newly allocated State{}, returning byte buffer.
func (*Formatter) AppendState ¶
AppendState will format the given value into the given State{}'s byte buffer, using currently-set arguments.
type State ¶
type State struct {
// A contains args
// passed to this
// FormatFunc call.
A Args
// B is the buffer
// that values will
// be formatted into.
B []byte
// P contains a ptr
// to the value type
// being formatted.
P unsafe.Pointer
// contains filtered or unexported fields
}
State contains all necessary arguments, buffer and value data pointer required for a FormatFunc operation, in a reusable structure if wanted.