package parse
import "github.com/tdewolff/minify/v2/parse"
Package parse contains a collection of parsers for various formats in its subpackages.
Index ¶
- Variables
- func Copy(src []byte) (dst []byte)
- func DataURI(dataURI []byte) ([]byte, []byte, error)
- func DecodeURL(b []byte) []byte
- func Dimension(b []byte) (int, int)
- func EncodeURL(b []byte, table [256]bool) []byte
- func EqualFold(s, targetLower []byte) bool
- func IsAllWhitespace(b []byte) bool
- func IsNewline(c byte) bool
- func IsWhitespace(c byte) bool
- func Mediatype(b []byte) ([]byte, map[string]string)
- func Number(b []byte) int
- func Position(r io.Reader, offset int) (line, col int, context string)
- func Printable(r rune) string
- func QuoteEntity(b []byte) (quote byte, n int)
- func ReplaceEntities(b []byte, entitiesMap map[string][]byte, revEntitiesMap map[byte][]byte) []byte
- func ReplaceMultipleWhitespace(b []byte) []byte
- func ReplaceMultipleWhitespaceAndEntities(b []byte, entitiesMap map[string][]byte, revEntitiesMap map[byte][]byte) []byte
- func ToLower(src []byte) []byte
- func TrimWhitespace(b []byte) []byte
- type Error
- func NewError(r io.Reader, offset int, message string, a ...interface{}) *Error
- func NewErrorLexer(l *Input, message string, a ...interface{}) *Error
- func (e *Error) Error() string
- func (e *Error) Position() (int, int, string)
- type Input
- func NewInput(r io.Reader) *Input
- func NewInputBytes(b []byte) *Input
- func NewInputString(s string) *Input
- func (z *Input) Bytes() []byte
- func (z *Input) Err() error
- func (z *Input) Len() int
- func (z *Input) Lexeme() []byte
- func (z *Input) Move(n int)
- func (z *Input) Offset() int
- func (z *Input) Peek(pos int) byte
- func (z *Input) PeekErr(pos int) error
- func (z *Input) PeekRune(pos int) (rune, int)
- func (z *Input) Pos() int
- func (z *Input) Reset()
- func (z *Input) Restore()
- func (z *Input) Rewind(pos int)
- func (z *Input) Shift() []byte
- func (z *Input) Skip()
Variables ¶
var DataURIEncodingTable = [256]bool{ /* 256 elements not displayed */ }
DataURIEncodingTable is a charmap for which characters need escaping in the Data URI encoding scheme Escape only non-printable characters, unicode and %, #, &. IE11 additionally requires encoding of \, [, ], ", <, >, `, {, }, |, ^ which is not required by Chrome, Firefox, Opera, Edge, Safari, Yandex
ErrBadDataURI is returned by DataURI when the byte slice does not start with 'data:' or is too short.
var URLEncodingTable = [256]bool{ /* 256 elements not displayed */ }
URLEncodingTable is a charmap for which characters need escaping in the URL encoding scheme
Functions ¶
func Copy ¶
Copy returns a copy of the given byte slice.
func DataURI ¶
DataURI parses the given data URI and returns the mediatype, data and ok.
func DecodeURL ¶
DecodeURL decodes an URL encoded using the URL encoding scheme
func Dimension ¶
Dimension parses a byte-slice and returns the length of the number and its unit.
func EncodeURL ¶
EncodeURL encodes bytes using the URL encoding scheme
func EqualFold ¶
EqualFold returns true when s matches case-insensitively the targetLower (which must be lowercase).
func IsAllWhitespace ¶
IsAllWhitespace returns true when the entire byte slice consists of space, \n, \r, \t, \f.
func IsNewline ¶
IsNewline returns true for \n, \r.
func IsWhitespace ¶
IsWhitespace returns true for space, \n, \r, \t, \f.
func Mediatype ¶
Mediatype parses a given mediatype and splits the mimetype from the parameters. It works similar to mime.ParseMediaType but is faster.
func Number ¶
Number returns the number of bytes that parse as a number of the regex format (+|-)?([0-9]+(\.[0-9]+)?|\.[0-9]+)((e|E)(+|-)?[0-9]+)?.
func Position ¶
Position returns the line and column number for a certain position in a file. It is useful for recovering the position in a file that caused an error. It only treates \n, \r, and \r\n as newlines, which might be different from some languages also recognizing \f, \u2028, and \u2029 to be newlines.
func Printable ¶
Printable returns a printable string for given rune
func QuoteEntity ¶
QuoteEntity parses the given byte slice and returns the quote that got matched (' or ") and its entity length. TODO: deprecated
func ReplaceEntities ¶
func ReplaceEntities(b []byte, entitiesMap map[string][]byte, revEntitiesMap map[byte][]byte) []byte
ReplaceEntities replaces all occurrences of entites (such as ") to their respective unencoded bytes.
func ReplaceMultipleWhitespace ¶
ReplaceMultipleWhitespace replaces character series of space, \n, \t, \f, \r into a single space or newline (when the serie contained a \n or \r).
func ReplaceMultipleWhitespaceAndEntities ¶
func ReplaceMultipleWhitespaceAndEntities(b []byte, entitiesMap map[string][]byte, revEntitiesMap map[byte][]byte) []byte
ReplaceMultipleWhitespaceAndEntities is a combination of ReplaceMultipleWhitespace and ReplaceEntities. It is faster than executing both sequentially.
func ToLower ¶
ToLower converts all characters in the byte slice from A-Z to a-z.
func TrimWhitespace ¶
TrimWhitespace removes any leading and trailing whitespace characters.
Types ¶
type Error ¶
Error is a parsing error returned by parser. It contains a message and an offset at which the error occurred.
func NewError ¶
NewError creates a new error
func NewErrorLexer ¶
NewErrorLexer creates a new error from an active Lexer.
func (*Error) Error ¶
Error returns the error string, containing the context and line + column number.
func (*Error) Position ¶
Position returns the line, column, and context of the error. Context is the entire line at which the error occurred.
type Input ¶
type Input struct {
// contains filtered or unexported fields
}
Input is a buffered reader that allows peeking forward and shifting, taking an io.Input. It keeps data in-memory until Free, taking a byte length, is called to move beyond the data.
func NewInput ¶
NewInput returns a new Input for a given io.Input and uses ioutil.ReadAll to read it into a byte slice. If the io.Input implements Bytes, that is used instead. It will append a NULL at the end of the buffer.
func NewInputBytes ¶
NewInputBytes returns a new Input for a given byte slice and appends NULL at the end. To avoid reallocation, make sure the capacity has room for one more byte.
func NewInputString ¶
NewInputString returns a new Input for a given string and appends NULL at the end.
func (*Input) Bytes ¶
Bytes returns the underlying buffez.
func (*Input) Err ¶
Err returns the error returned from io.Input or io.EOF when the end has been reached.
func (*Input) Len ¶
Len returns the length of the underlying buffez.
func (*Input) Lexeme ¶
Lexeme returns the bytes of the current selection.
func (*Input) Move ¶
Move advances the position.
func (*Input) Offset ¶
Offset returns the character position in the buffez.
func (*Input) Peek ¶
Peek returns the ith byte relative to the end position. Peek returns 0 when an error has occurred, Err returns the erroz.
func (*Input) PeekErr ¶
PeekErr returns the error at position pos. When pos is zero, this is the same as calling Err().
func (*Input) PeekRune ¶
PeekRune returns the rune and rune length of the ith byte relative to the end position.
func (*Input) Pos ¶
Pos returns a mark to which can be rewinded.
func (*Input) Reset ¶
func (z *Input) Reset()
Reset resets position to the underlying buffez.
func (*Input) Restore ¶
func (z *Input) Restore()
Restore restores the replaced byte past the end of the buffer by NULL.
func (*Input) Rewind ¶
Rewind rewinds the position to the given position.
func (*Input) Shift ¶
Shift returns the bytes of the current selection and collapses the position to the end of the selection.
func (*Input) Skip ¶
func (z *Input) Skip()
Skip collapses the position to the end of the selection.
Source Files ¶
common.go error.go input.go position.go util.go
Directories ¶
Path | Synopsis |
---|---|
parse/buffer | Package buffer contains buffer and wrapper types for byte slices. |
parse/css | Package css is a CSS3 lexer and parser following the specifications at http://www.w3.org/TR/css-syntax-3/. |
parse/html | Package html is an HTML5 lexer following the specifications at http://www.w3.org/TR/html5/syntax.html. |
parse/js | Package js is an ECMAScript5.1 lexer following the specifications at http://www.ecma-international.org/ecma-262/5.1/. |
parse/json | Package json is a JSON parser following the specifications at http://json.org/. |
parse/strconv | |
parse/xml | Package xml is an XML1.0 lexer following the specifications at http://www.w3.org/TR/xml/. |
- Version
- v2.9.17
- Published
- May 14, 2021
- Platform
- darwin/amd64
- Imports
- 9 packages
- Last checked
- 23 minutes ago –
Tools for package owners.