lua-patterns 0.4.0

Binding to Lua String Patterns
Documentation
  • Coverage
  • 79.66%
    47 out of 59 items documented24 out of 49 items with examples
  • Size
  • Source code size: 66.13 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 7.6 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • stevedonovan/lua-patterns
    28 5 3
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • stevedonovan

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"]);
}