charset

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package charset classifies a single Unicode code point against the property names this engine recognises for the \p{…} / \P{…} construct. It is the one rune-aware piece of the otherwise byte-oriented engine: the parser uses Valid to reject unknown property names at compile time, and the VM uses Match to test a decoded rune.

Two families of names are supported, matching the slice of Onigmo/Ruby this engine implements:

  • General categories: the one-letter groups L, N, P, S, Z, C and the two-letter letter/number/other subcategories Lu, Ll, Lt, Lm, Lo, Nd, Nl, No, Cf. These map directly onto Go's unicode range tables.
  • Onigmo POSIX-style aliases: Alpha, Alnum, Digit, Space, Upper, Lower and Word. These follow Ruby's definitions (e.g. Space is the Unicode White_Space property, which is broader than the Z general category; Word is letter | mark | decimal-number | connector-punctuation), which do not always coincide with a single general category.

Names are matched case-sensitively, exactly as Onigmo treats them. Negation (\P{…} and \p{^…}) is handled by the caller, not here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FoldEqual

func FoldEqual(a, b rune) bool

FoldEqual reports whether runes a and b are equal under simple (1:1) Unicode case folding — that is, whether they belong to the same simple-case-folding orbit. The orbit is the cycle Go's unicode.SimpleFold walks (e.g. k → K → Kelvin-sign → k, or Σ → ς → σ → Σ), so FoldEqual('k', 0x212A) and FoldEqual('É', 'é') are both true. This is the engine's rune-level /i model; full/special case folding (multi-character expansions such as ß→"ss" and locale-specific rules such as Turkish dotless-i) is deliberately out of scope.

func FoldRangeContains

func FoldRangeContains(r, lo, hi rune) bool

FoldRangeContains reports whether code point r is in the inclusive range [lo,hi] under simple case folding: r matches if r, or any rune in r's simple-case-folding orbit, lies within the range. So FoldRangeContains tests "A" against the range "a".."z" (folding to lowercase) and the Kelvin sign against the same range (its orbit includes ASCII "k"). The class machinery uses this so (?i)[a-z] and (?i)[α-ω] match their opposite-case members.

func Match

func Match(name string, negate bool, r rune) bool

Match reports whether rune r is a member of the named property. negate flips the result (for \P{…} and \p{^…}). It returns false for an unknown name; the parser is expected to have rejected such names via Valid before compilation, so this is only a defensive fallback.

func Valid

func Valid(name string) bool

Valid reports whether name is a property this engine recognises.

Types

This section is empty.

Jump to

Keyboard shortcuts

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