MCPcopy Create free account
hub / github.com/ampproject/amphtml / toUpperCase

Function toUpperCase

validator/js/engine/htmlparser-interface.js:26–40  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

24 * @return {string} The str in upper case format.
25 */
26const 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};
41exports.toUpperCase = toUpperCase;
42/**
43 * Name/Value pair representing an HTML Tag attribute.

Callers 1

constructorMethod · 0.70

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected