Changeset 27320 in webkit for trunk/JavaScriptCore/kjs/regexp.cpp
- Timestamp:
- Oct 31, 2007, 7:46:41 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/regexp.cpp
r26688 r27320 34 34 : m_flags(flags), m_constructionError(0), m_numSubPatterns(0) 35 35 { 36 #if HAVE(PCREPOSIX)36 #if USE(PCRE16) 37 37 38 38 int options = PCRE_UTF8; 39 // Note: the Global flag is already handled by RegExpProtoFunc::execute.40 // FIXME: That last comment is dubious. Not all RegExps get run through RegExpProtoFunc::execute.41 39 if (flags & IgnoreCase) 42 40 options |= PCRE_CASELESS; … … 44 42 options |= PCRE_MULTILINE; 45 43 46 const char *errorMessage;44 const char* errorMessage; 47 45 int errorOffset; 48 49 m_regex = pcre_compile(reinterpret_cast<const uint16_t*>(p.data()), p.size(), 50 options, &errorMessage, &errorOffset, NULL); 46 m_regex = pcre_compile2(reinterpret_cast<const uint16_t*>(p.data()), p.size(), 47 options, NULL, &errorMessage, &errorOffset, NULL); 51 48 if (!m_regex) { 52 49 m_constructionError = strdup(errorMessage); … … 54 51 } 55 52 56 #ifdef PCRE_INFO_CAPTURECOUNT57 53 // Get number of subpatterns that will be returned. 58 54 pcre_fullinfo(m_regex, NULL, PCRE_INFO_CAPTURECOUNT, &m_numSubPatterns); 59 #endif60 55 61 #else /* HAVE(PCREPOSIX) */56 #else /* USE(PCRE16) */ 62 57 63 58 int regflags = 0; … … 89 84 RegExp::~RegExp() 90 85 { 91 #if HAVE(PCREPOSIX)86 #if USE(PCRE16) 92 87 pcre_free(m_regex); 93 88 #else … … 98 93 } 99 94 100 UString RegExp::match(const UString &s, int i, int *pos, int **ovector)95 int RegExp::match(const UString& s, int i, OwnArrayPtr<int>* ovector) 101 96 { 102 97 if (i < 0) 103 98 i = 0; 104 int dummyPos;105 if (!pos)106 pos = &dummyPos;107 *pos = -1;108 99 if (ovector) 109 *ovector = 0;100 ovector->clear(); 110 101 111 102 if (i > s.size() || s.isNull()) 112 return UString::null();103 return -1; 113 104 114 #if HAVE(PCREPOSIX)105 #if USE(PCRE16) 115 106 116 107 if (!m_regex) 117 return UString::null();108 return -1; 118 109 119 110 // Set up the offset vector for the result. 120 111 // First 2/3 used for result, the last third used by PCRE. 121 int *offsetVector;112 int* offsetVector; 122 113 int offsetVectorSize; 123 114 int fixedSizeOffsetVector[3]; … … 128 119 offsetVectorSize = (m_numSubPatterns + 1) * 3; 129 120 offsetVector = new int [offsetVectorSize]; 121 ovector->set(offsetVector); 130 122 } 131 123 132 constint numMatches = pcre_exec(m_regex, NULL, reinterpret_cast<const uint16_t *>(s.data()), s.size(), i, 0, offsetVector, offsetVectorSize);124 int numMatches = pcre_exec(m_regex, NULL, reinterpret_cast<const uint16_t *>(s.data()), s.size(), i, 0, offsetVector, offsetVectorSize); 133 125 134 126 if (numMatches < 0) { … … 137 129 fprintf(stderr, "KJS: pcre_exec() failed with result %d\n", numMatches); 138 130 #endif 139 if (o ffsetVector != fixedSizeOffsetVector)140 delete [] offsetVector;141 return UString::null();131 if (ovector) 132 ovector->clear(); 133 return -1; 142 134 } 143 135 144 *pos = offsetVector[0]; 145 if (ovector) 146 *ovector = offsetVector; 147 return s.substr(offsetVector[0], offsetVector[1] - offsetVector[0]); 136 return offsetVector[0]; 148 137 149 138 #else … … 183 172 } 184 173 185 bool RegExp::isHexDigit(UChar uc)186 {187 int c = uc.unicode();188 return (c >= '0' && c <= '9' ||189 c >= 'a' && c <= 'f' ||190 c >= 'A' && c <= 'F');191 }192 193 unsigned char RegExp::convertHex(int c)194 {195 if (c >= '0' && c <= '9')196 return static_cast<unsigned char>(c - '0');197 if (c >= 'a' && c <= 'f')198 return static_cast<unsigned char>(c - 'a' + 10);199 return static_cast<unsigned char>(c - 'A' + 10);200 }201 202 unsigned char RegExp::convertHex(int c1, int c2)203 {204 return ((convertHex(c1) << 4) + convertHex(c2));205 }206 207 UChar RegExp::convertUnicode(UChar uc1, UChar uc2, UChar uc3, UChar uc4)208 {209 int c1 = uc1.unicode();210 int c2 = uc2.unicode();211 int c3 = uc3.unicode();212 int c4 = uc4.unicode();213 return UChar((convertHex(c1) << 4) + convertHex(c2),214 (convertHex(c3) << 4) + convertHex(c4));215 }216 217 174 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.