regex: Convert statics to constants
This require a bit of finesse to work around the changes with libunicode, but nothing too major!
This commit is contained in:
@@ -162,12 +162,12 @@ impl BuildAst {
|
|||||||
/// expression.
|
/// expression.
|
||||||
pub type Flags = u8;
|
pub type Flags = u8;
|
||||||
|
|
||||||
pub static FLAG_EMPTY: u8 = 0;
|
pub const FLAG_EMPTY: u8 = 0;
|
||||||
pub static FLAG_NOCASE: u8 = 1 << 0; // i
|
pub const FLAG_NOCASE: u8 = 1 << 0; // i
|
||||||
pub static FLAG_MULTI: u8 = 1 << 1; // m
|
pub const FLAG_MULTI: u8 = 1 << 1; // m
|
||||||
pub static FLAG_DOTNL: u8 = 1 << 2; // s
|
pub const FLAG_DOTNL: u8 = 1 << 2; // s
|
||||||
pub static FLAG_SWAP_GREED: u8 = 1 << 3; // U
|
pub const FLAG_SWAP_GREED: u8 = 1 << 3; // U
|
||||||
pub static FLAG_NEGATED: u8 = 1 << 4; // char class or not word boundary
|
pub const FLAG_NEGATED: u8 = 1 << 4; // char class or not word boundary
|
||||||
|
|
||||||
struct Parser<'a> {
|
struct Parser<'a> {
|
||||||
// The input, parsed only as a sequence of UTF8 code points.
|
// The input, parsed only as a sequence of UTF8 code points.
|
||||||
@@ -1025,7 +1025,7 @@ fn find_class(classes: NamedClasses, name: &str) -> Option<Vec<(char, char)>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Class = &'static [(char, char)];
|
type Class = &'static [(char, char)];
|
||||||
type NamedClasses = &'static [(&'static str, Class)];
|
type NamedClasses = &'static [(&'static str, &'static Class)];
|
||||||
|
|
||||||
static ASCII_CLASSES: NamedClasses = &[
|
static ASCII_CLASSES: NamedClasses = &[
|
||||||
// Classes must be in alphabetical order so that bsearch works.
|
// Classes must be in alphabetical order so that bsearch works.
|
||||||
@@ -1044,19 +1044,34 @@ static ASCII_CLASSES: NamedClasses = &[
|
|||||||
// [:word:] word characters (== [0-9A-Za-z_])
|
// [:word:] word characters (== [0-9A-Za-z_])
|
||||||
// [:xdigit:] hex digit (== [0-9A-Fa-f])
|
// [:xdigit:] hex digit (== [0-9A-Fa-f])
|
||||||
// Taken from: http://golang.org/pkg/regex/syntax/
|
// Taken from: http://golang.org/pkg/regex/syntax/
|
||||||
("alnum", &[('0', '9'), ('A', 'Z'), ('a', 'z')]),
|
("alnum", &ALNUM),
|
||||||
("alpha", &[('A', 'Z'), ('a', 'z')]),
|
("alpha", &ALPHA),
|
||||||
("ascii", &[('\x00', '\x7F')]),
|
("ascii", &ASCII),
|
||||||
("blank", &[(' ', ' '), ('\t', '\t')]),
|
("blank", &BLANK),
|
||||||
("cntrl", &[('\x00', '\x1F'), ('\x7F', '\x7F')]),
|
("cntrl", &CNTRL),
|
||||||
("digit", &[('0', '9')]),
|
("digit", &DIGIT),
|
||||||
("graph", &[('!', '~')]),
|
("graph", &GRAPH),
|
||||||
("lower", &[('a', 'z')]),
|
("lower", &LOWER),
|
||||||
("print", &[(' ', '~')]),
|
("print", &PRINT),
|
||||||
("punct", &[('!', '/'), (':', '@'), ('[', '`'), ('{', '~')]),
|
("punct", &PUNCT),
|
||||||
("space", &[('\t', '\t'), ('\n', '\n'), ('\x0B', '\x0B'), ('\x0C', '\x0C'),
|
("space", &SPACE),
|
||||||
('\r', '\r'), (' ', ' ')]),
|
("upper", &UPPER),
|
||||||
("upper", &[('A', 'Z')]),
|
("word", &WORD),
|
||||||
("word", &[('0', '9'), ('A', 'Z'), ('a', 'z'), ('_', '_')]),
|
("xdigit", &XDIGIT),
|
||||||
("xdigit", &[('0', '9'), ('A', 'F'), ('a', 'f')]),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
static ALNUM: Class = &[('0', '9'), ('A', 'Z'), ('a', 'z')];
|
||||||
|
static ALPHA: Class = &[('A', 'Z'), ('a', 'z')];
|
||||||
|
static ASCII: Class = &[('\x00', '\x7F')];
|
||||||
|
static BLANK: Class = &[(' ', ' '), ('\t', '\t')];
|
||||||
|
static CNTRL: Class = &[('\x00', '\x1F'), ('\x7F', '\x7F')];
|
||||||
|
static DIGIT: Class = &[('0', '9')];
|
||||||
|
static GRAPH: Class = &[('!', '~')];
|
||||||
|
static LOWER: Class = &[('a', 'z')];
|
||||||
|
static PRINT: Class = &[(' ', '~')];
|
||||||
|
static PUNCT: Class = &[('!', '/'), (':', '@'), ('[', '`'), ('{', '~')];
|
||||||
|
static SPACE: Class = &[('\t', '\t'), ('\n', '\n'), ('\x0B', '\x0B'),
|
||||||
|
('\x0C', '\x0C'), ('\r', '\r'), (' ', ' ')];
|
||||||
|
static UPPER: Class = &[('A', 'Z')];
|
||||||
|
static WORD: Class = &[('0', '9'), ('A', 'Z'), ('a', 'z'), ('_', '_')];
|
||||||
|
static XDIGIT: Class = &[('0', '9'), ('A', 'F'), ('a', 'f')];
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ pub struct ExNative {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub original: &'static str,
|
pub original: &'static str,
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub names: &'static [Option<&'static str>],
|
pub names: &'static &'static [Option<&'static str>],
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub prog: fn(MatchKind, &str, uint, uint) -> Vec<Option<uint>>
|
pub prog: fn(MatchKind, &str, uint, uint) -> Vec<Option<uint>>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
|
|||||||
|
|
||||||
::regex::native::Native(::regex::native::ExNative {
|
::regex::native::Native(::regex::native::ExNative {
|
||||||
original: $regex,
|
original: $regex,
|
||||||
names: CAP_NAMES,
|
names: &CAP_NAMES,
|
||||||
prog: exec,
|
prog: exec,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user