parse – github.com/tdewolff/parse Index | Files | Directories

package parse

import "github.com/tdewolff/parse"

Package parse contains a collection of parsers for various formats in its subpackages.

Index

Variables

var ErrBadDataURI = errors.New("not a data URI")

ErrBadDataURI is returned by DataURI when the byte slice does not start with 'data:' or is too short.

Functions

func Copy

func Copy(src []byte) (dst []byte)

Copy returns a copy of the given byte slice.

func DataURI

func DataURI(dataURI []byte) ([]byte, []byte, error)

DataURI parses the given data URI and returns the mediatype, data and ok.

func Dimension

func Dimension(b []byte) (int, int)

Dimension parses a byte-slice and returns the length of the number and its unit.

func EqualFold

func EqualFold(s, targetLower []byte) bool

EqualFold returns true when s matches case-insensitively the targetLower (which must be lowercase).

func IsAllWhitespace

func IsAllWhitespace(b []byte) bool

IsAllWhitespace returns true when the entire byte slice consists of space, \n, \r, \t, \f.

func IsNewline

func IsNewline(c byte) bool

IsNewline returns true for \n, \r.

func IsWhitespace

func IsWhitespace(c byte) bool

IsWhitespace returns true for space, \n, \r, \t, \f.

func Mediatype

func Mediatype(b []byte) ([]byte, map[string]string)

Mediatype parses a given mediatype and splits the mimetype from the parameters. It works similar to mime.ParseMediaType but is faster.

func Number

func Number(b []byte) int

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

func Position(r io.Reader, offset int) (line, col int, context string, err error)

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 QuoteEntity

func QuoteEntity(b []byte) (quote byte, n int)

QuoteEntity parses the given byte slice and returns the quote that got matched (' or ") and its entity length.

func ReplaceMultipleWhitespace

func ReplaceMultipleWhitespace(b []byte) []byte

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 ToLower

func ToLower(src []byte) []byte

ToLower converts all characters in the byte slice from A-Z to a-z.

func TrimWhitespace

func TrimWhitespace(b []byte) []byte

TrimWhitespace removes any leading and trailing whitespace characters.

Types

type Error

type Error struct {
	Message string
	Line    int
	Col     int
	Context string
}

func NewError

func NewError(msg string, r io.Reader, offset int) *Error

func NewErrorLexer

func NewErrorLexer(msg string, l *buffer.Lexer) *Error

func (*Error) Error

func (e *Error) Error() string

Source Files

common.go error.go position.go util.go

Directories

PathSynopsis
cssPackage css is a CSS3 lexer and parser following the specifications at http://www.w3.org/TR/css-syntax-3/.
htmlPackage html is an HTML5 lexer following the specifications at http://www.w3.org/TR/html5/syntax.html.
jsPackage js is an ECMAScript5.1 lexer following the specifications at http://www.ecma-international.org/ecma-262/5.1/.
jsonPackage json is a JSON parser following the specifications at http://json.org/.
svg
xmlPackage xml is an XML1.0 lexer following the specifications at http://www.w3.org/TR/xml/.
Version
v2.3.0+incompatible
Published
Nov 12, 2017
Platform
windows/amd64
Imports
8 packages
Last checked
now

Tools for package owners.