aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data/sandbox/string-util.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-01-31 08:38:30 -0500
committerGitHub <noreply@github.com>2024-01-31 13:38:30 +0000
commit87ed7c8affd3ade9d3cd2d9ed1a61dd5f224e473 (patch)
treebe727294e31ef21e8a3f634734610e69e4a155ac /ext/js/data/sandbox/string-util.js
parent3e419aa562aab03ca20421aaf7e4d1a39194a5b4 (diff)
Module refactoring (#588)
* Convert PronunciationGenerator into static functions * Convert DictionaryDataUtil into static functions * Convert AnkiNoteDataCreator into static functions * Convert MediaUtil into static functions * Convert RegexUtil into static functions * Convert StringUtil into static functions * Convert ArrayBufferUtil into static functions * Convert AnkiUtil into static functions * Convert PermissionsUtil into static functions * Convert ProfileConditionsUtil into static functions
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;
}