Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 ************************************************************************** | 2 ************************************************************************** |
| 3 * Copyright (C) 2002-2010 International Business Machines Corporation * | 3 * Copyright (C) 2002-2010 International Business Machines Corporation * |
| 4 * and others. All rights reserved. * | 4 * and others. All rights reserved. * |
| 5 ************************************************************************** | 5 ************************************************************************** |
| 6 */ | 6 */ |
| 7 // | 7 // |
| 8 // file: rematch.cpp | 8 // file: rematch.cpp |
| 9 // | 9 // |
| 10 // Contains the implementation of class RegexMatcher, | 10 // Contains the implementation of class RegexMatcher, |
| (...skipping 5580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5591 opValue = URX_VAL(op); | 5591 opValue = URX_VAL(op); |
| 5592 U_ASSERT(opType == URX_STRING_LEN); | 5592 U_ASSERT(opType == URX_STRING_LEN); |
| 5593 stringLen = opValue; | 5593 stringLen = opValue; |
| 5594 | 5594 |
| 5595 const UChar *patternChars = litText+stringStartIdx; | 5595 const UChar *patternChars = litText+stringStartIdx; |
| 5596 const UChar *patternEnd = patternChars+stringLen; | 5596 const UChar *patternEnd = patternChars+stringLen; |
| 5597 | 5597 |
| 5598 const UChar *foldChars = NULL; | 5598 const UChar *foldChars = NULL; |
| 5599 int32_t foldOffset, foldLength; | 5599 int32_t foldOffset, foldLength; |
| 5600 UChar32 c; | 5600 UChar32 c; |
| 5601 UBool c_is_valid = FALSE; | |
| 5601 | 5602 |
| 5602 #ifdef REGEX_SMART_BACKTRACKING | 5603 #ifdef REGEX_SMART_BACKTRACKING |
| 5603 int32_t originalInputIdx = fp->fInputIdx; | 5604 int32_t originalInputIdx = fp->fInputIdx; |
| 5604 #endif | 5605 #endif |
| 5605 UBool success = TRUE; | 5606 UBool success = TRUE; |
| 5606 | 5607 |
| 5607 foldOffset = foldLength = 0; | 5608 foldOffset = foldLength = 0; |
| 5608 | 5609 |
| 5609 while (patternChars < patternEnd && success) { | 5610 while (patternChars < patternEnd && success) { |
| 5610 if(foldOffset < foldLength) { | 5611 if (fp->fInputIdx >= fActiveLimit) { |
| 5612 // don't read past end of string | |
| 5613 } else if(foldOffset < foldLength) { | |
| 5611 U16_NEXT_UNSAFE(foldChars, foldOffset, c); | 5614 U16_NEXT_UNSAFE(foldChars, foldOffset, c); |
| 5615 c_is_valid = TRUE; | |
| 5612 } else { | 5616 } else { |
|
jungshik at Google
2011/09/14 18:35:29
How about rewritting the above if - elseif - else
Brad Chen
2011/09/14 19:10:06
Done. Note this makes the patch quite a bit longer
| |
| 5617 // test pre-condition of U16_NEXT: i < length | |
| 5618 U_ASSERT(fp->fInputIdx < fActiveLimit); | |
| 5613 U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c); | 5619 U16_NEXT(inputBuf, fp->fInputIdx, fActiveLimit, c); |
| 5620 c_is_valid = TRUE; | |
| 5614 foldLength = ucase_toFullFolding(csp, c, &foldChars, U_FOLD_CASE_DEFAULT); | 5621 foldLength = ucase_toFullFolding(csp, c, &foldChars, U_FOLD_CASE_DEFAULT); |
| 5615 if(foldLength >= 0) { | 5622 if(foldLength >= 0) { |
| 5616 if(foldLength <= UCASE_MAX_STRING_LENGTH) { // !!!: Does not correctly handle chars that fold to 0-length strings | 5623 if(foldLength <= UCASE_MAX_STRING_LENGTH) { // !!!: Does not correctly handle chars that fold to 0-length strings |
| 5617 foldOffset = 0; | 5624 foldOffset = 0; |
| 5618 U16_NEXT_UNSAFE(foldChars, foldOffset, c); | 5625 U16_NEXT_UNSAFE(foldChars, foldOffset, c); |
| 5619 } else { | 5626 } else { |
| 5620 c = foldLength; | 5627 c = foldLength; |
| 5621 foldLength = foldOffset; // to avoid reading chars from the folding buffer | 5628 foldLength = foldOffset; // to avoid reading chars from the folding buffer |
| 5622 } | 5629 } |
| 5623 } | 5630 } |
| 5624 } | 5631 } |
| 5625 | 5632 |
| 5626 if (fp->fInputIdx <= fActiveLimit) { | 5633 if (fp->fInputIdx <= fActiveLimit && c_is_valid) { |
| 5627 if (U_IS_BMP(c)) { | 5634 if (U_IS_BMP(c)) { |
| 5628 success = (*patternChars == c); | 5635 success = (*patternChars == c); |
| 5629 patternChars += 1; | 5636 patternChars += 1; |
| 5630 } else if (patternChars+1 < patternEnd) { | 5637 } else if (patternChars+1 < patternEnd) { |
| 5631 success = (*patternChars == U16_LEAD(c) && *(pat ternChars+1) == U16_TRAIL(c)); | 5638 success = (*patternChars == U16_LEAD(c) && *(pat ternChars+1) == U16_TRAIL(c)); |
| 5632 patternChars += 2; | 5639 patternChars += 2; |
| 5633 } | 5640 } |
| 5634 } else { | 5641 } else { |
| 5635 success = FALSE; | 5642 success = FALSE; |
| 5636 fHitEnd = TRUE; // TODO: See ticket 6074 | 5643 fHitEnd = TRUE; // TODO: See ticket 6074 |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6063 | 6070 |
| 6064 return; | 6071 return; |
| 6065 } | 6072 } |
| 6066 | 6073 |
| 6067 | 6074 |
| 6068 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RegexMatcher) | 6075 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RegexMatcher) |
| 6069 | 6076 |
| 6070 U_NAMESPACE_END | 6077 U_NAMESPACE_END |
| 6071 | 6078 |
| 6072 #endif // !UCONFIG_NO_REGULAR_EXPRESSIONS | 6079 #endif // !UCONFIG_NO_REGULAR_EXPRESSIONS |
| 6073 | |
| OLD | NEW |