PageSourceSearch

https://lienz.gv.at/media/mod_gptranslate/js/jsonrepair/utils/stringUtils.js

js lienz.gv.at collected 2026-10-02 19:10:37 UTC 5,758 bytes, 161 lines download raw bytes

1export const codeBackslash = 0x5c; // "\"
2export const codeSlash = 0x2f; // "/"
3export const codeAsterisk = 0x2a; // "*"
4export const codeOpeningBrace = 0x7b; // "{"
5export const codeClosingBrace = 0x7d; // "}"
6export const codeOpeningBracket = 0x5b; // "["
7export const codeClosingBracket = 0x5d; // "]"
8export const codeOpenParenthesis = 0x28; // "("
9export const codeCloseParenthesis = 0x29; // ")"
10export const codeSpace = 0x20; // " "
11export const codeNewline = 0xa; // "\n"
12export const codeTab = 0x9; // "\t"
13export const codeReturn = 0xd; // "\r"
14export const codeBackspace = 0x08; // "\b"
15export const codeFormFeed = 0x0c; // "\f"
16export const codeDoubleQuote = 0x0022; // "
17export const codePlus = 0x2b; // "+"
18export const codeMinus = 0x2d; // "-"
19export const codeQuote = 0x27; // "'"
20export const codeZero = 0x30; // "0"
21export const codeNine = 0x39; // "9"
22export const codeComma = 0x2c; // ","
23export const codeDot = 0x2e; // "." (dot, period)
24export const codeColon = 0x3a; // ":"
25export const codeSemicolon = 0x3b; // ";"
26export const codeUppercaseA = 0x41; // "A"
27export const codeLowercaseA = 0x61; // "a"
28export const codeUppercaseE = 0x45; // "E"
29export const codeLowercaseE = 0x65; // "e"
30export const codeUppercaseF = 0x46; // "F"
31export const codeLowercaseF = 0x66; // "f"
32const codeNonBreakingSpace = 0xa0;
33const codeEnQuad = 0x2000;
34const codeHairSpace = 0x200a;
35const codeNarrowNoBreakSpace = 0x202f;
36const codeMediumMathematicalSpace = 0x205f;
37const codeIdeographicSpace = 0x3000;
38const codeDoubleQuoteLeft = 0x201c; // “
39const codeDoubleQuoteRight = 0x201d; // ”
40const codeQuoteLeft = 0x2018; // ‘
41const codeQuoteRight = 0x2019; // ’
42const codeGraveAccent = 0x0060; // `
43const codeAcuteAccent = 0x00b4; // ´
44
45export function isHex(code) {
46  return code >= codeZero && code <= codeNine || code >= codeUppercaseA && code <= codeUppercaseF || code >= codeLowercaseA && code <= codeLowercaseF;
47}
48export function isDigit(code) {
49  return code >= codeZero && code <= codeNine;
50}
51export function isValidStringCharacter(code) {
52  return code >= 0x20 && code <= 0x10ffff;
53}
54export function isDelimiter(char) {
55  return regexDelimiter.test(char);
56}
57const regexDelimiter = /^[,:[\]/{}()\n+]$/;
58export function isDelimiterExceptSlash(char) {
59  return isDelimiter(char) && char !== '/';
60}
61export function isStartOfValue(char) {
62  return regexStartOfValue.test(char) || char && isQuote(char.charCodeAt(0));
63}
64
65// alpha, number, minus, or opening bracket or brace
66const regexStartOfValue = /^[[{\w-]$/;
67export function isControlCharacter(code) {
68  return code === codeNewline || code === codeReturn || code === codeTab || code === codeBackspace || code === codeFormFeed;
69}
70
71/**
72 * Check if the given character is a whitespace character like space, tab, or
73 * newline
74 */
75export function isWhitespace(code) {
76  return code === codeSpace || code === codeNewline || code === codeTab || code === codeReturn;
77}
78
79/**
80 * Check if the given character is a special whitespace character, some
81 * unicode variant
82 */
83export function isSpecialWhitespace(code) {
84  return code === codeNonBreakingSpace || code >= codeEnQuad && code <= codeHairSpace || code === codeNarrowNoBreakSpace || code === codeMediumMathematicalSpace || code === codeIdeographicSpace;
85}
86
87/**
88 * Test whether the given character is a quote or double quote character.
89 * Also tests for special variants of quotes.
90 */
91export function isQuote(code) {
92  // the first check double quotes, since that occurs most often
93  return isDoubleQuoteLike(code) || isSingleQuoteLike(code);
94}
95
96/**
97 * Test whether the given character is a double quote character.
98 * Also tests for special variants of double quotes.
99 */
100export function isDoubleQuoteLike(code) {
101  // the first check double quotes, since that occurs most often
102  return code === codeDoubleQuote || code === codeDoubleQuoteLeft || code === codeDoubleQuoteRight;
103}
104
105/**
106 * Test whether the given character is a double quote character.
107 * Does NOT test for special variants of double quotes.
108 */
109export function isDoubleQuote(code) {
110  return code === codeDoubleQuote;
111}
112
113/**
114 * Test whether the given character is a single quote character.
115 * Also tests for special variants of single quotes.
116 */
117export function isSingleQuoteLike(code) {
118  return code === codeQuote || code === codeQuoteLeft || code === codeQuoteRight || code === codeGraveAccent || code === codeAcuteAccent;
119}
120
121/**
122 * Test whether the given character is a single quote character.
123 * Does NOT test for special variants of single quotes.
124 */
125export function isSingleQuote(code) {
126  return code === codeQuote;
127}
128
129/**
130 * Strip last occurrence of textToStrip from text
131 */
132export function stripLastOccurrence(text, textToStrip) {
133  let stripRemainingText = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
134  const index = text.lastIndexOf(textToStrip);
135  return index !== -1 ? text.substring(0, index) + (stripRemainingText ? '' : text.substring(index + 1)) : text;
136}
137export function insertBeforeLastWhitespace(text, textToInsert) {
138  let index = text.length;
139  if (!isWhitespace(text.charCodeAt(index - 1))) {
140    // no trailing whitespaces
141    return text + textToInsert;
142  }
143  while (isWhitespace(text.charCodeAt(index - 1))) {
144    index--;
145  }
146  return text.substring(0, index) + textToInsert + text.substring(index);
147}
148export function removeAtIndex(text, start, count) {
149  return text.substring(0, start) + text.substring(start + count);
150}
151
152/**
153 * Test whether a string ends with a newline or comma character and optional whitespace
154 */
155export function endsWithCommaOrNewline(text) {
156  return /[,\n][ \t\r]*$/.test(text);
157}
158export function isFunctionName(text) {
159  return /^\w+$/.test(text);
160}
161//# sourceMappingURL=stringUtils.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.