Documentation
¶
Overview ¶
Code generated by _tools; DO NOT EDIT.
Code generated by _tools; DO NOT EDIT.
Package util provides utility functions for the goldmark.
Index ¶
- func BytesToReadOnlyString(b []byte) string
- func DoFullUnicodeCaseFolding(v []byte) []byte
- func EastAsianWidth(r rune) string
- func EscapeHTML(v []byte) []byte
- func EscapeHTMLByte(b byte) []byte
- func FirstNonSpacePosition(bs []byte) int
- func IndentPosition(bs []byte, currentPos, width int) (pos, padding int)
- func IndentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, padding int)
- func IndentWidth(bs []byte, currentPos int) (width, pos int)
- func IsAlphaNumeric(c byte) bool
- func IsBlank(bs []byte) bool
- func IsEastAsianWideRune(r rune) bool
- func IsHexDecimal(c byte) bool
- func IsNumeric(c byte) bool
- func IsPunct(c byte) bool
- func IsPunctRune(r rune) bool
- func IsSpace(c byte) bool
- func IsSpaceDiscardingUnicodeRune(r rune) bool
- func IsSpaceRune(r rune) bool
- func ReadWhile(source []byte, index [2]int, pred func(byte) bool) (int, bool)
- func ReplaceSpaces(source []byte, repl byte) []byte
- func ResolveEntityNames(source []byte) []byte
- func ResolveNumericReferences(source []byte) []byte
- func StringToReadOnlyBytes(s string) []byte
- func TabWidth(currentPos int) int
- func ToLinkReference(v []byte) string
- func ToRune(source []byte, pos int) rune
- func ToValidRune(v rune) rune
- func TrimLeft(source, b []byte) []byte
- func TrimLeftLength(source, s []byte) int
- func TrimLeftSpace(source []byte) []byte
- func TrimLeftSpaceLength(source []byte) int
- func TrimRight(source, b []byte) []byte
- func TrimRightLength(source, s []byte) int
- func TrimRightSpace(source []byte) []byte
- func TrimRightSpaceLength(source []byte) int
- func URLEscape(v []byte, resolveReference bool) []byte
- func UTF8Len(b byte) int8
- func UnescapePunctuations(source []byte) []byte
- func VisualizeSpaces(bs []byte) []byte
- type BufWriter
- type BytesFilter
- type CopyOnWriteBuffer
- func (b *CopyOnWriteBuffer) Append(value []byte)
- func (b *CopyOnWriteBuffer) AppendByte(c byte)
- func (b *CopyOnWriteBuffer) AppendString(value string)
- func (b *CopyOnWriteBuffer) Bytes() []byte
- func (b *CopyOnWriteBuffer) IsCopied() bool
- func (b *CopyOnWriteBuffer) Write(value []byte)
- func (b *CopyOnWriteBuffer) WriteByte(c byte) error
- func (b *CopyOnWriteBuffer) WriteString(value string)
- type ErrorBufWriter
- type HTML5Entity
- type PrioritizedValue
- type PrioritizedValues
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToReadOnlyString ¶
BytesToReadOnlyString returns a string converted from given bytes.
func DoFullUnicodeCaseFolding ¶
DoFullUnicodeCaseFolding performs full unicode case folding to given bytes.
func EastAsianWidth ¶
EastAsianWidth returns the east asian width of the given rune. See https://www.unicode.org/reports/tr11/tr11-36.html
func EscapeHTML ¶
EscapeHTML escapes characters that should be escaped in HTML text.
func EscapeHTMLByte ¶
EscapeHTMLByte returns HTML escaped bytes if the given byte should be escaped, otherwise nil.
func FirstNonSpacePosition ¶
FirstNonSpacePosition returns a position line that is a first nonspace character.
func IndentPosition ¶
IndentPosition searches an indent position with the given width for the given line. If the line contains tab characters, paddings may be not zero. currentPos==0 and width==2:
position: 0 1
[TAB]aaaa
width: 1234 5678
width=2 is in the tab character. In this case, IndentPosition returns (pos=1, padding=2).
func IndentPositionPadding ¶
IndentPositionPadding searches an indent position with the given width for the given line. This function is mostly same as IndentPosition except this function takes account into additional paddings.
func IndentWidth ¶
IndentWidth calculate an indent width for the given line.
func IsAlphaNumeric ¶
IsAlphaNumeric returns true if the given character is a alphabet or a numeric, otherwise false.
func IsEastAsianWideRune ¶
IsEastAsianWideRune returns true if the given rune is an east asian wide character, otherwise false.
func IsHexDecimal ¶
IsHexDecimal returns true if the given character is a hexdecimal, otherwise false.
func IsPunctRune ¶
IsPunctRune returns true if the given rune is a punctuation, otherwise false.
func IsSpaceDiscardingUnicodeRune ¶
IsSpaceDiscardingUnicodeRune returns true if the given rune is space-discarding unicode character, otherwise false. See https://www.w3.org/TR/2020/WD-css-text-3-20200429/#space-discard-set
func IsSpaceRune ¶
IsSpaceRune returns true if the given rune is a space, otherwise false.
func ReplaceSpaces ¶
ReplaceSpaces replaces sequence of spaces with the given repl.
func ResolveEntityNames ¶
ResolveEntityNames resolve entity references like 'ö" .
func ResolveNumericReferences ¶
ResolveNumericReferences resolve numeric references like 'Ӓ" .
func StringToReadOnlyBytes ¶
StringToReadOnlyBytes returns bytes converted from given string.
func ToLinkReference ¶
ToLinkReference converts given bytes into a valid link reference string. ToLinkReference performs unicode case folding, trims leading and trailing spaces, converts into lower case and replace spaces with a single space character.
func ToValidRune ¶
ToValidRune returns 0xFFFD if the given rune is invalid, otherwise v.
func TrimLeft ¶
TrimLeft trims characters in the given s from head of the source. bytes.TrimLeft offers same functionalities, but bytes.TrimLeft allocates new buffer for the result.
func TrimLeftLength ¶
TrimLeftLength returns a length of leading specified characters.
func TrimLeftSpace ¶
TrimLeftSpace returns a subslice of the given string by slicing off all leading space characters.
func TrimLeftSpaceLength ¶
TrimLeftSpaceLength returns a length of leading space characters.
func TrimRightLength ¶
TrimRightLength returns a length of trailing specified characters.
func TrimRightSpace ¶
TrimRightSpace returns a subslice of the given string by slicing off all trailing space characters.
func TrimRightSpaceLength ¶
TrimRightSpaceLength returns a length of trailing space characters.
func URLEscape ¶
URLEscape escape the given URL. If resolveReference is set true:
- unescape punctuations
- resolve numeric references
- resolve entity references
URL encoded values (%xx) are kept as is.
func UnescapePunctuations ¶
UnescapePunctuations unescapes blackslash escaped punctuations.
func VisualizeSpaces ¶
VisualizeSpaces visualize invisible space characters.
Types ¶
type BufWriter ¶
type BufWriter interface {
io.Writer
WriteByte(c byte) error
WriteRune(r rune) (size int, err error)
WriteString(s string) (int, error)
Flush() error
}
A BufWriter is a subset of the bufio.Writer .
type BytesFilter ¶
type BytesFilter interface {
// Add adds given bytes to this set.
Add([]byte)
// Contains return true if this set contains given bytes, otherwise false.
Contains([]byte) bool
// Extend copies this filter and adds given bytes to new filter.
Extend(...[]byte) BytesFilter
// ExtendString copies this filter and adds given bytes to new filter.
// Given string must be separated by a comma.
ExtendString(string) BytesFilter
}
BytesFilter is a efficient data structure for checking whether bytes exist or not. BytesFilter is thread-safe.
func NewBytesFilter ¶
func NewBytesFilter(elements ...[]byte) BytesFilter
NewBytesFilter returns a new BytesFilter.
func NewBytesFilterString ¶
func NewBytesFilterString(elements string) BytesFilter
NewBytesFilterString returns a new BytesFilter. Given string must be separated by a comma.
type CopyOnWriteBuffer ¶
type CopyOnWriteBuffer struct {
// contains filtered or unexported fields
}
A CopyOnWriteBuffer is a byte buffer that copies buffer when it need to be changed.
func NewCopyOnWriteBuffer ¶
func NewCopyOnWriteBuffer(buffer []byte) CopyOnWriteBuffer
NewCopyOnWriteBuffer returns a new CopyOnWriteBuffer.
func (*CopyOnWriteBuffer) Append ¶
func (b *CopyOnWriteBuffer) Append(value []byte)
Append appends given bytes to the buffer. Append copy buffer at the first time.
func (*CopyOnWriteBuffer) AppendByte ¶
func (b *CopyOnWriteBuffer) AppendByte(c byte)
AppendByte appends given bytes to the buffer. AppendByte copy buffer at the first time.
func (*CopyOnWriteBuffer) AppendString ¶
func (b *CopyOnWriteBuffer) AppendString(value string)
AppendString appends given string to the buffer. AppendString copy buffer at the first time.
func (*CopyOnWriteBuffer) Bytes ¶
func (b *CopyOnWriteBuffer) Bytes() []byte
Bytes returns bytes of this buffer.
func (*CopyOnWriteBuffer) IsCopied ¶
func (b *CopyOnWriteBuffer) IsCopied() bool
IsCopied returns true if buffer has been copied, otherwise false.
func (*CopyOnWriteBuffer) Write ¶
func (b *CopyOnWriteBuffer) Write(value []byte)
Write writes given bytes to the buffer. Write allocate new buffer and clears it at the first time.
func (*CopyOnWriteBuffer) WriteByte ¶
func (b *CopyOnWriteBuffer) WriteByte(c byte) error
WriteByte writes the given byte to the buffer. WriteByte allocate new buffer and clears it at the first time.
func (*CopyOnWriteBuffer) WriteString ¶
func (b *CopyOnWriteBuffer) WriteString(value string)
WriteString writes given string to the buffer. WriteString allocate new buffer and clears it at the first time.
type ErrorBufWriter ¶
type ErrorBufWriter interface {
BufWriter
// Error returns the first error that occurred in any of its methods, or nil if no error occurred.
Error() error
}
ErrorBufWriter is a BufWriter that can return the first error that occurred in any of its methods.
func NewErrorBufWriter ¶
func NewErrorBufWriter(w io.Writer) ErrorBufWriter
NewErrorBufWriter returns a new ErrorBufWriter.
func NewErrorBufWriterSize ¶
func NewErrorBufWriterSize(w io.Writer, size int) ErrorBufWriter
NewErrorBufWriterSize returns a new ErrorBufWriter with the given buffer size.
type HTML5Entity ¶
HTML5Entity struct represents HTML5 entitites.
func LookUpHTML5EntityByName ¶
func LookUpHTML5EntityByName(name string) (*HTML5Entity, bool)
LookUpHTML5EntityByName returns (an HTML5Entity, true) if an entity named given name is found, otherwise (nil, false).
type PrioritizedValue ¶
type PrioritizedValue[T any] struct { // Value is an arbitrary value that you want to prioritize. Value T // Priority is a priority of the value. Priority int }
A PrioritizedValue struct holds pair of an arbitrary value and a priority.
func Prioritized ¶
func Prioritized[T any](v T, priority int) PrioritizedValue[T]
Prioritized returns a new PrioritizedValue.
type PrioritizedValues ¶
type PrioritizedValues[T comparable] []PrioritizedValue[T]
PrioritizedValues is a slice of the PrioritizedValues.
func (PrioritizedValues[T]) Remove ¶
func (s PrioritizedValues[T]) Remove(v T) PrioritizedValues[T]
Remove removes the given value from this slice.
func (PrioritizedValues[T]) Sort ¶
func (s PrioritizedValues[T]) Sort()
Sort sorts the PrioritizedValues in ascending order.