Crate lua_patterns

source ·
Expand description

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

Structs

Low-overhead convenient access to byte match captures
Low-overhead convenient access to string match captures
Unsafe version of Captures, needed for gmatch_captures
Iterator for all string slices from gmatch
Iterator for all byte slices from gmatch_bytes
Streaming iterator for all captures from gmatch_captures
Represents a Lua string pattern and the results of a match
Build a byte Lua pattern, optionally escaping ‘magic’ characters

Enums

Functions