Changeset 31955 in webkit
- Timestamp:
- Apr 16, 2008 12:34:07 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r31954 r31955 1 2008-04-15 Adam Roben <aroben@apple.com> 2 3 Generalize String.format some more 4 5 String.format now takes an initial value and an append function which 6 it uses to build the result. Each time a token is processed, 7 append(valueSoFar, newValue) is called. 8 9 Reviewed by Tim Hatcher. 10 11 * page/inspector/utilities.js: 12 (String.vsprintf): Pass the empty string for the initial value, and 13 a function that concatenates two strings as the append function. 14 (String.format): Use initialValue and append to build the result 15 instead of only working with strings. 16 1 17 2008-04-15 Adam Roben <aroben@apple.com> 2 18 -
trunk/WebCore/page/inspector/utilities.js
r31954 r31955 838 838 String.vsprintf = function(format, substitutions) 839 839 { 840 return String.format(format, substitutions, String.standardFormatters );841 } 842 843 String.format = function(format, substitutions, formatters )840 return String.format(format, substitutions, String.standardFormatters, "", function(a, b) { return a + b; }); 841 } 842 843 String.format = function(format, substitutions, formatters, initialValue, append) 844 844 { 845 845 if (!format || !substitutions || !substitutions.length) 846 return format;846 return append(initialValue, format); 847 847 848 848 function prettyFunctionName() … … 861 861 } 862 862 863 var result = "";863 var result = initialValue; 864 864 var tokens = String.tokenizeFormatString(format); 865 865 … … 868 868 869 869 if (token.type === "string") { 870 result += token.value;870 result = append(result, token.value); 871 871 continue; 872 872 } … … 881 881 // just output the format specifier literally and move on. 882 882 error("not enough substitution arguments. Had " + substitutions.length + " but needed " + (token.substitutionIndex + 1) + ", so substitution was skipped."); 883 result += "%" + (token.precision > -1 ? token.precision : "") + token.specifier;883 result = append(result, "%" + (token.precision > -1 ? token.precision : "") + token.specifier); 884 884 continue; 885 885 } … … 888 888 // Encountered an unsupported format character, treat as a string. 889 889 warn("unsupported format character \u201C" + token.specifier + "\u201D. Treating as a string."); 890 result += substitutions[token.substitutionIndex];890 result = append(result, substitutions[token.substitutionIndex]); 891 891 continue; 892 892 } 893 893 894 result += formatters[token.specifier](substitutions[token.substitutionIndex], token);894 result = append(result, formatters[token.specifier](substitutions[token.substitutionIndex], token)); 895 895 } 896 896
Note: See TracChangeset
for help on using the changeset viewer.