Chromium Code Reviews| Index: ui/webui/resources/js/load_time_data.js |
| diff --git a/ui/webui/resources/js/load_time_data.js b/ui/webui/resources/js/load_time_data.js |
| index 38b4721e13c9a4ac3d4c5da425ec84e38396b5e0..e26e51fd7bd6eee11d4cade9c6712e79de575272 100644 |
| --- a/ui/webui/resources/js/load_time_data.js |
| +++ b/ui/webui/resources/js/load_time_data.js |
| @@ -93,6 +93,35 @@ function LoadTimeData(){} |
| }); |
| }, |
| + /** |
| + * Returns a list of pieces of a substituted string which has separate |
|
tsergeant
2017/06/05 03:33:54
This is a fairly complex function with a bunch of
calamity
2017/06/06 05:36:02
Done.
|
| + * elements for substituted pieces. |
| + * @param {string} label |
|
tsergeant
2017/06/05 03:33:54
Add a comment here to explicitly say that this is
calamity
2017/06/06 05:36:02
Done.
|
| + * @param {...(string|number)} var_args The extra values to include in the |
| + * formatted output. |
| + * @return {!Array<!{value: string, arg: (null|string)}>} The formatted |
| + * string. |
| + */ |
| + getSubstitutedStringPieces: function(label, var_args) { |
| + var varArgs = arguments; |
| + var pieces = label.split(/(?=[^$]?)(\$[1-9])/) |
|
tsergeant
2017/06/05 03:33:54
Why is the positive lookahead here?
It says somet
calamity
2017/06/06 05:36:02
Yeah, good point. Okay. I've revised this. We need
|
| + .filter(function(p) { |
| + return p != ''; |
| + }) |
| + .map(function(p) { |
| + if (!p.match(/\$[1-9]/)) { |
| + // Assert if there are an odd number of $ signs in |
| + // the segment. |
| + assert((p.match(/\$/g) || []).length % 2 == 0); |
|
tsergeant
2017/06/05 03:33:54
This assertion makes getSubstitutedStringPieces()
calamity
2017/06/06 05:36:02
Done. Went with 'all $ must be escaped' and added
|
| + return {value: p.replace(/\$\$/g, '$'), arg: null}; |
| + } |
| + |
| + return {value: varArgs[p[1]], arg: p}; |
| + }); |
| + |
| + return pieces; |
| + }, |
| + |
| /** |
| * As above, but also makes sure that the value is a boolean. |
| * @param {string} id The key that identifies the desired boolean. |