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 )
func IndentTabs(s string, n int) string
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.
func ParseNum(s string, n *NumInfo) error
ParseNum parses s and populates NumInfo with the result.
func Unquote(s string) (string, error)
Unquote interprets s as a single- or double-quoted, single- or multi-line string, possibly with custom escape delimiters, returning the string value that s quotes.
Form defines how to quote a string or bytes literal.
type Form struct {
// contains filtered or unexported fields
}
var ( // String defines the format of a CUE string. Conversions may be lossy. String Form = stringForm // Label is like Text, but optimized for labels. Label Form = stringForm // Bytes defines the format of bytes literal. Bytes Form = bytesForm )
func (f Form) Append(buf []byte, s string) []byte
Append appends a CUE string literal representing s, as generated by Quote, to buf and returns the extended buffer.
func (f Form) AppendEscaped(buf []byte, s string) []byte
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 (f Form) Quote(s string) string
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 (f Form) WithASCIIOnly() Form
WithASCIIOnly ensures the quoted strings consists solely of valid ASCII characters.
func (f Form) WithGraphicOnly() Form
WithGraphicOnly ensures the quoted strings consists solely of printable characters.
func (f Form) WithOptionalTabIndent(tabs int) Form
WithOptionalIndent is like WithTabIndent, but only returns a multiline strings if it doesn't contain any newline characters.
func (f Form) WithTabIndent(n int) Form
WithTabIndent returns a new Form with indentation set to the given number of tabs. The result will be a multiline string.
A Multiplier indicates a multiplier indicator used in the literal.
type Multiplier byte
NumInfo contains information about a parsed numbers.
Reusing a NumInfo across parses may avoid memory allocations.
type NumInfo struct { UseSep bool // contains filtered or unexported fields }
func (p *NumInfo) Decimal(v *decimal) error
Decimal is for internal use.
func (p *NumInfo) IsInt() bool
IsInt reports whether the number is an integral number.
func (p *NumInfo) Multiplier() Multiplier
Multiplier reports which multiplier was used in an integral number.
func (p *NumInfo) String() string
String returns a canonical string representation of the number so that it can be parsed with math.Float.Parse.
QuoteInfo describes the type of quotes used for a string.
type QuoteInfo struct {
// contains filtered or unexported fields
}
func ParseQuotes(start, end string) (q QuoteInfo, nStart, nEnd int, err error)
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 (q QuoteInfo) IsDouble() bool
IsDouble reports whether the literal uses double quotes.
func (q QuoteInfo) IsMulti() bool
IsMulti reports whether a multi-line string was parsed.
func (q QuoteInfo) Unquote(s string) (string, error)
Unquote unquotes the given string, which should not contain the initial quote character(s). 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 (q QuoteInfo) Whitespace() string
Whitespace returns prefix whitespace for multiline strings.