OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 /** | 855 /** |
856 * @param {string} format | 856 * @param {string} format |
857 * @param {...*} var_arg | 857 * @param {...*} var_arg |
858 * @return {string} | 858 * @return {string} |
859 */ | 859 */ |
860 String.sprintf = function(format, var_arg) | 860 String.sprintf = function(format, var_arg) |
861 { | 861 { |
862 return String.vsprintf(format, Array.prototype.slice.call(arguments, 1)); | 862 return String.vsprintf(format, Array.prototype.slice.call(arguments, 1)); |
863 } | 863 } |
864 | 864 |
865 /** | |
866 * @param {string} format | |
867 * @param {!Object.<string, function(string, ...):*>} formatters | |
868 * @return {!Array.<!Object>} | |
869 */ | |
865 String.tokenizeFormatString = function(format, formatters) | 870 String.tokenizeFormatString = function(format, formatters) |
866 { | 871 { |
867 var tokens = []; | 872 var tokens = []; |
868 var substitutionIndex = 0; | 873 var substitutionIndex = 0; |
869 | 874 |
870 function addStringToken(str) | 875 function addStringToken(str) |
871 { | 876 { |
872 tokens.push({ type: "string", value: str }); | 877 tokens.push({ type: "string", value: str }); |
873 } | 878 } |
874 | 879 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
969 /** | 974 /** |
970 * @param {string} format | 975 * @param {string} format |
971 * @param {!Array.<*>} substitutions | 976 * @param {!Array.<*>} substitutions |
972 * @return {string} | 977 * @return {string} |
973 */ | 978 */ |
974 String.vsprintf = function(format, substitutions) | 979 String.vsprintf = function(format, substitutions) |
975 { | 980 { |
976 return String.format(format, substitutions, String.standardFormatters, "", f unction(a, b) { return a + b; }).formattedResult; | 981 return String.format(format, substitutions, String.standardFormatters, "", f unction(a, b) { return a + b; }).formattedResult; |
977 } | 982 } |
978 | 983 |
984 /** | |
985 * @param {string} format | |
986 * @param {?Array.<string>} substitutions | |
987 * @param {!Object.<string, function(string, ...):string>} formatters | |
988 * @param {!T} initialValue | |
989 * @param {function(?, ?): T|undefined} append | |
aandrey
2014/06/17 11:33:54
function(T, string)
apavlov
2014/06/17 12:46:03
Done.
| |
990 * @return {!{formattedResult: T, unusedSubstitutions: ?Array.<string>}}; | |
991 * @template T | |
992 */ | |
979 String.format = function(format, substitutions, formatters, initialValue, append ) | 993 String.format = function(format, substitutions, formatters, initialValue, append ) |
980 { | 994 { |
981 if (!format || !substitutions || !substitutions.length) | 995 if (!format || !substitutions || !substitutions.length) |
982 return { formattedResult: append(initialValue, format), unusedSubstituti ons: substitutions }; | 996 return { formattedResult: append(initialValue, format), unusedSubstituti ons: substitutions }; |
983 | 997 |
984 function prettyFunctionName() | 998 function prettyFunctionName() |
985 { | 999 { |
986 return "String.format(\"" + format + "\", \"" + substitutions.join("\", \"") + "\")"; | 1000 return "String.format(\"" + format + "\", \"" + substitutions.join("\", \"") + "\")"; |
987 } | 1001 } |
988 | 1002 |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1731 this._outgoingCallback(); | 1745 this._outgoingCallback(); |
1732 } | 1746 } |
1733 } | 1747 } |
1734 | 1748 |
1735 /** | 1749 /** |
1736 * @param {*} value | 1750 * @param {*} value |
1737 */ | 1751 */ |
1738 function suppressUnused(value) | 1752 function suppressUnused(value) |
1739 { | 1753 { |
1740 } | 1754 } |
OLD | NEW |