Changeset 27320 in webkit for trunk/JavaScriptCore/kjs/string_object.cpp
- Timestamp:
- Oct 31, 2007, 7:46:41 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/string_object.cpp
r27222 r27320 339 339 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp()); 340 340 341 int matchIndex = 0;342 341 int lastIndex = 0; 343 342 int startPosition = 0; … … 352 351 // This is either a loop (if global is set) or a one-way (if not). 353 352 do { 354 int *ovector; 355 UString matchString = regExpObj->performMatch(reg, source, startPosition, &matchIndex, &ovector); 356 if (matchIndex == -1) 353 int matchIndex; 354 int matchLen; 355 int* ovector; 356 regExpObj->performMatch(reg, source, startPosition, matchIndex, matchLen, &ovector); 357 if (matchIndex < 0) 357 358 break; 358 int matchLen = matchString.size();359 359 360 360 pushSourceRange(sourceRanges, sourceRangeCount, sourceRangeCapacity, UString::Range(lastIndex, matchIndex - lastIndex)); … … 365 365 List args; 366 366 367 args.append(jsString(matchString)); 368 369 for (unsigned i = 0; i < reg->subPatterns(); i++) { 370 int matchStart = ovector[(i + 1) * 2]; 371 int matchLen = ovector[(i + 1) * 2 + 1] - matchStart; 367 for (unsigned i = 0; i < reg->subPatterns() + 1; i++) { 368 int matchStart = ovector[i * 2]; 369 int matchLen = ovector[i * 2 + 1] - matchStart; 372 370 373 371 if (matchStart < 0) … … 525 523 } 526 524 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp()); 527 UString mstr = regExpObj->performMatch(reg, u, 0, &pos); 525 int pos; 526 int matchLength; 527 regExpObj->performMatch(reg, u, 0, pos, matchLength); 528 528 if (id == Search) { 529 529 result = jsNumber(pos); 530 530 } else { 531 // Exec531 // Match 532 532 if ((reg->flags() & RegExp::Global) == 0) { 533 533 // case without 'g' flag is handled like RegExp.prototype.exec 534 if ( mstr.isNull()) {534 if (pos < 0) 535 535 result = jsNull(); 536 } else { 537 result = regExpObj->arrayOfMatches(exec,mstr); 538 } 536 else 537 result = regExpObj->arrayOfMatches(exec); 539 538 } else { 540 539 // return array of matches … … 542 541 int lastIndex = 0; 543 542 while (pos >= 0) { 544 if (mstr.isNull()) 545 list.append(jsUndefined()); 546 else 547 list.append(jsString(mstr)); 543 list.append(jsString(u.substr(pos, matchLength))); 548 544 lastIndex = pos; 549 pos += m str.isEmpty() ? 1 : mstr.size();550 mstr = regExpObj->performMatch(reg, u, pos, &pos);545 pos += matchLength == 0 ? 1 : matchLength; 546 regExpObj->performMatch(reg, u, pos, pos, matchLength); 551 547 } 552 548 if (imp) … … 600 596 if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpImp::info)) { 601 597 RegExp *reg = static_cast<RegExpImp *>(a0)->regExp(); 602 if (u.isEmpty() && !reg->match(u, 0).isNull()) {598 if (u.isEmpty() && reg->match(u, 0) >= 0) { 603 599 // empty string matched by regexp -> empty array 604 600 res->put(exec, exec->propertyNames().length, jsNumber(0)); … … 607 603 pos = 0; 608 604 while (static_cast<uint32_t>(i) != limit && pos < u.size()) { 609 int mpos; 610 int* ovector; 611 UString mstr = reg->match(u, pos, &mpos, &ovector); 612 if (mpos < 0) { 613 delete [] ovector; 605 OwnArrayPtr<int> ovector; 606 int mpos = reg->match(u, pos, &ovector); 607 if (mpos < 0) 614 608 break; 615 }616 pos = mpos + (m str.isEmpty() ? 1 : mstr.size());617 if (mpos != p0 || !mstr.isEmpty()) {609 int mlen = ovector[1] - ovector[0]; 610 pos = mpos + (mlen == 0 ? 1 : mlen); 611 if (mpos != p0 || mlen) { 618 612 res->put(exec,i, jsString(u.substr(p0, mpos-p0))); 619 p0 = mpos + m str.size();613 p0 = mpos + mlen; 620 614 i++; 621 615 } … … 627 621 res->put(exec, i++, jsString(u.substr(spos, ovector[si * 2 + 1] - spos))); 628 622 } 629 delete [] ovector;630 623 } 631 624 } else {
Note:
See TracChangeset
for help on using the changeset viewer.