Documentation
¶
Overview ¶
Package text is a collection of helpers for working with text inside nostr events such as implementing the string escaping scheme defined in NIP-01.
Index ¶
- func AppendBackticks(dst, src []byte, ac AppendBytesClosure) []byte
- func AppendBinaryFromHex(dst, src []byte, unquote bool) (b []byte, err error)
- func AppendBrace(dst, src []byte, ac AppendBytesClosure) []byte
- func AppendBracket(dst, src []byte, ac AppendBytesClosure) []byte
- func AppendHexFromBinary(dst, src []byte, quote bool) (b []byte)
- func AppendList(dst []byte, src [][]byte, separator byte, ac AppendBytesClosure) []byte
- func AppendParenthesis(dst, src []byte, ac AppendBytesClosure) []byte
- func AppendQuote(dst, src []byte, ac AppendBytesClosure) []byte
- func AppendSingleQuote(dst, src []byte, ac AppendBytesClosure) []byte
- func Comma(b []byte) (rem []byte, err error)
- func False() []byte
- func JSONKey(dst, k []byte) (b []byte)
- func MarshalBool(src []byte, truth bool) []byte
- func MarshalHexArray(dst []byte, ha [][]byte) (b []byte)
- func Noop(dst, src []byte) []byte
- func NostrEscape(dst, src []byte) []byte
- func NostrUnescape(dst []byte) (b []byte)
- func Quote(dst, src []byte) []byte
- func True() []byte
- func UnmarshalBool(src []byte) (rem []byte, truth bool, err error)
- func UnmarshalHex(b []byte) (h []byte, rem []byte, err error)
- func UnmarshalHexArray(b []byte, size int) (t [][]byte, rem []byte, err error)
- func UnmarshalQuoted(b []byte) (content, rem []byte, err error)
- func UnmarshalStringArray(b []byte) (t [][]byte, rem []byte, err error)
- func Unquote(b []byte) []byte
- type AppendBytesClosure
- type AppendClosure
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendBackticks ¶
func AppendBackticks(dst, src []byte, ac AppendBytesClosure) []byte
AppendBackticks appends a provided AppendBytesClosure's output from a given source of bytes, wrapped in backticks “.
func AppendBinaryFromHex ¶
AppendBinaryFromHex encodes binary input as hex and appends it to the output.
func AppendBrace ¶
func AppendBrace(dst, src []byte, ac AppendBytesClosure) []byte
AppendBrace appends a provided AppendBytesClosure's output from a given source of bytes, wrapped in braces ().
func AppendBracket ¶
func AppendBracket(dst, src []byte, ac AppendBytesClosure) []byte
AppendBracket appends a provided AppendBytesClosure's output from a given source of bytes, wrapped in brackets [].
func AppendHexFromBinary ¶
AppendHexFromBinary appends to a hex output from binary input.
func AppendList ¶
func AppendList( dst []byte, src [][]byte, separator byte, ac AppendBytesClosure, ) []byte
AppendList appends an input source bytes processed by an AppendBytesClosure and separates elements with the given separator byte.
func AppendParenthesis ¶
func AppendParenthesis(dst, src []byte, ac AppendBytesClosure) []byte
AppendParenthesis appends a provided AppendBytesClosure's output from a given source of bytes, wrapped in parentheses {}.
func AppendQuote ¶
func AppendQuote(dst, src []byte, ac AppendBytesClosure) []byte
AppendQuote appends a source of bytes, that have been processed by an AppendBytesClosure and returns the appended-to slice.
func AppendSingleQuote ¶
func AppendSingleQuote(dst, src []byte, ac AppendBytesClosure) []byte
AppendSingleQuote appends a provided AppendBytesClosure's output from a given source of bytes, wrapped in single quotes ”.
func JSONKey ¶
JSONKey generates the JSON format for an object key and terminates with the semicolon.
func MarshalBool ¶
func MarshalHexArray ¶
func NostrEscape ¶
NostrEscape for JSON encoding according to RFC8259.
This is the efficient implementation based on the NIP-01 specification:
To prevent implementation differences from creating a different event Id for the same event, the following rules MUST be followed while serializing:
No whitespace, line breaks or other unnecessary formatting should be included in the output JSON. No characters except the following should be escaped, and instead should be included verbatim: - A line break, 0x0A, as \n - A double quote, 0x22, as \" - A backslash, 0x5C, as \\ - A carriage return, 0x0D, as \r - A tab character, 0x09, as \t - A backspace, 0x08, as \b - A form feed, 0x0C, as \f UTF-8 should be used for encoding.
func NostrUnescape ¶
NostrUnescape reverses the operation of NostrEscape except instead of appending it to the provided slice, it rewrites it, eliminating a memory copy. Keep in mind that the original JSON will be mangled by this operation, but the resultant slices will cost zero allocations.
func Quote ¶
Quote simply quotes a provided source and attaches it to the provided destination slice.
func UnmarshalHex ¶
UnmarshalHex takes a byte string that should contain a quoted hexadecimal encoded value, decodes it using a SIMD hex codec and returns the decoded bytes in a newly allocated buffer.
func UnmarshalHexArray ¶
UnmarshalHexArray unpacks a JSON array containing strings with hexadecimal, and checks all values have the specified byte size.
func UnmarshalQuoted ¶
UnmarshalQuoted performs an in-place unquoting of NIP-01 quoted byte string.
func UnmarshalStringArray ¶
UnmarshalStringArray unpacks a JSON array containing strings.
Types ¶
type AppendBytesClosure ¶
AppendBytesClosure is a function type for appending data from a source to a destination and returning the appended-to slice.
type AppendClosure ¶
AppendClosure is a simple append where the caller appends to the destination and returns the appended-to slice.