summaryrefslogtreecommitdiff
path: root/ext/js/data/sandbox/string-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/data/sandbox/string-util.js')
-rw-r--r--ext/js/data/sandbox/string-util.js89
1 files changed, 42 insertions, 47 deletions
diff --git a/ext/js/data/sandbox/string-util.js b/ext/js/data/sandbox/string-util.js
index 3bc1c549..45e52f08 100644
--- a/ext/js/data/sandbox/string-util.js
+++ b/ext/js/data/sandbox/string-util.js
@@ -17,59 +17,54 @@
*/
/**
- * Class containing generic string utility functions.
+ * Reads code points from a string in the forward direction.
+ * @param {string} text The text to read the code points from.
+ * @param {number} position The index of the first character to read.
+ * @param {number} count The number of code points to read.
+ * @returns {string} The code points from the string.
*/
-export class StringUtil {
- /**
- * Reads code points from a string in the forward direction.
- * @param {string} text The text to read the code points from.
- * @param {number} position The index of the first character to read.
- * @param {number} count The number of code points to read.
- * @returns {string} The code points from the string.
- */
- static readCodePointsForward(text, position, count) {
- const textLength = text.length;
- let result = '';
- for (; count > 0; --count) {
- const char = text[position];
- result += char;
- if (++position >= textLength) { break; }
- const charCode = char.charCodeAt(0);
- if (charCode >= 0xd800 && charCode < 0xdc00) { // charCode is a high surrogate code
- const char2 = text[position];
- const charCode2 = char2.charCodeAt(0);
- if (charCode2 >= 0xdc00 && charCode2 < 0xe000) { // charCode2 is a low surrogate code
- result += char2;
- if (++position >= textLength) { break; }
- }
+export function readCodePointsForward(text, position, count) {
+ const textLength = text.length;
+ let result = '';
+ for (; count > 0; --count) {
+ const char = text[position];
+ result += char;
+ if (++position >= textLength) { break; }
+ const charCode = char.charCodeAt(0);
+ if (charCode >= 0xd800 && charCode < 0xdc00) { // charCode is a high surrogate code
+ const char2 = text[position];
+ const charCode2 = char2.charCodeAt(0);
+ if (charCode2 >= 0xdc00 && charCode2 < 0xe000) { // charCode2 is a low surrogate code
+ result += char2;
+ if (++position >= textLength) { break; }
}
}
- return result;
}
+ return result;
+}
- /**
- * Reads code points from a string in the backward direction.
- * @param {string} text The text to read the code points from.
- * @param {number} position The index of the first character to read.
- * @param {number} count The number of code points to read.
- * @returns {string} The code points from the string.
- */
- static readCodePointsBackward(text, position, count) {
- let result = '';
- for (; count > 0; --count) {
- const char = text[position];
- result = char + result;
- if (--position < 0) { break; }
- const charCode = char.charCodeAt(0);
- if (charCode >= 0xdc00 && charCode < 0xe000) { // charCode is a low surrogate code
- const char2 = text[position];
- const charCode2 = char2.charCodeAt(0);
- if (charCode2 >= 0xd800 && charCode2 < 0xdc00) { // charCode2 is a high surrogate code
- result = char2 + result;
- if (--position < 0) { break; }
- }
+/**
+ * Reads code points from a string in the backward direction.
+ * @param {string} text The text to read the code points from.
+ * @param {number} position The index of the first character to read.
+ * @param {number} count The number of code points to read.
+ * @returns {string} The code points from the string.
+ */
+export function readCodePointsBackward(text, position, count) {
+ let result = '';
+ for (; count > 0; --count) {
+ const char = text[position];
+ result = char + result;
+ if (--position < 0) { break; }
+ const charCode = char.charCodeAt(0);
+ if (charCode >= 0xdc00 && charCode < 0xe000) { // charCode is a low surrogate code
+ const char2 = text[position];
+ const charCode2 = char2.charCodeAt(0);
+ if (charCode2 >= 0xd800 && charCode2 < 0xdc00) { // charCode2 is a high surrogate code
+ result = char2 + result;
+ if (--position < 0) { break; }
}
}
- return result;
}
+ return result;
}