Changeset 9462 in webkit for trunk/JavaScriptCore/kjs/string_object.cpp
- Timestamp:
- Jun 22, 2005, 10:26:17 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/string_object.cpp
r9455 r9462 265 265 static Value replace(ExecState *exec, const UString &source, const Value &pattern, const Value &replacement) 266 266 { 267 ObjectImp *replacementFunction = 0; 268 UString replacementString; 269 270 if (replacement.type() == ObjectType && replacement.toObject(exec).implementsCall()) 271 replacementFunction = replacement.toObject(exec).imp(); 272 else 273 replacementString = replacement.toString(exec); 274 267 275 if (pattern.type() == ObjectType && pattern.toObject(exec).inherits(&RegExpImp::info)) { 268 276 RegExpImp* imp = static_cast<RegExpImp *>( pattern.toObject(exec).imp() ); … … 271 279 272 280 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp().imp()); 273 274 UString replacementString = replacement.toString(exec);275 281 276 282 int matchIndex = 0; … … 296 302 pushSourceRange(sourceRanges, sourceRangeCount, sourceRangeCapacity, UString::Range(lastIndex, matchIndex - lastIndex)); 297 303 304 if (replacementFunction) { 305 int completeMatchStart = (*ovector)[0]; 306 List args; 307 308 args.append(Value(matchString)); 309 310 for (unsigned i = 0; i < reg->subPatterns(); i++) { 311 int matchStart = (*ovector)[(i + 1) * 2]; 312 int matchLen = (*ovector)[(i + 1) * 2 + 1] - matchStart; 313 314 args.append(Value(source.substr(matchStart, matchLen))); 315 } 316 317 args.append(Value(completeMatchStart)); 318 args.append(Value(source)); 319 320 replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(), 321 args).toString(exec); 322 } 323 298 324 UString substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg); 299 325 pushReplacement(replacements, replacementCount, replacementCapacity, substitutedReplacement); … … 328 354 if (matchPos == -1) 329 355 return String(source); 330 return String(source.substr(0, matchPos) + replacement.toString(exec) + source.substr(matchPos + matchLen)); 356 357 if (replacementFunction) { 358 List args; 359 360 args.append(Value(source.substr(matchPos, matchLen))); 361 args.append(Value(matchPos)); 362 args.append(Value(source)); 363 364 replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(), 365 args).toString(exec); 366 } 367 368 return String(source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen)); 331 369 } 332 370
Note:
See TracChangeset
for help on using the changeset viewer.