Struct lua_patterns::LuaPatternBuilder
[−]
[src]
pub struct LuaPatternBuilder { /* fields omitted */ }
Build a byte Lua pattern, optionally escaping 'magic' characters
Methods
impl LuaPatternBuilder
[src]
fn new() -> LuaPatternBuilder
Create a new Lua pattern builder
fn text(&mut self, s: &str) -> &mut Self
Add unescaped characters from a string
let patt = lua_patterns::LuaPatternBuilder::new() .text("(boo)") .build(); assert_eq!(std::str::from_utf8(&patt).unwrap(), "(boo)");
fn text_lines(&mut self, lines: &str) -> &mut Self
Add unescaped characters from lines
This looks for first non-whitespace run in each line, useful for spreading patterns out and commmenting them. Works with patterns that use '%s' religiously!
let patt = lua_patterns::LuaPatternBuilder::new() .text_lines(" hello-dolly you-are-fine # comment cool ") .build(); assert_eq!(std::str::from_utf8(&patt).unwrap(), "hello-dollyyou-are-finecool");
fn bytes(&mut self, b: &[u8]) -> &mut Self
Add escaped bytes from a slice
let patt = lua_patterns::LuaPatternBuilder::new() .text("^") .bytes(b"^") // magic character! .build(); assert_eq!(std::str::from_utf8(&patt).unwrap(), "^%^");
fn bytes_as_hex(&mut self, bs: &str) -> &mut Self
Add escaped bytes from hex string
This consists of adjacent pairs of hex digits.
let patt = lua_patterns::LuaPatternBuilder::new() .text("^") .bytes_as_hex("5E") // which is ASCII '^' .build(); assert_eq!(std::str::from_utf8(&patt).unwrap(), "^%^");
fn build(&mut self) -> Vec<u8>
Create the pattern
fn hex_to_bytes(s: &str) -> Vec<u8>
Utility to create a vector of bytes from a hex string
let bb = lua_patterns::LuaPatternBuilder::hex_to_bytes("AEFE00FE"); assert_eq!(bb, &[0xAE,0xFE,0x00,0xFE]);
fn bytes_to_hex(s: &[u8]) -> String
Utility to create a hex string from a slice of bytes
let hex = lua_patterns::LuaPatternBuilder::bytes_to_hex(&[0xAE,0xFE,0x00,0xFE]); assert_eq!(hex,"AEFE00FE");