OLD | NEW |
1 /* | 1 /* |
2 ** 2012-11-13 | 2 ** 2012-11-13 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 unsigned char zInit[12]; /* Initial text to match */ | 129 unsigned char zInit[12]; /* Initial text to match */ |
130 int nInit; /* Number of characters in zInit */ | 130 int nInit; /* Number of characters in zInit */ |
131 unsigned nState; /* Number of entries in aOp[] and aArg[] */ | 131 unsigned nState; /* Number of entries in aOp[] and aArg[] */ |
132 unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */ | 132 unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */ |
133 }; | 133 }; |
134 | 134 |
135 /* Add a state to the given state set if it is not already there */ | 135 /* Add a state to the given state set if it is not already there */ |
136 static void re_add_state(ReStateSet *pSet, int newState){ | 136 static void re_add_state(ReStateSet *pSet, int newState){ |
137 unsigned i; | 137 unsigned i; |
138 for(i=0; i<pSet->nState; i++) if( pSet->aState[i]==newState ) return; | 138 for(i=0; i<pSet->nState; i++) if( pSet->aState[i]==newState ) return; |
139 pSet->aState[pSet->nState++] = newState; | 139 pSet->aState[pSet->nState++] = (ReStateNumber)newState; |
140 } | 140 } |
141 | 141 |
142 /* Extract the next unicode character from *pzIn and return it. Advance | 142 /* Extract the next unicode character from *pzIn and return it. Advance |
143 ** *pzIn to the first byte past the end of the character returned. To | 143 ** *pzIn to the first byte past the end of the character returned. To |
144 ** be clear: this routine converts utf8 to unicode. This routine is | 144 ** be clear: this routine converts utf8 to unicode. This routine is |
145 ** optimized for the common case where the next character is a single byte. | 145 ** optimized for the common case where the next character is a single byte. |
146 */ | 146 */ |
147 static unsigned re_next_char(ReInput *p){ | 147 static unsigned re_next_char(ReInput *p){ |
148 unsigned c; | 148 unsigned c; |
149 if( p->i>=p->mx ) return 0; | 149 if( p->i>=p->mx ) return 0; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 ** insertion point is just prior to existing opcode iBefore. | 351 ** insertion point is just prior to existing opcode iBefore. |
352 */ | 352 */ |
353 static int re_insert(ReCompiled *p, int iBefore, int op, int arg){ | 353 static int re_insert(ReCompiled *p, int iBefore, int op, int arg){ |
354 int i; | 354 int i; |
355 if( p->nAlloc<=p->nState && re_resize(p, p->nAlloc*2) ) return 0; | 355 if( p->nAlloc<=p->nState && re_resize(p, p->nAlloc*2) ) return 0; |
356 for(i=p->nState; i>iBefore; i--){ | 356 for(i=p->nState; i>iBefore; i--){ |
357 p->aOp[i] = p->aOp[i-1]; | 357 p->aOp[i] = p->aOp[i-1]; |
358 p->aArg[i] = p->aArg[i-1]; | 358 p->aArg[i] = p->aArg[i-1]; |
359 } | 359 } |
360 p->nState++; | 360 p->nState++; |
361 p->aOp[iBefore] = op; | 361 p->aOp[iBefore] = (char)op; |
362 p->aArg[iBefore] = arg; | 362 p->aArg[iBefore] = arg; |
363 return iBefore; | 363 return iBefore; |
364 } | 364 } |
365 | 365 |
366 /* Append a new opcode and argument to the end of the RE under construction. | 366 /* Append a new opcode and argument to the end of the RE under construction. |
367 */ | 367 */ |
368 static int re_append(ReCompiled *p, int op, int arg){ | 368 static int re_append(ReCompiled *p, int op, int arg){ |
369 return re_insert(p, p->nState, op, arg); | 369 return re_insert(p, p->nState, op, arg); |
370 } | 370 } |
371 | 371 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 ** one or more matching characters, enter those matching characters into | 670 ** one or more matching characters, enter those matching characters into |
671 ** zInit[]. The re_match() routine can then search ahead in the input | 671 ** zInit[]. The re_match() routine can then search ahead in the input |
672 ** string looking for the initial match without having to run the whole | 672 ** string looking for the initial match without having to run the whole |
673 ** regex engine over the string. Do not worry able trying to match | 673 ** regex engine over the string. Do not worry able trying to match |
674 ** unicode characters beyond plane 0 - those are very rare and this is | 674 ** unicode characters beyond plane 0 - those are very rare and this is |
675 ** just an optimization. */ | 675 ** just an optimization. */ |
676 if( pRe->aOp[0]==RE_OP_ANYSTAR ){ | 676 if( pRe->aOp[0]==RE_OP_ANYSTAR ){ |
677 for(j=0, i=1; j<sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){ | 677 for(j=0, i=1; j<sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){ |
678 unsigned x = pRe->aArg[i]; | 678 unsigned x = pRe->aArg[i]; |
679 if( x<=127 ){ | 679 if( x<=127 ){ |
680 pRe->zInit[j++] = x; | 680 pRe->zInit[j++] = (unsigned char)x; |
681 }else if( x<=0xfff ){ | 681 }else if( x<=0xfff ){ |
682 pRe->zInit[j++] = 0xc0 | (x>>6); | 682 pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6)); |
683 pRe->zInit[j++] = 0x80 | (x&0x3f); | 683 pRe->zInit[j++] = 0x80 | (x&0x3f); |
684 }else if( x<=0xffff ){ | 684 }else if( x<=0xffff ){ |
685 pRe->zInit[j++] = 0xd0 | (x>>12); | 685 pRe->zInit[j++] = (unsigned char)(0xd0 | (x>>12)); |
686 pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f); | 686 pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f); |
687 pRe->zInit[j++] = 0x80 | (x&0x3f); | 687 pRe->zInit[j++] = 0x80 | (x&0x3f); |
688 }else{ | 688 }else{ |
689 break; | 689 break; |
690 } | 690 } |
691 } | 691 } |
692 if( j>0 && pRe->zInit[j-1]==0 ) j--; | 692 if( j>0 && pRe->zInit[j-1]==0 ) j--; |
693 pRe->nInit = j; | 693 pRe->nInit = j; |
694 } | 694 } |
695 return pRe->zErr; | 695 return pRe->zErr; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 sqlite3 *db, | 751 sqlite3 *db, |
752 char **pzErrMsg, | 752 char **pzErrMsg, |
753 const sqlite3_api_routines *pApi | 753 const sqlite3_api_routines *pApi |
754 ){ | 754 ){ |
755 int rc = SQLITE_OK; | 755 int rc = SQLITE_OK; |
756 SQLITE_EXTENSION_INIT2(pApi); | 756 SQLITE_EXTENSION_INIT2(pApi); |
757 rc = sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, 0, | 757 rc = sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, 0, |
758 re_sql_func, 0, 0); | 758 re_sql_func, 0, 0); |
759 return rc; | 759 return rc; |
760 } | 760 } |
OLD | NEW |