diff --git a/hawk/lib/fnc.c b/hawk/lib/fnc.c index 8529aa51..18180a4f 100644 --- a/hawk/lib/fnc.c +++ b/hawk/lib/fnc.c @@ -1161,7 +1161,7 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count) if (max_count == 0 || sub_count < max_count) { - n = hawk_rtx_matchrex(rtx, rex, &s2, &cur, &mat, HAWK_NULL); + n = hawk_rtx_matchrexwithoocs(rtx, rex, &s2, &cur, &mat, HAWK_NULL); if (n <= -1) goto oops; } else n = 0; diff --git a/hawk/lib/misc-prv.h b/hawk/lib/misc-prv.h index 2d538dca..ae5dc9b8 100644 --- a/hawk/lib/misc-prv.h +++ b/hawk/lib/misc-prv.h @@ -77,12 +77,6 @@ int hawk_rtx_matchval ( ); -int hawk_rtx_matchrex ( - hawk_rtx_t* rtx, hawk_tre_t* code, - const hawk_oocs_t* str, const hawk_oocs_t* substr, - hawk_oocs_t* match, hawk_oocs_t submat[9] -); - int hawk_rtx_matchrexwithucs ( hawk_rtx_t* rtx, hawk_tre_t* code, const hawk_ucs_t* str, const hawk_ucs_t* substr, @@ -95,6 +89,12 @@ int hawk_rtx_matchrexwithbcs ( hawk_bcs_t* match, hawk_bcs_t submat[9] ); +#if defined(HAWK_OOCH_IS_UCH) +# define hawk_rtx_matchrexwithoocs hawk_rtx_matchrexwithucs +#else +# define hawk_rtx_matchrexwithoocs hawk_rtx_matchrexwithbcs +#endif + #if defined(__cplusplus) } #endif diff --git a/hawk/lib/misc.c b/hawk/lib/misc.c index 958005e8..f1628fa0 100644 --- a/hawk/lib/misc.c +++ b/hawk/lib/misc.c @@ -261,7 +261,7 @@ hawk_ooch_t* hawk_rtx_strxntokbyrex ( while (cursub.len > 0) { - n = hawk_rtx_matchrex(rtx, rex, &s, &cursub, &match, HAWK_NULL); + n = hawk_rtx_matchrexwithoocs(rtx, rex, &s, &cursub, &match, HAWK_NULL); if (n <= -1) return HAWK_NULL; if (n == 0) @@ -432,45 +432,6 @@ hawk_ooch_t* hawk_rtx_strxnfld ( return HAWK_NULL; } -static int matchtre (hawk_tre_t* tre, int opt, const hawk_oocs_t* str, hawk_oocs_t* mat, hawk_oocs_t submat[9], hawk_gem_t* errgem) -{ - int n; - /*hawk_tre_match_t match[10] = { { 0, 0 }, };*/ - hawk_tre_match_t match[10]; - - HAWK_MEMSET (match, 0, HAWK_SIZEOF(match)); - n = hawk_tre_execx(tre, str->ptr, str->len, match, HAWK_COUNTOF(match), opt, errgem); - if (n <= -1) - { - if (hawk_gem_geterrnum(errgem) == HAWK_EREXNOMAT) return 0; - return -1; - } - - HAWK_ASSERT (match[0].rm_so != -1); - if (mat) - { - mat->ptr = &str->ptr[match[0].rm_so]; - mat->len = match[0].rm_eo - match[0].rm_so; - } - - if (submat) - { - int i; - - /* you must intialize submat before you pass into this - * function because it can abort filling */ - for (i = 1; i < HAWK_COUNTOF(match); i++) - { - if (match[i].rm_so != -1) - { - submat[i-1].ptr = &str->ptr[match[i].rm_so]; - submat[i-1].len = match[i].rm_eo - match[i].rm_so; - } - } - } - return 1; -} - static int matchtre_ucs (hawk_tre_t* tre, int opt, const hawk_ucs_t* str, hawk_ucs_t* mat, hawk_ucs_t submat[9], hawk_gem_t* errgem) { int n; @@ -478,7 +439,7 @@ static int matchtre_ucs (hawk_tre_t* tre, int opt, const hawk_ucs_t* str, hawk_u hawk_tre_match_t match[10]; HAWK_MEMSET (match, 0, HAWK_SIZEOF(match)); - n = hawk_tre_execbchars(tre, str->ptr, str->len, match, HAWK_COUNTOF(match), opt, errgem); + n = hawk_tre_execuchars(tre, str->ptr, str->len, match, HAWK_COUNTOF(match), opt, errgem); if (n <= -1) { if (hawk_gem_geterrnum(errgem) == HAWK_EREXNOMAT) return 0; @@ -574,8 +535,12 @@ int hawk_rtx_matchval (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_oocs_t* str, hawk_rtx_freevaloocstr (rtx, val, tmp.ptr); if (x <= -1) return -1; } - - x = matchtre( + +#if defined(HAWK_OOCH_IS_UCH) + x = matchtre_ucs( +#else + x = matchtre_bcs( +#endif code, ((str->ptr == substr->ptr)? opt: (opt | HAWK_TRE_NOTBOL)), substr, match, submat, hawk_rtx_getgem(rtx) ); @@ -592,15 +557,6 @@ int hawk_rtx_matchval (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_oocs_t* str, return x; } -int hawk_rtx_matchrex (hawk_rtx_t* rtx, hawk_tre_t* code, const hawk_oocs_t* str, const hawk_oocs_t* substr, hawk_oocs_t* match, hawk_oocs_t submat[9]) -{ - int opt = HAWK_TRE_BACKTRACKING; /* TODO: option... HAWK_TRE_BACKTRACKING or others??? */ - return matchtre( - code, ((str->ptr == substr->ptr)? opt: (opt | HAWK_TRE_NOTBOL)), - substr, match, submat, hawk_rtx_getgem(rtx) - ); -} - int hawk_rtx_matchrexwithucs (hawk_rtx_t* rtx, hawk_tre_t* code, const hawk_ucs_t* str, const hawk_ucs_t* substr, hawk_ucs_t* match, hawk_ucs_t submat[9]) { int opt = HAWK_TRE_BACKTRACKING; /* TODO: option... HAWK_TRE_BACKTRACKING or others??? */ diff --git a/hawk/lib/rio.c b/hawk/lib/rio.c index cc7bbc59..bbdfdf6c 100644 --- a/hawk/lib/rio.c +++ b/hawk/lib/rio.c @@ -247,7 +247,7 @@ static HAWK_INLINE int match_long_rs (hawk_rtx_t* rtx, hawk_ooecs_t* buf, hawk_r HAWK_ASSERT (rtx->gbl.rs[0] != HAWK_NULL); HAWK_ASSERT (rtx->gbl.rs[1] != HAWK_NULL); - ret = hawk_rtx_matchrex(rtx, rtx->gbl.rs[rtx->gbl.ignorecase], HAWK_OOECS_OOCS(buf), HAWK_OOECS_OOCS(buf), &match, HAWK_NULL); + ret = hawk_rtx_matchrexwithoocs(rtx, rtx->gbl.rs[rtx->gbl.ignorecase], HAWK_OOECS_OOCS(buf), HAWK_OOECS_OOCS(buf), &match, HAWK_NULL); if (ret >= 1) { if (p->in.eof)