errors starting to bubble up
This commit is contained in:
parent
816fd0db2c
commit
44ee64a821
|
@ -6,7 +6,6 @@ links = "foo"
|
|||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
libc="0.2.0"
|
||||
|
||||
[build-dependencies]
|
||||
gcc="0.3"
|
||||
|
|
|
@ -3,6 +3,12 @@ extern crate lua_patterns as lp;
|
|||
|
||||
|
||||
fn main() {
|
||||
|
||||
let mut m = lp::LuaPattern::new("hello%");
|
||||
m.matches("hello");
|
||||
println!("ok");
|
||||
|
||||
///*
|
||||
let mut m = lp::LuaPattern::new("(%a+)");
|
||||
let mut iter = m.gmatch("one two three");
|
||||
assert_eq!(iter.next(), Some("one"));
|
||||
|
@ -31,6 +37,9 @@ fn main() {
|
|||
|cc| cc.get(1).to_uppercase()
|
||||
);
|
||||
assert_eq!(res,"hello DOLLY you're so FINE");
|
||||
//*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
28
src/lib.rs
28
src/lib.rs
|
@ -1,7 +1,7 @@
|
|||
extern crate libc;
|
||||
use libc::{size_t,c_int};
|
||||
use std::ptr;
|
||||
use std::ops;
|
||||
use std::os::raw::{c_int,c_char,c_uint};
|
||||
use std::ffi::CStr;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(PartialEq,Eq,Debug)]
|
||||
|
@ -12,13 +12,13 @@ struct LuaMatch {
|
|||
|
||||
static LUA_MAXCAPTURES: usize = 32;
|
||||
|
||||
// int str_match (const char *s, size_t ls, const char *p, size_t lp, char **err_msg, LuaMatch *mm)
|
||||
#[link(name = "lua-str", kind="static")]
|
||||
extern {
|
||||
fn str_match (s: *const u8, ls: size_t, p: *const u8, lp: size_t,
|
||||
//err_msg: *mut *const u8,
|
||||
err_msg: *const u8,
|
||||
mm: *mut LuaMatch) -> c_int;
|
||||
fn str_match (
|
||||
s: *const u8, ls: c_uint, p: *const u8, lp: c_uint,
|
||||
err_msg: *mut *mut c_char,
|
||||
mm: *mut LuaMatch
|
||||
) -> c_int;
|
||||
}
|
||||
|
||||
pub struct LuaPattern<'a> {
|
||||
|
@ -39,13 +39,21 @@ impl <'a> LuaPattern<'a> {
|
|||
}
|
||||
|
||||
pub fn matches_bytes(&mut self, s: &[u8]) -> bool {
|
||||
let err_msg: *const u8 = ptr::null();
|
||||
let c_ptr: *mut c_char = ptr::null_mut();
|
||||
let pvoid = Box::into_raw(Box::new(c_ptr));
|
||||
let err_msg : *mut *mut c_char = pvoid;
|
||||
|
||||
unsafe {
|
||||
self.n_match = str_match(s.as_ptr(),s.len() as size_t,
|
||||
self.patt.as_ptr(),self.patt.len() as size_t,
|
||||
self.n_match = str_match(s.as_ptr(),s.len() as c_uint,
|
||||
self.patt.as_ptr(),self.patt.len() as c_uint,
|
||||
err_msg, self.matches.as_mut_ptr()) as usize;
|
||||
let ep = *err_msg;
|
||||
if ! ep.is_null() {
|
||||
let slice = CStr::from_ptr(ep);
|
||||
println!("{:?}", slice);
|
||||
}
|
||||
}
|
||||
|
||||
self.n_match > 0
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ static int capture_to_close (MatchState *ms) {
|
|||
|
||||
|
||||
static const char *classend (MatchState *ms, const char *p) {
|
||||
|
||||
switch (*p++) {
|
||||
case L_ESC: {
|
||||
if (p == ms->p_end)
|
||||
|
@ -384,13 +385,19 @@ static int push_captures (MatchState *ms, const char *s, const char *e, LuaMatch
|
|||
}
|
||||
|
||||
|
||||
int str_match (const char *s, size_t ls, const char *p, size_t lp, char **err_msg, LuaMatch *mm) {
|
||||
int str_match (const char *s, unsigned int ls, const char *p, unsigned int lp, char **err_msg, LuaMatch *mm) {
|
||||
const char *s1 = s;
|
||||
MatchState ms;
|
||||
int anchor = (*p == '^');
|
||||
if (anchor) {
|
||||
p++; lp--; /* skip anchor character */
|
||||
}
|
||||
|
||||
if (setjmp(s_jmp_buf) != 0) {
|
||||
if (err_msg != NULL) *err_msg = s_msg_buff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ms.matchdepth = MAXCCALLS;
|
||||
ms.src_init = s;
|
||||
ms.src_end = s + ls;
|
||||
|
@ -405,11 +412,6 @@ int str_match (const char *s, size_t ls, const char *p, size_t lp, char **err_ms
|
|||
}
|
||||
} while (s1++ < ms.src_end && !anchor);
|
||||
|
||||
if (setjmp(s_jmp_buf) != 0) {
|
||||
if (err_msg != NULL) *err_msg = s_msg_buff;
|
||||
} else {
|
||||
if (err_msg != NULL) *err_msg = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue