Crate lua_patterns[−][src]
This is a Rust binding to Lua string patterns, using the original code from Lua 5.2.
Although not regular expressions (they lack alternation) they are a powerful and lightweight way to process text. Please note that they are not UTF-8-aware, and in fact can process arbitrary binary data.
LuaPattern
can be created from a string or a byte slice, and has
methods which are similar to the original Lua API. Please see
the README
for more discussion.
LuaPattern implements the public API.
Examples
extern crate lua_patterns; let mut m = lua_patterns::LuaPattern::new("one"); let text = "hello one two"; assert!(m.matches(text)); let r = m.range(); assert_eq!(r.start, 6); assert_eq!(r.end, 9);
Collecting captures from a match:
extern crate lua_patterns; let text = " hello one"; let mut m = lua_patterns::LuaPattern::new("(%S+) one"); // allocates a vector of captures let v = m.captures(text); assert_eq!(v, &["hello one","hello"]); let mut v = Vec::new(); // writes captures into preallocated vector if m.capture_into(text,&mut v) { assert_eq!(v, &["hello one","hello"]); }
Modules
errors |
Structs
ByteCaptures | Low-overhead convenient access to byte match captures |
Captures | Low-overhead convenient access to string match captures |
CapturesUnsafe | Unsafe version of Captures, needed for gmatch_captures |
GMatch | Iterator for all string slices from |
GMatchBytes | Iterator for all byte slices from |
GMatchCaptures | Streaming iterator for all captures from |
LuaPattern | Represents a Lua string pattern and the results of a match |
LuaPatternBuilder | Build a byte Lua pattern, optionally escaping ‘magic’ characters |
Enums
ByteSubst |