summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2014-01-07 15:02:45 +0200
committerOskari Timperi <oskari.timperi@iki.fi>2014-01-07 15:02:45 +0200
commit83746583b5dbcf4c470cad3ac177a0c24d0f23a8 (patch)
treeb336132cab5fd7fadcef482d97620186b77ae90c
parent6a7e7f8bc9182675098b587ff22b629654bd473d (diff)
downloadtiny-rex-83746583b5dbcf4c470cad3ac177a0c24d0f23a8.tar.gz
tiny-rex-83746583b5dbcf4c470cad3ac177a0c24d0f23a8.zip
support case insensitive matching
-rw-r--r--trex.c29
-rw-r--r--trex.h2
2 files changed, 28 insertions, 3 deletions
diff --git a/trex.c b/trex.c
index d597265..8865f16 100644
--- a/trex.c
+++ b/trex.c
@@ -371,13 +371,29 @@ static TRexBool trex_matchclass(TRex* exp,TRexNode *node,TRexChar c)
do {
switch(node->type) {
case OP_RANGE:
- if(c >= node->left && c <= node->right) return TRex_True;
+ if (exp->_flags & TREX_CASE)
+ {
+ if(c >= toupper(node->left) && c <= toupper(node->right)) return TRex_True;
+ if(c >= tolower(node->left) && c <= tolower(node->right)) return TRex_True;
+ }
+ else
+ {
+ if(c >= node->left && c <= node->right) return TRex_True;
+ }
break;
case OP_CCLASS:
if(trex_matchcclass(node->left,c)) return TRex_True;
break;
default:
- if(c == node->type)return TRex_True;
+ if (exp->_flags & TREX_CASE)
+ {
+ if (c == tolower(node->type) || c == toupper(node->type)) return TRex_True;
+ }
+ else
+ {
+ if(c == node->type)return TRex_True;
+ }
+
}
} while((node->next != -1) && (node = &exp->_nodes[node->next]));
return TRex_False;
@@ -521,7 +537,14 @@ static const TRexChar *trex_matchnode(TRex* exp,TRexNode *node,const TRexChar *s
}
return NULL;
default: /* char */
- if(*str != node->type) return NULL;
+ if (exp->_flags & TREX_CASE)
+ {
+ if(*str != tolower(node->type) && *str != toupper(node->type)) return NULL;
+ }
+ else
+ {
+ if (*str != node->type) return NULL;
+ }
*str++;
return str;
}
diff --git a/trex.h b/trex.h
index 698147d..9348bcb 100644
--- a/trex.h
+++ b/trex.h
@@ -48,6 +48,8 @@
#define TRex_True 1
#define TRex_False 0
+#define TREX_CASE 1
+
typedef unsigned int TRexBool;
typedef struct TRex TRex;