diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2014-01-07 15:02:45 +0200 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2014-01-07 15:02:45 +0200 |
| commit | 83746583b5dbcf4c470cad3ac177a0c24d0f23a8 (patch) | |
| tree | b336132cab5fd7fadcef482d97620186b77ae90c | |
| parent | 6a7e7f8bc9182675098b587ff22b629654bd473d (diff) | |
| download | tiny-rex-83746583b5dbcf4c470cad3ac177a0c24d0f23a8.tar.gz tiny-rex-83746583b5dbcf4c470cad3ac177a0c24d0f23a8.zip | |
support case insensitive matching
| -rw-r--r-- | trex.c | 29 | ||||
| -rw-r--r-- | trex.h | 2 |
2 files changed, 28 insertions, 3 deletions
@@ -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; } @@ -48,6 +48,8 @@ #define TRex_True 1 #define TRex_False 0 +#define TREX_CASE 1 + typedef unsigned int TRexBool; typedef struct TRex TRex; |
