Changeset 24453 in webkit for trunk/JavaScriptCore/kjs/regexp.cpp
- Timestamp:
- Jul 19, 2007, 2:10:40 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/regexp.cpp
r18517 r24453 51 51 options, &errorMessage, &errorOffset, NULL); 52 52 if (!m_regex) { 53 // Try again, this time handle any \u we might find. 54 UString uPattern = sanitizePattern(p); 55 m_regex = pcre_compile(reinterpret_cast<const uint16_t*>(uPattern.data()), uPattern.size(), 56 options, &errorMessage, &errorOffset, NULL); 57 if (!m_regex) { 58 m_constructionError = strdup(errorMessage); 59 return; 60 } 53 m_constructionError = strdup(errorMessage); 54 return; 61 55 } 62 56 … … 190 184 } 191 185 192 UString RegExp::sanitizePattern(const UString& p)193 {194 UString newPattern;195 196 int startPos = 0;197 int pos = p.find("\\u", 0) + 2; // Skip the \u198 199 while (pos != 1) { // p.find failing is -1 + 2 = 1200 if (pos + 3 < p.size()) {201 if (isHexDigit(p[pos]) && isHexDigit(p[pos + 1]) &&202 isHexDigit(p[pos + 2]) && isHexDigit(p[pos + 3])) {203 newPattern.append(p.substr(startPos, pos - startPos - 2));204 UChar escapedUnicode(convertUnicode(p[pos], p[pos + 1],205 p[pos + 2], p[pos + 3]));206 // \u encoded characters should be treated as if they were escaped,207 // so add an escape for certain characters that need it.208 switch (escapedUnicode.unicode()) {209 case '|':210 case '+':211 case '*':212 case '(':213 case ')':214 case '[':215 case ']':216 case '{':217 case '}':218 case '?':219 case '\\':220 newPattern.append('\\');221 }222 newPattern.append(escapedUnicode);223 224 startPos = pos + 4;225 }226 }227 pos = p.find("\\u", pos) + 2;228 }229 newPattern.append(p.substr(startPos, p.size() - startPos));230 231 return newPattern;232 }233 234 186 bool RegExp::isHexDigit(UChar uc) 235 187 {
Note:
See TracChangeset
for help on using the changeset viewer.