Changeset 1623 in webkit for trunk/JavaScriptCore/kjs/string_object.cpp
- Timestamp:
- Jul 21, 2002, 10:38:39 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/string_object.cpp
r1326 r1623 58 58 replace StringProtoFuncImp::Replace DontEnum|Function 2 59 59 search StringProtoFuncImp::Search DontEnum|Function 1 60 slice StringProtoFuncImp::Slice DontEnum|Function 061 split StringProtoFuncImp::Split DontEnum|Function 160 slice StringProtoFuncImp::Slice DontEnum|Function 2 61 split StringProtoFuncImp::Split DontEnum|Function 2 62 62 substr StringProtoFuncImp::Substr DontEnum|Function 2 63 63 substring StringProtoFuncImp::Substring DontEnum|Function 2 … … 197 197 case Search: { 198 198 u = s; 199 RegExp* reg = 0; 199 RegExp *reg, *tmpReg = 0; 200 RegExpImp *imp = 0; 200 201 if (a0.isA(ObjectType) && a0.toObject(exec).inherits(&RegExpImp::info)) 201 202 { 202 RegExpImp*imp = static_cast<RegExpImp *>( a0.toObject(exec).imp() );203 imp = static_cast<RegExpImp *>( a0.toObject(exec).imp() ); 203 204 reg = imp->regExp(); 204 205 } … … 209 210 * replaced with the result of the expression new RegExp(regexp). 210 211 */ 211 reg = new RegExp(a0.toString(exec), RegExp::None);212 reg = tmpReg = new RegExp(a0.toString(exec), RegExp::None); 212 213 } 213 214 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->interpreter()->builtinRegExp().imp()); 214 int **ovector = regExpObj->registerRegexp( reg, u);215 int **ovector = regExpObj->registerRegexp(reg, u); 215 216 UString mstr = reg->match(u, -1, &pos, ovector); 216 regExpObj->setSubPatterns(reg->subPatterns());217 if (a0.isA(StringType))218 delete reg;219 217 if (id == Search) { 220 218 result = Number(pos); 221 break; 222 } 223 if (mstr.isNull()) 224 result = Null(); 225 else 226 result = regExpObj->arrayOfMatches(exec,mstr); 219 } else { 220 // Exec 221 if ((reg->flags() & RegExp::Global) == 0) { 222 // case without 'g' flag is handled like RegExp.prototype.exec 223 if (mstr.isNull()) 224 return Null(); // no match 225 regExpObj->setSubPatterns(reg->subPatterns()); 226 result = regExpObj->arrayOfMatches(exec,mstr); 227 } else { 228 // return array of matches 229 List list; 230 int lastIndex = 0; 231 while (pos >= 0) { 232 list.append(String(mstr)); 233 lastIndex = pos; 234 pos += mstr.isEmpty() ? 1 : mstr.size(); 235 delete [] *ovector; 236 mstr = reg->match(u, pos, &pos, ovector); 237 } 238 if (imp) 239 imp->put(exec, "lastIndex", Number(lastIndex), DontDelete|DontEnum); 240 result = exec->interpreter()->builtinArray().construct(exec, list); 241 } 242 } 243 delete tmpReg; 244 break; 227 245 } 228 break;229 246 case Replace: 230 247 u = s; … … 329 346 break; 330 347 } 331 int *ovector;332 int mpos;333 348 pos = 0; 334 while ( 1) {349 while (pos < u.size()) { 335 350 // TODO: back references 351 int mpos; 352 int *ovector = 0L; 336 353 UString mstr = reg.match(u, pos, &mpos, &ovector); 354 delete [] ovector; ovector = 0L; 337 355 if (mpos < 0) 338 356 break; … … 344 362 } 345 363 } 346 delete [] ovector;347 364 } else if (a0.type() != UndefinedType) { 348 365 u2 = a0.toString(exec);
Note:
See TracChangeset
for help on using the changeset viewer.