Chromium Code Reviews| Index: ui/webui/resources/js/util.js |
| diff --git a/ui/webui/resources/js/util.js b/ui/webui/resources/js/util.js |
| index caf421e38519b6de61582333660dda4d683decbe..815939cc336764fa39c20726a5431128ca1e9996 100644 |
| --- a/ui/webui/resources/js/util.js |
| +++ b/ui/webui/resources/js/util.js |
| @@ -381,3 +381,31 @@ function scrollLeftForDocument(doc) { |
| function setScrollLeftForDocument(doc, value) { |
| doc.documentElement.scrollLeft = doc.body.scrollLeft = value; |
| } |
| + |
| +/** |
| + * Replace '&', '<', '>', '"', and ''' characters with their HTML encoding. |
|
Pam (message me for reviews)
2014/01/08 14:36:46
nit: Replaces
Adrian Kuegel
2014/01/08 16:49:09
Done.
|
| + * @param {string} original The original string. |
| + * @return {string} The string with all the characters mentioned above replaced. |
| + */ |
| +function HTMLEscape(original) { |
| + return original.replace(/&/g, '&') |
| + .replace(/</g, '<') |
| + .replace(/>/g, '>') |
| + .replace(/"/g, '"') |
| + .replace(/'/g, '''); |
| +} |
| + |
| +/** |
| + * Shortens the provided string (if necessary) to a string of length at most |
| + * |maxLength|. |
| + * @param {string} original The original string. |
| + * @param {number} maxLength The maximum length allowed for the string. |
| + * @return {string} The original string if its length does not exceed |
| + * |maxLength|. Otherwise the first |maxLength| - 3 characters with '...' |
| + * appended. |
| + */ |
| +function elide(original, maxLength) { |
| + if (original.length <= maxLength) |
| + return original; |
| + return original.substring(0, maxLength - 3) + '...'; |
| +} |