Changeset 31956 in webkit


Ignore:
Timestamp:
Apr 16, 2008 12:34:29 PM (16 years ago)
Author:
Adam Roben
Message:

Make String.format return an array of unused substitutions

String.format now returns an object with two properties:
formattedResult and unusedSubstitutions.

Reviewed by Tim Hatcher.

  • page/inspector/utilities.js: (String.vsprintf): Updated for changes to String.format. We throw away the array of unused substitutions. (String.format): Changed to keep track of which substitutions are used when formatting. We then return both the formatted result and the array of unused substitutions.
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r31955 r31956  
     12008-04-15  Adam Roben  <aroben@apple.com>
     2
     3        Make String.format return an array of unused substitutions
     4
     5        String.format now returns an object with two properties:
     6        formattedResult and unusedSubstitutions.
     7
     8        Reviewed by Tim Hatcher.
     9
     10        * page/inspector/utilities.js:
     11        (String.vsprintf): Updated for changes to String.format. We throw away
     12        the array of unused substitutions.
     13        (String.format): Changed to keep track of which substitutions are used
     14        when formatting. We then return both the formatted result and the
     15        array of unused substitutions.
     16
    1172008-04-15  Adam Roben  <aroben@apple.com>
    218
  • trunk/WebCore/page/inspector/utilities.js

    r31955 r31956  
    838838String.vsprintf = function(format, substitutions)
    839839{
    840     return String.format(format, substitutions, String.standardFormatters, "", function(a, b) { return a + b; });
     840    return String.format(format, substitutions, String.standardFormatters, "", function(a, b) { return a + b; }).formattedResult;
    841841}
    842842
     
    844844{
    845845    if (!format || !substitutions || !substitutions.length)
    846         return append(initialValue, format);
     846        return { formattedResult: append(initialValue, format), unusedSubstitutions: substitutions };
    847847
    848848    function prettyFunctionName()
     
    863863    var result = initialValue;
    864864    var tokens = String.tokenizeFormatString(format);
     865    var usedSubstitutionIndexes = {};
    865866
    866867    for (var i = 0; i < tokens.length; ++i) {
     
    885886        }
    886887
     888        usedSubstitutionIndexes[token.substitutionIndex] = true;
     889
    887890        if (!(token.specifier in formatters)) {
    888891            // Encountered an unsupported format character, treat as a string.
     
    895898    }
    896899
    897     return result;
    898 }
     900    var unusedSubstitutions = [];
     901    for (var i = 0; i < substitutions.length; ++i) {
     902        if (i in usedSubstitutionIndexes)
     903            continue;
     904        unusedSubstitutions.push(substitutions[i]);
     905    }
     906
     907    return { formattedResult: result, unusedSubstitutions: unusedSubstitutions };
     908}
Note: See TracChangeset for help on using the changeset viewer.