Changeset 35027 in webkit for trunk/JavaScriptCore/kjs/regexp.cpp
- Timestamp:
- Jul 6, 2008, 7:49:29 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/regexp.cpp
r34580 r35027 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 2 * Copyright (C) 1999-2001, 2004 Harri Porten ([email protected]) … … 34 33 35 34 inline RegExp::RegExp(const UString& pattern) 36 : m_pattern(pattern)37 , m_flagBits(0)38 , m_constructionError(0)39 , m_numSubpatterns(0)35 : m_pattern(pattern) 36 , m_flagBits(0) 37 , m_constructionError(0) 38 , m_numSubpatterns(0) 40 39 { 41 40 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), … … 49 48 50 49 inline RegExp::RegExp(const UString& pattern, const UString& flags) 51 : m_pattern(pattern)52 , m_flags(flags)53 , m_flagBits(0)54 , m_constructionError(0)55 , m_numSubpatterns(0)50 : m_pattern(pattern) 51 , m_flags(flags) 52 , m_flagBits(0) 53 , m_constructionError(0) 54 , m_numSubpatterns(0) 56 55 { 57 56 // NOTE: The global flag is handled on a case-by-case basis by functions like … … 72 71 multilineOption = JSRegExpMultiline; 73 72 } 74 73 75 74 m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(), 76 75 ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); … … 89 88 int RegExp::match(const UString& s, int i, OwnArrayPtr<int>* ovector) 90 89 { 91 if (i < 0)92 i = 0;93 if (ovector)94 ovector->clear();90 if (i < 0) 91 i = 0; 92 if (ovector) 93 ovector->clear(); 95 94 96 if (i > s.size() || s.isNull())97 return -1;95 if (i > s.size() || s.isNull()) 96 return -1; 98 97 99 if (!m_regExp)100 return -1;98 if (!m_regExp) 99 return -1; 101 100 102 // Set up the offset vector for the result.103 // First 2/3 used for result, the last third used by PCRE.104 int* offsetVector;105 int offsetVectorSize;106 int fixedSizeOffsetVector[3];107 if (!ovector) {108 offsetVectorSize = 3;109 offsetVector = fixedSizeOffsetVector;110 } else {111 offsetVectorSize = (m_numSubpatterns + 1) * 3;112 offsetVector = new int [offsetVectorSize];113 ovector->set(offsetVector);114 }101 // Set up the offset vector for the result. 102 // First 2/3 used for result, the last third used by PCRE. 103 int* offsetVector; 104 int offsetVectorSize; 105 int fixedSizeOffsetVector[3]; 106 if (!ovector) { 107 offsetVectorSize = 3; 108 offsetVector = fixedSizeOffsetVector; 109 } else { 110 offsetVectorSize = (m_numSubpatterns + 1) * 3; 111 offsetVector = new int [offsetVectorSize]; 112 ovector->set(offsetVector); 113 } 115 114 116 int numMatches = jsRegExpExecute(m_regExp, reinterpret_cast<const UChar*>(s.data()), s.size(), i, offsetVector, offsetVectorSize);115 int numMatches = jsRegExpExecute(m_regExp, reinterpret_cast<const UChar*>(s.data()), s.size(), i, offsetVector, offsetVectorSize); 117 116 118 if (numMatches < 0) {117 if (numMatches < 0) { 119 118 #ifndef NDEBUG 120 if (numMatches != JSRegExpErrorNoMatch)121 fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches);119 if (numMatches != JSRegExpErrorNoMatch) 120 fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches); 122 121 #endif 123 if (ovector)124 ovector->clear();125 return -1;126 }122 if (ovector) 123 ovector->clear(); 124 return -1; 125 } 127 126 128 return offsetVector[0];127 return offsetVector[0]; 129 128 } 130 129
Note:
See TracChangeset
for help on using the changeset viewer.