From 83746583b5dbcf4c470cad3ac177a0c24d0f23a8 Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Tue, 7 Jan 2014 15:02:45 +0200 Subject: support case insensitive matching --- trex.c | 29 ++++++++++++++++++++++++++--- trex.h | 2 ++ 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; -- cgit v1.2.3