Documentation ¶
Overview ¶
Package literal implements conversions to and from string representations of basic data types.
Index ¶
- Constants
- func IndentTabs(s string, n int) string
- func ParseNum(s string, n *NumInfo) error
- func Unquote(s string) (string, error)
- type Form
- func (f Form) Append(buf []byte, s string) []byte
- func (f Form) AppendEscaped(buf []byte, s string) []byte
- func (f Form) Quote(s string) string
- func (f Form) WithASCIIOnly() Form
- func (f Form) WithGraphicOnly() Form
- func (f Form) WithOptionalTabIndent(tabs int) Form
- func (f Form) WithTabIndent(n int) Form
- type Multiplier
- type NumInfo
- type QuoteInfo
Constants ¶
const ( K = mulDec | mul1 M = mulDec | mul2 G = mulDec | mul3 T = mulDec | mul4 P = mulDec | mul5 E = mulDec | mul6 Z = mulDec | mul7 Y = mulDec | mul8 Ki = mulBin | mul1 Mi = mulBin | mul2 Gi = mulBin | mul3 Ti = mulBin | mul4 Pi = mulBin | mul5 Ei = mulBin | mul6 Zi = mulBin | mul7 Yi = mulBin | mul8 )
Variables ¶
This section is empty.
Functions ¶
func IndentTabs ¶
IndentTabs takes a quoted string and reindents it for the given indentation. If a string is not a multiline string it will return the string as is.
Types ¶
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
Form defines how to quote a string or bytes literal.
func (Form) Append ¶
Append appends a CUE string literal representing s, as generated by Quote, to buf and returns the extended buffer.
func (Form) AppendEscaped ¶
AppendEscaped appends a CUE string literal representing s, as generated by Quote but without the quotes, to buf and returns the extended buffer.
It does not include the last indentation.
func (Form) Quote ¶
Quote returns CUE string literal representing s. The returned string uses CUE escape sequences (\t, \n, \u00FF, \u0100) for control characters and non-printable characters as defined by strconv.IsPrint.
It reports an error if the string cannot be converted to the desired form.
func (Form) WithASCIIOnly ¶
WithASCIIOnly ensures the quoted strings consists solely of valid ASCII characters.
func (Form) WithGraphicOnly ¶
WithGraphicOnly ensures the quoted strings consists solely of printable characters.
func (Form) WithOptionalTabIndent ¶
WithOptionalIndent is like WithTabIndent, but only returns a multiline strings if it doesn't contain any newline characters.
func (Form) WithTabIndent ¶
WithTabIndent returns a new Form with indentation set to the given number of tabs. The result will be a multiline string.
type Multiplier ¶
type Multiplier byte
A Multiplier indicates a multiplier indicator used in the literal.
type NumInfo ¶
type NumInfo struct { UseSep bool // contains filtered or unexported fields }
NumInfo contains information about a parsed numbers.
Reusing a NumInfo across parses may avoid memory allocations.
func (*NumInfo) Multiplier ¶
func (p *NumInfo) Multiplier() Multiplier
Multiplier reports which multiplier was used in an integral number.
type QuoteInfo ¶
type QuoteInfo struct {
// contains filtered or unexported fields
}
QuoteInfo describes the type of quotes used for a string.
func ParseQuotes ¶
ParseQuotes checks if the opening quotes in start matches the ending quotes in end and reports its type as q or an error if they do not matching or are invalid. nStart indicates the number of bytes used for the opening quote.
func (QuoteInfo) Unquote ¶
Unquote unquotes the given string. It must be terminated with a quote or an interpolation start. Escape sequences are expanded and surrogates are replaced with the corresponding non-surrogate code points.
func (QuoteInfo) Whitespace ¶
Whitespace returns prefix whitespace for multiline strings.