func BytesToReadOnlyString(b []byte) string
BytesToReadOnlyString returns a string converted from given bytes.
func DedentPosition(bs []byte, currentPos, width int) (pos, padding int)
DedentPosition dedents lines by the given width.
Deprecated: This function has bugs. Use util.IndentPositionPadding and util.FirstNonSpacePosition.
func DedentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, padding int)
DedentPositionPadding dedents lines by the given width. This function is mostly same as DedentPosition except this function takes account into additional paddings.
Deprecated: This function has bugs. Use util.IndentPositionPadding and util.FirstNonSpacePosition.
func DoFullUnicodeCaseFolding(v []byte) []byte
DoFullUnicodeCaseFolding performs full unicode case folding to given bytes.
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(v []byte) []byte
EscapeHTML escapes characters that should be escaped in HTML text.
func EscapeHTMLByte(b byte) []byte
EscapeHTMLByte returns HTML escaped bytes if the given byte should be escaped, otherwise nil.
func FindClosure(bs []byte, opener, closure byte, codeSpan, allowNesting bool) int
FindClosure returns a position that closes the given opener. If codeSpan is set true, it ignores characters in code spans. If allowNesting is set true, closures correspond to nested opener will be ignored.
Deprecated: This function can not handle newlines. Many elements can be existed over multiple lines(e.g. link labels). Use text.Reader.FindClosure.
func FindEmailIndex(b []byte) int
FindEmailIndex returns a stop index value if the given bytes seem an email address.
func FindURLIndex(b []byte) int
FindURLIndex returns a stop index value if the given bytes seem an URL. This function is equivalent to [A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\x00-\x20]* .
func FirstNonSpacePosition(bs []byte) int
FirstNonSpacePosition returns a position line that is a first nonspace character.
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(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(bs []byte, currentPos int) (width, pos int)
IndentWidth calculate an indent width for the given line.
func IsAlphaNumeric(c byte) bool
IsAlphaNumeric returns true if the given character is a alphabet or a numeric, otherwise false.
func IsBlank(bs []byte) bool
IsBlank returns true if the given string is all space characters.
func IsEastAsianWideRune(r rune) bool
IsEastAsianWideRune returns trhe if the given rune is an east asian wide character, otherwise false.
func IsEscapedPunctuation(source []byte, i int) bool
IsEscapedPunctuation returns true if character at a given index i is an escaped punctuation, otherwise false.
func IsHexDecimal(c byte) bool
IsHexDecimal returns true if the given character is a hexdecimal, otherwise false.
func IsNumeric(c byte) bool
IsNumeric returns true if the given character is a numeric, otherwise false.
func IsPunct(c byte) bool
IsPunct returns true if the given character is a punctuation, otherwise false.
func IsPunctRune(r rune) bool
IsPunctRune returns true if the given rune is a punctuation, otherwise false.
func IsSpace(c byte) bool
IsSpace returns true if the given character is a space, otherwise false.
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(r rune) bool
IsSpaceRune returns true if the given rune is a space, otherwise false.
func ReadWhile(source []byte, index [2]int, pred func(byte) bool) (int, bool)
ReadWhile read the given source while pred is true.
func ReplaceSpaces(source []byte, repl byte) []byte
ReplaceSpaces replaces sequence of spaces with the given repl.
func ResolveEntityNames(source []byte) []byte
ResolveEntityNames resolve entity references like 'ö" .
func ResolveNumericReferences(source []byte) []byte
ResolveNumericReferences resolve numeric references like 'Ӓ" .
func StringToReadOnlyBytes(s string) (bs []byte)
StringToReadOnlyBytes returns bytes converted from given string.
func TabWidth(currentPos int) int
TabWidth calculates actual width of a tab at the given position.
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(source []byte, pos int) rune
ToRune decode given bytes start at pos and returns a rune.
func ToValidRune(v rune) rune
ToValidRune returns 0xFFFD if the given rune is invalid, otherwise v.
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(source, s []byte) int
TrimLeftLength returns a length of leading specified characters.
func TrimLeftSpace(source []byte) []byte
TrimLeftSpace returns a subslice of the given string by slicing off all leading space characters.
func TrimLeftSpaceLength(source []byte) int
TrimLeftSpaceLength returns a length of leading space characters.
func TrimRight(source, b []byte) []byte
TrimRight trims characters in the given s from tail of the source.
func TrimRightLength(source, s []byte) int
TrimRightLength returns a length of trailing specified characters.
func TrimRightSpace(source []byte) []byte
TrimRightSpace returns a subslice of the given string by slicing off all trailing space characters.
func TrimRightSpaceLength(source []byte) int
TrimRightSpaceLength returns a length of trailing space characters.
func URLEscape(v []byte, resolveReference bool) []byte
URLEscape escape the given URL. If resolveReference is set true:
URL encoded values (%xx) are kept as is.
func UTF8Len(b byte) int8
UTF8Len returns a byte length of the utf-8 character.
func UnescapePunctuations(source []byte) []byte
UnescapePunctuations unescapes blackslash escaped punctuations.
func VisualizeSpaces(bs []byte) []byte
VisualizeSpaces visualize invisible space characters.
A BufWriter is a subset of the bufio.Writer .
type BufWriter interface { io.Writer Available() int Buffered() int Flush() error WriteByte(c byte) error WriteRune(r rune) (size int, err error) WriteString(s string) (int, error) }
BytesFilter is a efficient data structure for checking whether bytes exist or not. BytesFilter is thread-safe.
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 }
func NewBytesFilter(elements ...[]byte) BytesFilter
NewBytesFilter returns a new BytesFilter.
A CopyOnWriteBuffer is a byte buffer that copies buffer when it need to be changed.
type CopyOnWriteBuffer struct {
// contains filtered or unexported fields
}
func NewCopyOnWriteBuffer(buffer []byte) CopyOnWriteBuffer
NewCopyOnWriteBuffer returns a new CopyOnWriteBuffer.
func (b *CopyOnWriteBuffer) Append(value []byte)
Append appends given bytes to the buffer. Append copy buffer at the first time.
func (b *CopyOnWriteBuffer) AppendByte(c byte)
AppendByte appends given bytes to the buffer. AppendByte copy buffer at the first time.
func (b *CopyOnWriteBuffer) AppendString(value string)
AppendString appends given string to the buffer. AppendString copy buffer at the first time.
func (b *CopyOnWriteBuffer) Bytes() []byte
Bytes returns bytes of this buffer.
func (b *CopyOnWriteBuffer) IsCopied() bool
IsCopied returns true if buffer has been copied, otherwise false.
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 (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 (b *CopyOnWriteBuffer) WriteString(value string)
WriteString writes given string to the buffer. WriteString allocate new buffer and clears it at the first time.
An HTML5Entity struct represents HTML5 entitites.
type HTML5Entity struct { Name string CodePoints []int Characters []byte }
func LookUpHTML5EntityByName(name string) (*HTML5Entity, bool)
LookUpHTML5EntityByName returns (an HTML5Entity, true) if an entity named given name is found, otherwise (nil, false).
PrioritizedSlice is a slice of the PrioritizedValues.
type PrioritizedSlice []PrioritizedValue
func (s PrioritizedSlice) Remove(v interface{}) PrioritizedSlice
Remove removes the given value from this slice.
func (s PrioritizedSlice) Sort()
Sort sorts the PrioritizedSlice in ascending order.
A PrioritizedValue struct holds pair of an arbitrary value and a priority.
type PrioritizedValue struct { // Value is an arbitrary value that you want to prioritize. Value interface{} // Priority is a priority of the value. Priority int }
func Prioritized(v interface{}, priority int) PrioritizedValue
Prioritized returns a new PrioritizedValue.