diff c/regexParser/regexParser.cc @ 150:a4940a8dd263 pairPro

implement insertCharClass
author masa
date Wed, 16 Dec 2015 16:42:18 +0900
parents f1880f25fabf
children 6ba059ce9109
line wrap: on
line diff
--- a/c/regexParser/regexParser.cc	Wed Dec 16 15:37:14 2015 +0900
+++ b/c/regexParser/regexParser.cc	Wed Dec 16 16:42:18 2015 +0900
@@ -85,7 +85,7 @@
   13.                          b--e
 
  */
-CharClassPtr insertCharClass(CharClassPtr cc, unsigned char begin, unsigned char end) {
+CharClassPtr insertCharClass(CharClassPtr cc, unsigned long begin, unsigned long end) {
 
     if (end < cc->cond.range.begin ) { // 1
         CharClassPtr cc1 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->left,cc->right);
@@ -98,12 +98,13 @@
             return cc1;
         }
     } else if (end == cc->cond.range.begin ) { // 2
-            CharClassPtr cc2 = createCharClassRange(begin,end,0,0);
         cc->cond.range.begin = begin;
+        return cc;
     } else if (end <= cc->cond.range.end) {  // 3,4,6,7,9,10
         if (begin < cc->cond.range.begin) {  // 3,4
             cc->cond.range.begin = begin;
         }
+        return cc;
     } else if (begin > cc->cond.range.end ) { // 13
         CharClassPtr cc1 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->left,cc->right);
         if (cc->right) {
@@ -114,10 +115,17 @@
             cc1->right = cc2;
             return cc1;
         }
-    } else if (begin == cc->cond.range.end ) { // 12
-        cc->cond.range.end = end;
+    }
+    if (cc->right) {
+        return insertCharClass(cc->right,cc->cond.range.begin,end);
+    }
+    if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { // 12
+        if (end > cc->cond.range.end) cc->cond.range.end = end; // 11
     } else if (begin < cc->cond.range.begin) { // 5
         cc->cond.range.begin = begin;
+        cc->cond.range.end = end; 
+    } else {
+        printf("insertCharClass Error : begin %lu end %lu cc->begin %lu cc->end %lu\n", begin,end,cc->cond.range.begin,cc->cond.range.end);
     }
     return cc;
 }
@@ -150,7 +158,9 @@
         rangeList->next = NULL;
     }
 
-    for (RangeListPtr r = &cc->cond.range; r; r = r->next) {
+    RangeListPtr r = cc->cond.range.next;
+    cc->cond.range.next = 0;
+    for (; r; r = r->next) {
         cc = insertCharClass(cc, r->begin, r->end);
     }