src/js/builtin/RegExp.js
//   * replaceValue is a string without "$"
replaceValue is a string without "$"
replaceValue is a string without " $ "
function RegExpGlobalReplaceShortOpt(rx, S, lengthS, replaceValue, flags)
{
    var fullUnicode = !!(flags & REGEXP_UNICODE_FLAG);
    var lastIndex = 0;
    rx.lastIndex = 0;
    var accumulatedResult = "";
    var nextSourcePosition = 0;
    while (true) {
        a.
        var result = RegExpSearcher(rx, S, lastIndex);
        b.
        if (result === -1)
            break;
        var position = result & 0x7fff;
        lastIndex = (result >> 15) & 0x7fff;
        accumulatedResult += Substring(S, nextSourcePosition,
                                       position - nextSourcePosition) + replaceValue;
        nextSourcePosition = lastIndex;
        c.iii.2.
        if (lastIndex === position) {
            lastIndex = fullUnicode ? AdvanceStringIndex(S, lastIndex) : lastIndex + 1;
            if (lastIndex > lengthS)
                break;
        }
    }
    if (nextSourcePosition >= lengthS)
        return accumulatedResult;
    return accumulatedResult + Substring(S, nextSourcePosition, lengthS - nextSourcePosition);
}
function RegExpGlobalReplaceShortOpt ( rx , S , lengthS , replaceValue , flags ) { var fullUnicode = ! ! ( flags & REGEXP_UNICODE_FLAG ) ; var lastIndex = 0 ; rx . lastIndex = 0 ; var accumulatedResult = "" ; var nextSourcePosition = 0 ; while ( true ) { var result = RegExpSearcher ( rx , S , lastIndex ) ; if ( result === - 1 ) break ; var position = result & 0x7fff ; lastIndex = ( result >> 15 ) & 0x7fff ; accumulatedResult += Substring ( S , nextSourcePosition , position - nextSourcePosition ) + replaceValue ; nextSourcePosition = lastIndex ; if ( lastIndex === position ) { lastIndex = fullUnicode ? AdvanceStringIndex ( S , lastIndex ) : lastIndex + 1 ; if ( lastIndex > lengthS ) break ; } } if ( nextSourcePosition >= lengthS ) return accumulatedResult ; return accumulatedResult + Substring ( S , nextSourcePosition , lengthS - nextSourcePosition ) ; }
replaceValue is a string without "$"
replaceValue is a string without " $ "
// Step 8.a. // Step 8.b. // Step 12 (reordered). // Step 13 (reordered). // Step 11. // Step 11.a. // Step 11.b. // Step 14.l.ii. // Step 14.l.iii. // Step 11.c.iii.2. // Step 15. // Step 16.