diff options
-rw-r--r-- | Regex.dcl | 18 | ||||
-rw-r--r-- | Regex.icl | 13 | ||||
-rw-r--r-- | cleanregex.c | 4 | ||||
-rw-r--r-- | cleanregex.h | 2 | ||||
-rw-r--r-- | test.icl | 4 |
5 files changed, 30 insertions, 11 deletions
@@ -2,6 +2,7 @@ definition module Regex from Data.Maybe import ::Maybe from StdOverloaded import class toString, class fromString, class zero +from StdInt import << :: Regex @@ -22,4 +23,19 @@ instance fromString (Maybe Regex) freeRegex :: !Regex -> String // Nothing on error; otherwise True iff match -match :: !Regex !String -> Maybe Bool +match :: !Regex !Flags !String -> Maybe Bool + +/////////////////////////////////////////////////////////////////////////////// +/// regex.h /// +/////////////////////////////////////////////////////////////////////////////// + +/* POSIX `cflags' bits (i.e., information for regcomp = toRegex). */ +REG_EXTENDED :== 1 +REG_ICASE :== REG_EXTENDED << 1 +REG_NEWLINE :== REG_ICASE << 1 +REG_NOSUB :== REG_NEWLINE << 1 + +/* POSIX `eflags' bits (i.e., information for regexec = match). */ +REG_NOTBOL :== 1 +REG_NOTEOL :== (REG_NOTBOL << 1) +REG_STARTEND :== (REG_NOTEOL << 2) @@ -36,10 +36,13 @@ where ccall cleanrgx_free "p:V:S" } -match :: !Regex !String -> Maybe Bool -match {ptr} s = case match` ptr s of 0 = Just False; 1 = Just True; _ = Nothing +match :: !Regex !Flags !String -> Maybe Bool +match {ptr} flags s = case match` ptr flags s of + 0 = Just False + 1 = Just True + _ = Nothing where - match` :: !Int !String -> Int - match` ptr s = code { - ccall cleanrgx_exec "pS:I" + match` :: !Int !Int !String -> Int + match` ptr flags s = code { + ccall cleanrgx_exec "pIS:I" } diff --git a/cleanregex.c b/cleanregex.c index 20f3154..a886d79 100644 --- a/cleanregex.c +++ b/cleanregex.c @@ -22,9 +22,9 @@ void cleanrgx_compile( free(s); } -int64_t cleanrgx_exec(int64_t* rgx, CleanString* cs) { +int64_t cleanrgx_exec(int64_t* rgx, int64_t flags, CleanString* cs) { char* s = (char*) clstocs(cs); - int64_t result = regexec((regex_t*) rgx, s, 0, NULL, 0); + int64_t result = regexec((regex_t*) rgx, s, 0, NULL, flags); free(s); if (!result) { return 1; diff --git a/cleanregex.h b/cleanregex.h index 397eab8..09132ef 100644 --- a/cleanregex.h +++ b/cleanregex.h @@ -7,6 +7,6 @@ void cleanrgx_compile( CleanString*, int64_t flags, int64_t* re_code, int64_t* re_regex); -int64_t cleanrgx_exec(int64_t* rgx, CleanString* cs); +int64_t cleanrgx_exec(int64_t* rgx, int64_t flags, CleanString* cs); void cleanrgx_free(regex_t* rgx); @@ -4,7 +4,7 @@ import StdEnv import Regex import Data.Maybe -Start = map (match rgx) ["hello", "abc"] +Start = map (fromJust o (match rgx zero)) ["hello", "abc", "aXz"] where - (Just rgx) = toRegex 0 "^a[[:alnum:]]" + (Just rgx) = toRegex REG_EXTENDED "^a[a-z]*$" |