xsdregex

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Code generated from UnicodeData-3.0.0.txt for XSD 1.0 regex categories; DO NOT EDIT.

Index

Constants

View Source
const XMLNameCharRange = xmlNameCharRange
View Source
const XMLNameStartCharRange = xmlNameStartCharRange

XMLNameStartCharRange / XMLNameCharRange are the XML Name character ranges (for use inside a [...] class), shared with NCName/NMTOKEN validation.

Variables

This section is empty.

Functions

func DefaultMatchTimeout

func DefaultMatchTimeout() time.Duration

DefaultMatchTimeout returns the bound on how long the regexp2 backtracking engine spends on a single pattern-facet match before giving up. Patterns that use constructs RE2 cannot handle (character-class subtraction, large quantifiers) compile to regexp2, which is vulnerable to catastrophic backtracking on adversarial inputs; this is a defense-in-depth ceiling for those matches. RE2-compiled patterns are linear-time and unaffected. A value of 0 disables the timeout.

func HasBackrefs

func HasBackrefs(pattern string) bool

HasBackrefs reports whether the pattern contains a back-reference.

func HasCharClassSubtraction

func HasCharClassSubtraction(pattern string) bool

HasCharClassSubtraction reports whether the pattern uses [a-z-[...]] subtraction.

func HasLargeQuantifier

func HasLargeQuantifier(pattern string) bool

HasLargeQuantifier reports whether the pattern has a {n,m} bound exceeding RE2's limit.

func NormalizeBackrefs

func NormalizeBackrefs(pattern string) string

NormalizeBackrefs rewrites multi-digit back-references for Go's regexp engine.

func RejectPerlSpecific

func RejectPerlSpecific(pattern string) error

RejectPerlSpecific rejects Perl-only constructs not allowed in XPath regex.

func SetDefaultMatchTimeout added in v0.3.0

func SetDefaultMatchTimeout(d time.Duration)

SetDefaultMatchTimeout sets the default match timeout returned by DefaultMatchTimeout. Setting it to 0 disables the timeout. The change affects only subsequently-compiled patterns. It is safe to call concurrently with regex compilation.

func Translate

func Translate(pattern string, dotAll, ignoreCase bool) (string, error)

Translate converts an XPath/XQuery regex pattern (fn:matches/tokenize/replace) into a Go RE2 pattern. In this flavor '^' and '$' are anchors and the pattern is not implicitly anchored; use Compile for XSD xs:pattern facets, where '^'/'$' are literals and the whole value must match.

func Validate

func Validate(pattern string, allowBackrefs bool) error

Validate rejects patterns Go's regexp accepts but the XPath/XSD regex spec forbids.

Types

type Regexp

type Regexp struct {
	// contains filtered or unexported fields
}

Regexp is a compiled XML Schema pattern-facet regular expression. It matches the whole input value (the pattern is anchored at both ends) against either Go's RE2 engine or, for constructs RE2 lacks, the regexp2 backtracking engine.

func Compile

func Compile(pattern string) (*Regexp, error)

Compile translates and compiles an XML Schema pattern-facet regular expression, anchoring it so it matches the entire value. Patterns that use XML Schema character-class subtraction ([a-z-[aeiou]]) or quantifier bounds beyond RE2's limit are compiled with the regexp2 backtracking engine, which supports those constructs natively; all other patterns use Go's RE2 engine. It returns an error for patterns that are not valid XML Schema regular expressions, so callers can report a schema error and never silently ignore the facet.

func CompileVersion added in v0.4.0

func CompileVersion(pattern string, xsd11 bool) (*Regexp, error)

CompileVersion is Compile with an XSD 1.1 toggle. In XSD 1.1 mode an unrecognized \p{Is...} block name is accepted (matching every character) per XSD 1.1 test bug 13670. Both versions of the XSD pattern-facet path admit the full XML 1.1 / XML 1.0 5th edition NameChar combining range (U+0300–U+036F, including U+0346) for \c/\C: the U+0346 carve-out belongs to the older XPath-2.0 flavor only (xpath3's Translate, xsdPattern=false), and every XSD pattern facet — 1.0 or 1.1 — follows the 5th-edition NameChar definition (test bug 13606). With xsd11=false the rest of the XSD 1.0 behavior is byte-identical to Compile's original.

func (*Regexp) MatchString

func (r *Regexp) MatchString(s string) bool

MatchString reports whether the whole string s is matched by the pattern.

Jump to

Keyboard shortcuts

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