jmuehlner commented on code in PR #853:
URL: https://github.com/apache/guacamole-client/pull/853#discussion_r1186353027
##########
guacamole-common-js/src/main/webapp/modules/Parser.js:
##########
@@ -157,3 +241,74 @@ Guacamole.Parser = function() {
this.oninstruction = null;
};
+
+/**
+ * Returns the number of Unicode codepoints (not code units) within the given
+ * string. If character offsets are provided, only codepoints between those
+ * offsets are counted. Unlike the length property of a string, this function
+ * counts proper surrogate pairs as a single codepoint. High and low surrogate
+ * characters that are not part of a proper surrogate pair are counted
+ * separately as individual codepoints.
+ *
+ * @param {!string} str
+ * The string whose contents should be inspected.
+ *
+ * @param {number} [start=0]
+ * The index of the location in the given string where codepoint counting
+ * should start. If omitted, counting will begin at the start of the
+ * string.
+ *
+ * @param {number} [end]
+ * The index of the first location in the given string after where counting
+ * should stop (the character after the last character being counted). If
+ * omitted, all characters after the start location will be counted.
+ *
+ * @returns {!number}
+ * The number of Unicode codepoints within the requested portion of the
+ * given string.
+ */
+Guacamole.Parser.codePointCount = function codePointCount(str, start, end) {
+ str = str.substring(start || 0, end);
+ var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g);
Review Comment:
A quick comment (or commented constant) on what this regex is doing would be
cool.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]