util

package
v2.0.0-beta.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToReadOnlyString

func BytesToReadOnlyString(b []byte) string

BytesToReadOnlyString returns a string converted from given bytes.

func DoFullUnicodeCaseFolding

func DoFullUnicodeCaseFolding(v []byte) []byte

DoFullUnicodeCaseFolding performs full unicode case folding to given bytes.

func EastAsianWidth

func EastAsianWidth(r rune) string

EastAsianWidth returns the east asian width of the given rune. See https://www.unicode.org/reports/tr11/tr11-36.html

func EscapeHTML

func EscapeHTML(v []byte) []byte

EscapeHTML escapes characters that should be escaped in HTML text.

func EscapeHTMLByte

func EscapeHTMLByte(b byte) []byte

EscapeHTMLByte returns HTML escaped bytes if the given byte should be escaped, otherwise nil.

func FirstNonSpacePosition

func FirstNonSpacePosition(bs []byte) int

FirstNonSpacePosition returns a position line that is a first nonspace character.

func IndentPosition

func IndentPosition(bs []byte, currentPos, width int) (pos, padding int)

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

func IndentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, padding int)

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

func IndentWidth(bs []byte, currentPos int) (width, pos int)

IndentWidth calculate an indent width for the given line.

func IsAlphaNumeric

func IsAlphaNumeric(c byte) bool

IsAlphaNumeric returns true if the given character is a alphabet or a numeric, otherwise false.

func IsBlank

func IsBlank(bs []byte) bool

IsBlank returns true if the given string is all space characters.

func IsEastAsianWideRune

func IsEastAsianWideRune(r rune) bool

IsEastAsianWideRune returns true if the given rune is an east asian wide character, otherwise false.

func IsHexDecimal

func IsHexDecimal(c byte) bool

IsHexDecimal returns true if the given character is a hexdecimal, otherwise false.

func IsNumeric

func IsNumeric(c byte) bool

IsNumeric returns true if the given character is a numeric, otherwise false.

func IsPunct

func IsPunct(c byte) bool

IsPunct returns true if the given character is a punctuation, otherwise false.

func IsPunctRune

func IsPunctRune(r rune) bool

IsPunctRune returns true if the given rune is a punctuation, otherwise false.

func IsSpace

func IsSpace(c byte) bool

IsSpace returns true if the given character is a space, otherwise false.

func IsSpaceDiscardingUnicodeRune

func IsSpaceDiscardingUnicodeRune(r rune) bool

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

func IsSpaceRune(r rune) bool

IsSpaceRune returns true if the given rune is a space, otherwise false.

func ReadWhile

func ReadWhile(source []byte, index [2]int, pred func(byte) bool) (int, bool)

ReadWhile read the given source while pred is true.

func ReplaceSpaces

func ReplaceSpaces(source []byte, repl byte) []byte

ReplaceSpaces replaces sequence of spaces with the given repl.

func ResolveEntityNames

func ResolveEntityNames(source []byte) []byte

ResolveEntityNames resolve entity references like 'ö" .

func ResolveNumericReferences

func ResolveNumericReferences(source []byte) []byte

ResolveNumericReferences resolve numeric references like 'Ӓ" .

func StringToReadOnlyBytes

func StringToReadOnlyBytes(s string) []byte

StringToReadOnlyBytes returns bytes converted from given string.

func TabWidth

func TabWidth(currentPos int) int

TabWidth calculates actual width of a tab at the given position.

func ToLinkReference

func ToLinkReference(v []byte) string

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 ToRune

func ToRune(source []byte, pos int) rune

ToRune decode given bytes start at pos and returns a rune.

func ToValidRune

func ToValidRune(v rune) rune

ToValidRune returns 0xFFFD if the given rune is invalid, otherwise v.

func TrimLeft

func TrimLeft(source, b []byte) []byte

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

func TrimLeftLength(source, s []byte) int

TrimLeftLength returns a length of leading specified characters.

func TrimLeftSpace

func TrimLeftSpace(source []byte) []byte

TrimLeftSpace returns a subslice of the given string by slicing off all leading space characters.

func TrimLeftSpaceLength

func TrimLeftSpaceLength(source []byte) int

TrimLeftSpaceLength returns a length of leading space characters.

func TrimRight

func TrimRight(source, b []byte) []byte

TrimRight trims characters in the given s from tail of the source.

func TrimRightLength

func TrimRightLength(source, s []byte) int

TrimRightLength returns a length of trailing specified characters.

func TrimRightSpace

func TrimRightSpace(source []byte) []byte

TrimRightSpace returns a subslice of the given string by slicing off all trailing space characters.

func TrimRightSpaceLength

func TrimRightSpaceLength(source []byte) int

TrimRightSpaceLength returns a length of trailing space characters.

func URLEscape

func URLEscape(v []byte, resolveReference bool) []byte

URLEscape escape the given URL. If resolveReference is set true:

  1. unescape punctuations
  2. resolve numeric references
  3. resolve entity references

URL encoded values (%xx) are kept as is.

func UTF8Len

func UTF8Len(b byte) int8

UTF8Len returns a byte length of the utf-8 character.

func UnescapePunctuations

func UnescapePunctuations(source []byte) []byte

UnescapePunctuations unescapes blackslash escaped punctuations.

func VisualizeSpaces

func VisualizeSpaces(bs []byte) []byte

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

type HTML5Entity struct {
	Name       string
	Characters []byte
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL