package literal
import "cuelang.org/go/cue/literal"
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
- func (p *NumInfo) Decimal(v *decimal) error
- func (p *NumInfo) IsInt() bool
- func (p *NumInfo) Multiplier() Multiplier
- func (p *NumInfo) String() string
- 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 )
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.
func ParseNum ¶
ParseNum parses s and populates NumInfo with the result.
func Unquote ¶
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.
Types ¶
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
Form defines how to quote a string or bytes literal.
var ( // String defines the format of a CUE string. Conversions may be lossy. String Form = stringForm // Label is like String, but optimized for labels. Label Form = stringForm // Bytes defines the format of bytes literal. Bytes Form = bytesForm )
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) Decimal ¶
Decimal is for internal use.
func (*NumInfo) IsInt ¶
IsInt reports whether the number is an integral number.
func (*NumInfo) Multiplier ¶
func (p *NumInfo) Multiplier() Multiplier
Multiplier reports which multiplier was used in an integral number.
func (*NumInfo) String ¶
String returns a canonical string representation of the number so that it can be parsed with math.Float.Parse.
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) IsDouble ¶
IsDouble reports whether the literal uses double quotes.
func (QuoteInfo) IsMulti ¶
IsMulti reports whether a multi-line string was parsed.
func (QuoteInfo) Unquote ¶
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 (QuoteInfo) Whitespace ¶
Whitespace returns prefix whitespace for multiline strings.
Source Files ¶
doc.go indent.go num.go quote.go string.go
- Version
- v0.12.0 (latest)
- Published
- Jan 30, 2025
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 5 hours ago –
Tools for package owners.