Changeset 18182 in webkit for trunk/JavaScriptCore/kjs/regexp.cpp
- Timestamp:
- Dec 12, 2006, 12:09:58 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/regexp.cpp
r17862 r18182 2 2 /* 3 3 * This file is part of the KDE libraries 4 * Copyright (C) 1999-2001 Harri Porten ([email protected])4 * Copyright (C) 1999-2001,2004 Harri Porten ([email protected]) 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 23 23 #include "regexp.h" 24 24 25 #include "lexer.h" 26 25 27 #include <assert.h> 26 28 #include <stdio.h> … … 31 33 32 34 RegExp::RegExp(const UString &p, int flags) 33 : _flags(flags),_numSubPatterns(0)35 : m_flags(flags), m_constructionError(0), m_numSubPatterns(0) 34 36 { 35 37 #if HAVE(PCREPOSIX) … … 49 51 50 52 pattern.append('\0'); 51 _regex = pcre_compile(reinterpret_cast<const uint16_t*>(pattern.data()),53 m_regex = pcre_compile(reinterpret_cast<const uint16_t*>(pattern.data()), 52 54 options, &errorMessage, &errorOffset, NULL); 53 if (! _regex) {55 if (!m_regex) { 54 56 // Try again, this time handle any \u we might find. 55 57 UString uPattern = sanitizePattern(pattern); 56 _regex = pcre_compile(reinterpret_cast<const uint16_t*>(uPattern.data()),58 m_regex = pcre_compile(reinterpret_cast<const uint16_t*>(uPattern.data()), 57 59 options, &errorMessage, &errorOffset, NULL); 58 if (!_regex) 60 if (!m_regex) { 61 m_constructionError = strdup(errorMessage); 59 62 return; 63 } 60 64 } 61 65 62 66 #ifdef PCRE_INFO_CAPTURECOUNT 63 67 // Get number of subpatterns that will be returned. 64 pcre_fullinfo( _regex, NULL, PCRE_INFO_CAPTURECOUNT, &_numSubPatterns);68 pcre_fullinfo(m_regex, NULL, PCRE_INFO_CAPTURECOUNT, &m_numSubPatterns); 65 69 #endif 66 70 … … 81 85 // Note: the Global flag is already handled by RegExpProtoFunc::execute 82 86 83 regcomp(&_regex, p.ascii(), regflags); 84 /* TODO check for errors */ 87 // FIXME: support \u Unicode escapes. 88 89 int errorCode = regcomp(&m_regex, intern.ascii(), regflags); 90 if (errorCode != 0) { 91 char errorMessage[80]; 92 regerror(errorCode, &m_regex, errorMessage, sizeof errorMessage); 93 m_constructionError = strdup(errorMessage); 94 } 85 95 86 96 #endif … … 90 100 { 91 101 #if HAVE(PCREPOSIX) 92 pcre_free( _regex);102 pcre_free(m_regex); 93 103 #else 94 104 /* TODO: is this really okay after an error ? */ 95 regfree(&_regex); 96 #endif 105 regfree(&m_regex); 106 #endif 107 free(m_constructionError); 97 108 } 98 109 … … 113 124 #if HAVE(PCREPOSIX) 114 125 115 if (! _regex)126 if (!m_regex) 116 127 return UString::null(); 117 128 … … 125 136 offsetVector = fixedSizeOffsetVector; 126 137 } else { 127 offsetVectorSize = ( _numSubPatterns + 1) * 3;138 offsetVectorSize = (m_numSubPatterns + 1) * 3; 128 139 offsetVector = new int [offsetVectorSize]; 129 140 } 130 141 131 const int numMatches = pcre_exec( _regex, NULL, reinterpret_cast<const uint16_t *>(s.data()), s.size(), i, 0, offsetVector, offsetVectorSize);142 const int numMatches = pcre_exec(m_regex, NULL, reinterpret_cast<const uint16_t *>(s.data()), s.size(), i, 0, offsetVector, offsetVectorSize); 132 143 133 144 if (numMatches < 0) { … … 152 163 153 164 char *str = strdup(s.ascii()); // TODO: why ??? 154 if (regexec(& _regex, str + i, maxMatch, rmatch, 0)) {165 if (regexec(&m_regex, str + i, maxMatch, rmatch, 0)) { 155 166 free(str); 156 167 return UString::null(); … … 164 175 165 176 // map rmatch array to ovector used in PCRE case 166 _numSubPatterns = 0;177 m_numSubPatterns = 0; 167 178 for(unsigned j = 1; j < maxMatch && rmatch[j].rm_so >= 0 ; j++) 168 _numSubPatterns++;169 int ovecsize = ( _numSubPatterns+1)*3; // see above179 m_numSubPatterns++; 180 int ovecsize = (m_numSubPatterns+1)*3; // see above 170 181 *ovector = new int[ovecsize]; 171 for (unsigned j = 0; j < _numSubPatterns + 1; j++) {182 for (unsigned j = 0; j < m_numSubPatterns + 1; j++) { 172 183 if (j>maxMatch) 173 184 break;
Note:
See TracChangeset
for help on using the changeset viewer.