| 24 | * @return {string} The str in upper case format. |
| 25 | */ |
| 26 | const toUpperCase = function(str) { |
| 27 | // htmlparser heavily relies on the length of the strings, and |
| 28 | // unfortunately some characters change their length when |
| 29 | // lowercased; for instance, the Turkish İ has a length of 1, but |
| 30 | // when lower-cased, it has a length of 2. So, as a workaround we |
| 31 | // check that the length be the same as before upper-casing, and if |
| 32 | // not, we only upper-case the letters A-Z. |
| 33 | const upperCased = str.toUpperCase(); |
| 34 | if (upperCased.length == str.length) { |
| 35 | return upperCased; |
| 36 | } |
| 37 | return str.replace(/[a-z]/g, function(ch) { |
| 38 | return String.fromCharCode(ch.charCodeAt(0) & 223); |
| 39 | }); |
| 40 | }; |
| 41 | exports.toUpperCase = toUpperCase; |
| 42 | /** |
| 43 | * Name/Value pair representing an HTML Tag attribute. |