From fe777584ae04a54b0836bb66f026f99f236423a4 Mon Sep 17 00:00:00 2001 From: Edwin Hoogerbeets Date: Mon, 3 Mar 2025 22:02:37 -0800 Subject: [PATCH] Updated documentation --- .../ilib-tools-common/docs/CSharpEscaper.html | 449 +++ .../docs/DirectoryWalk.js.html | 4 +- packages/ilib-tools-common/docs/Escaper.html | 1132 +++++++ .../docs/EscaperFactory.js.html | 220 ++ .../ilib-tools-common/docs/JavaEscaper.html | 450 +++ .../docs/JavascriptEscaper.html | 448 +++ .../ilib-tools-common/docs/JsonEscaper.html | 363 +++ packages/ilib-tools-common/docs/Location.html | 4 +- .../ilib-tools-common/docs/Location.js.html | 4 +- .../ilib-tools-common/docs/PHPEscaper.html | 451 +++ .../ilib-tools-common/docs/PythonEscaper.html | 450 +++ .../docs/RegexBasedEscaper.html | 447 +++ packages/ilib-tools-common/docs/Resource.html | 4 +- .../ilib-tools-common/docs/Resource.js.html | 4 +- .../ilib-tools-common/docs/ResourceArray.html | 4 +- .../docs/ResourceArray.js.html | 4 +- .../docs/ResourceConvert.js.html | 4 +- .../docs/ResourcePlural.html | 4 +- .../docs/ResourcePlural.js.html | 4 +- .../docs/ResourceString.html | 4 +- .../docs/ResourceString.js.html | 4 +- .../ilib-tools-common/docs/ResourceXliff.html | 4 +- .../docs/ResourceXliff.js.html | 4 +- .../ilib-tools-common/docs/SmartyEscaper.html | 449 +++ .../ilib-tools-common/docs/SwiftEscaper.html | 449 +++ .../docs/TranslationSet.html | 4 +- .../docs/TranslationSet.js.html | 4 +- .../docs/TranslationUnit.html | 4 +- .../docs/TranslationUnit.js.html | 4 +- .../docs/TranslationVariant.html | 4 +- .../docs/TranslationVariant.js.html | 4 +- .../ilib-tools-common/docs/URIEscaper.html | 366 +++ .../docs/escapes_CSharpEscaper.js.html | 174 ++ .../docs/escapes_EscapeCommon.js.html | 870 ++++++ .../docs/escapes_Escaper.js.html | 175 ++ .../docs/escapes_JavaEscaper.js.html | 176 ++ .../docs/escapes_JavascriptEscaper.js.html | 169 + .../docs/escapes_JsonEscaper.js.html | 131 + .../docs/escapes_PHPEscaper.js.html | 168 + .../docs/escapes_PythonEscaper.js.html | 167 + .../docs/escapes_RegexBasedEscaper.js.html | 138 + .../docs/escapes_SmartyEscaper.js.html | 163 + .../docs/escapes_SwiftEscaper.js.html | 158 + .../docs/escapes_URIEscaper.js.html | 124 + packages/ilib-tools-common/docs/global.html | 2751 ++++++++++++++++- .../ilib-tools-common/docs/ilibToolsCommon.md | 992 +++++- packages/ilib-tools-common/docs/index.html | 4 +- packages/ilib-tools-common/docs/utils.js.html | 4 +- 48 files changed, 11924 insertions(+), 194 deletions(-) create mode 100644 packages/ilib-tools-common/docs/CSharpEscaper.html create mode 100644 packages/ilib-tools-common/docs/Escaper.html create mode 100644 packages/ilib-tools-common/docs/EscaperFactory.js.html create mode 100644 packages/ilib-tools-common/docs/JavaEscaper.html create mode 100644 packages/ilib-tools-common/docs/JavascriptEscaper.html create mode 100644 packages/ilib-tools-common/docs/JsonEscaper.html create mode 100644 packages/ilib-tools-common/docs/PHPEscaper.html create mode 100644 packages/ilib-tools-common/docs/PythonEscaper.html create mode 100644 packages/ilib-tools-common/docs/RegexBasedEscaper.html create mode 100644 packages/ilib-tools-common/docs/SmartyEscaper.html create mode 100644 packages/ilib-tools-common/docs/SwiftEscaper.html create mode 100644 packages/ilib-tools-common/docs/URIEscaper.html create mode 100644 packages/ilib-tools-common/docs/escapes_CSharpEscaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_EscapeCommon.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_Escaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_JavaEscaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_JavascriptEscaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_JsonEscaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_PHPEscaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_PythonEscaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_RegexBasedEscaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_SmartyEscaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_SwiftEscaper.js.html create mode 100644 packages/ilib-tools-common/docs/escapes_URIEscaper.js.html diff --git a/packages/ilib-tools-common/docs/CSharpEscaper.html b/packages/ilib-tools-common/docs/CSharpEscaper.html new file mode 100644 index 000000000..1467fbbba --- /dev/null +++ b/packages/ilib-tools-common/docs/CSharpEscaper.html @@ -0,0 +1,449 @@ + + + + + + CSharpEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

CSharpEscaper

+ + + + + + + +
+ +
+ +

+ + CSharpEscaper + +

+ +
Escaper for CSharp
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new CSharpEscaper(style)

+ + + + + + +
+ +
Description:
+
  • Can support the following styles: +- csharp (default): single or double-quoted strings +- csharp-raw: csharp multi-line strings like """foo""" +- csharp-verbatim: csharp raw strings like @"foo"
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +string + + + + + the style to use for escaping
+ + + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+ if the style is not supported +
+
+
+
+
+
+ Type +
+
+ +Error + + + +
+
+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/DirectoryWalk.js.html b/packages/ilib-tools-common/docs/DirectoryWalk.js.html index 2170a7c8c..daeb00eea 100644 --- a/packages/ilib-tools-common/docs/DirectoryWalk.js.html +++ b/packages/ilib-tools-common/docs/DirectoryWalk.js.html @@ -29,7 +29,7 @@ @@ -241,7 +241,7 @@

DirectoryWalk.js


diff --git a/packages/ilib-tools-common/docs/Escaper.html b/packages/ilib-tools-common/docs/Escaper.html new file mode 100644 index 000000000..4de1d80d7 --- /dev/null +++ b/packages/ilib-tools-common/docs/Escaper.html @@ -0,0 +1,1132 @@ + + + + + + Escaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

Escaper

+ + + + + + + +
+ +
+ +

+ + Escaper + +

+ +
A class that escapes and unescapes strings.
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

(abstract) new Escaper(style)

+ + + + + + +
+ +
Description:
+
  • Create a new escaper instance.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +Object + + + + + the style object to use to determine how to escape
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +

Members

+ + + +

description :string

+ + + + + +
+ +
Description:
+
  • A short description of this escaper instance
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ A short description of this escaper instance +
+ + + +
Type:
+
    +
  • + +string + + + +
  • +
+ + + + + + + + +

name :string

+ + + + + +
+ +
Description:
+
  • The unique name of the escaper instance
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ The unique name of the escaper instance +
+ + + +
Type:
+
    +
  • + +string + + + +
  • +
+ + + + + + + + +

style :string

+ + + + + +
+ +
Description:
+
  • The style to use to determine how to escape
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ The style to use to determine how to escape +
+ + + +
Type:
+
    +
  • + +string + + + +
  • +
+ + + + + + + + + + +

Methods

+ + + + + + +

(abstract) escape(str) → {String}

+ + + + + + +
+ +
Description:
+
  • Escape the given string for the given style. The escaped string is what +the programming language would use in source code.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +String + + + + + the string to escape
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the escaped string +
+ + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + + + + + + +

getDescription() → {String}

+ + + + + + +
+ +
Description:
+
  • Get a short description of this escaper.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the description of this escaper +
+ + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + + + + + + +

getName() → {String}

+ + + + + + +
+ +
Description:
+
  • Get the name of this escaper.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the name of this escaper +
+ + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + + + + + + +

getStyle() → {Object}

+ + + + + + +
+ +
Description:
+
  • Get the style object for this escaper.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the style object for this escaper +
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + + + + + + +

(abstract) unescape(str) → {String}

+ + + + + + +
+ +
Description:
+
  • Unescape the given string for the given style. The unescaped +string is what the programming language would use in memory as it is running.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +String + + + + + the string to unescape
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the unescaped string +
+ + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/EscaperFactory.js.html b/packages/ilib-tools-common/docs/EscaperFactory.js.html new file mode 100644 index 000000000..c3b037d73 --- /dev/null +++ b/packages/ilib-tools-common/docs/EscaperFactory.js.html @@ -0,0 +1,220 @@ + + + + + + EscaperFactory.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

EscaperFactory.js

+ + + + + + + +
+
+
/*
+ * EscaperFactory.js - factory function that returns escaper instances
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import CSharpEscaper from "./escapes/CSharpEscaper.js";
+import JavaEscaper from "./escapes/JavaEscaper.js";
+import JavascriptEscaper from "./escapes/JavascriptEscaper.js";
+import JsonEscaper from "./escapes/JsonEscaper.js";
+import RegexBasedEscaper from "./escapes/RegexBasedEscaper.js";
+import PHPEscaper from "./escapes/PHPEscaper.js";
+import SmartyEscaper from "./escapes/SmartyEscaper.js";
+import PythonEscaper from "./escapes/PythonEscaper.js";
+import SwiftEscaper from "./escapes/SwiftEscaper.js";
+import URIEscaper from "./escapes/URIEscaper.js";
+
+const escaperCache = {};
+
+/**
+ * Return an Escaper instance for the given style. The style must be one of the
+ * following:
+ * <ul>
+ * <li>csharp - escape for C#</li>
+ * <li>csharp-raw - escape for C# raw strings</li>
+ * <li>csharp-verbatim - escape for C# verbatim strings</li>
+ * <li>java - escape for Java</li>
+ * <li>java-raw - escape for JSON raw strings</li>
+ * <li>js - escape for JavaScript</li>
+ * <li>javascript-template - escape for JavaScript template strings</li>
+ * <li>json - escape for JSON</li>
+ * <li>kotlin - escape for Kotlin</li>
+ * <li>kotlin-raw - escape for Kotlin raw strings</li>
+ * <li>php - escape for PHP (default, same as php-double)</li>
+ * <li>php-double - escape for double-quoted PHP strings</li>
+ * <li>php-single - escape for single-quoted PHP strings</li>
+ * <li>php-heredoc - escape for PHP heredoc strings</li>
+ * <li>php-nowdoc - escape for PHP nowdoc strings</li>
+ * <li>python - escape for Python regular strings (default)</li>
+ * <li>python-raw - escape for Python raw strings</li>
+ * <li>python-byte - escape for Python byte strings</li>
+ * <li>python-multi - escape for Python multi-line strings</li>
+ * <li>regexp - escape for regular expressions</li>
+ * <li>smarty - escape for Smarty templates (default, same as smarty-double)</li>
+ * <li>smarty-double - escape for double-quoted Smarty strings</li>
+ * <li>smarty-single - escape for single-quoted Smarty strings</li>
+ * <li>swift - escape for regular Swift strings</li>
+ * <li>swift-multi - escape for Swift multi-line strings</li>
+ * <li>swift-extended - escape for Swift extended strings</li>
+ * <li>uri - escape for URLs and URIs</li>
+ * <li>xml - escape for XML text, including HTML</li>
+ * <li>xml-attr - escape for XML attributes, including HTML</li>
+ * </ul>
+ * @param {string} style the style to use to determine how to escape
+ * @returns {Escaper} a new Escaper instance, or undefined if the style
+ * is not recognized
+ */
+function escaperFactory(style) {
+    if (style === "html") {
+        style = "xml";
+    }
+    if (escaperCache[style]) {
+        return escaperCache[style];
+    }
+    switch (style) {
+        case 'csharp':
+        case 'c#':
+        case 'csharp-raw':
+        case 'c#-raw':
+        case 'csharp-verbatim':
+        case 'c#-verbatim':
+            escaperCache[style] = new CSharpEscaper(style);
+            break;
+
+        case 'kotlin':
+        case 'kotlin-raw':
+        case 'java':
+        case 'java-raw':
+            escaperCache[style] = new JavaEscaper(style);
+            break;
+
+        case 'json':
+            escaperCache[style] = new JsonEscaper();
+            break;
+
+        case 'js':
+        case 'js-template':
+        case 'javascript':
+        case 'javascript-template':
+            escaperCache[style] = new JavascriptEscaper(style);
+            break;
+
+        case 'php':
+        case 'php-double':
+        case 'php-single':
+        case 'php-heredoc':
+        case 'php-nowdoc':
+            escaperCache[style] = new PHPEscaper(style);
+            break;
+
+        case 'smarty':
+        case 'smarty-double':
+        case 'smarty-single':
+            escaperCache[style] = new SmartyEscaper(style);
+            break;
+
+        case 'python':
+        case 'python-raw':
+        case 'python-byte':
+        case 'python-multi':
+            escaperCache[style] = new PythonEscaper(style);
+            break;
+
+        case 'swift':
+        case 'swift-multi':
+        case 'swift-extended':
+            escaperCache[style] = new SwiftEscaper(style);
+            break;
+
+        case 'uri':
+        case 'url':
+            escaperCache[style] = new URIEscaper(style);
+            break;
+
+        default:
+            try {
+                escaperCache[style] = new RegexBasedEscaper(style);
+            } catch (e) {
+                // if the style is not recognized, just return undefined
+                return undefined;
+            }
+            break;
+    }
+    return escaperCache[style];
+}
+
+export default escaperFactory;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/JavaEscaper.html b/packages/ilib-tools-common/docs/JavaEscaper.html new file mode 100644 index 000000000..209110e6f --- /dev/null +++ b/packages/ilib-tools-common/docs/JavaEscaper.html @@ -0,0 +1,450 @@ + + + + + + JavaEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

JavaEscaper

+ + + + + + + +
+ +
+ +

+ + JavaEscaper + +

+ +
Escaper for Java and Kotlin
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new JavaEscaper(style)

+ + + + + + +
+ +
Description:
+
  • Can support the following styles: +- java: single or double-quoted strings +- java-raw: raw strings like """foo""" +- kotlin: regular single or double-quoted strings +- kotlin-raw: Kotlin raw strings like """foo"""
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +string + + + + + the style to use for escaping
+ + + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+ if the style is not supported +
+
+
+
+
+
+ Type +
+
+ +Error + + + +
+
+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/JavascriptEscaper.html b/packages/ilib-tools-common/docs/JavascriptEscaper.html new file mode 100644 index 000000000..246f17123 --- /dev/null +++ b/packages/ilib-tools-common/docs/JavascriptEscaper.html @@ -0,0 +1,448 @@ + + + + + + JavascriptEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

JavascriptEscaper

+ + + + + + + +
+ +
+ +

+ + JavascriptEscaper + +

+ +
Escaper for JavaScript
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new JavascriptEscaper(style)

+ + + + + + +
+ +
Description:
+
  • Can support the following styles: +- js: single or double-quoted strings +- js-template: JS template strings like `foo`
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +string + + + + + the style to use for escaping
+ + + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+ if the style is not supported +
+
+
+
+
+
+ Type +
+
+ +Error + + + +
+
+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/JsonEscaper.html b/packages/ilib-tools-common/docs/JsonEscaper.html new file mode 100644 index 000000000..6d766c609 --- /dev/null +++ b/packages/ilib-tools-common/docs/JsonEscaper.html @@ -0,0 +1,363 @@ + + + + + + JsonEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

JsonEscaper

+ + + + + + + +
+ +
+ +

+ + JsonEscaper + +

+ +
Escaper for Java
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new JsonEscaper()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/Location.html b/packages/ilib-tools-common/docs/Location.html index b6306631f..ad9d535bc 100644 --- a/packages/ilib-tools-common/docs/Location.html +++ b/packages/ilib-tools-common/docs/Location.html @@ -29,7 +29,7 @@ @@ -457,7 +457,7 @@

getLocatio
- Documentation generated by JSDoc 4.0.4 on Fri Feb 14 2025 18:30:31 GMT+0100 (Central European Standard Time) using the docdash theme. + Documentation generated by JSDoc 4.0.4 on Mon Mar 03 2025 22:01:57 GMT-0800 (Pacific Standard Time) using the docdash theme.
diff --git a/packages/ilib-tools-common/docs/Location.js.html b/packages/ilib-tools-common/docs/Location.js.html index e1a525edb..5f2b15bfa 100644 --- a/packages/ilib-tools-common/docs/Location.js.html +++ b/packages/ilib-tools-common/docs/Location.js.html @@ -29,7 +29,7 @@ @@ -117,7 +117,7 @@

Location.js


diff --git a/packages/ilib-tools-common/docs/PHPEscaper.html b/packages/ilib-tools-common/docs/PHPEscaper.html new file mode 100644 index 000000000..198382444 --- /dev/null +++ b/packages/ilib-tools-common/docs/PHPEscaper.html @@ -0,0 +1,451 @@ + + + + + + PHPEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

PHPEscaper

+ + + + + + + +
+ +
+ +

+ + PHPEscaper + +

+ +
Escaper for PHP
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new PHPEscaper(style)

+ + + + + + +
+ +
Description:
+
  • Can support the following styles: +- php (default): double-quoted strings +- php-double: double-quoted strings +- php-single: single-quoted strings +- php-heredoc: heredoc strings +- php-nowdoc: nowdoc strings
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +string + + + + + the style to use for escaping
+ + + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+ if the style is not supported +
+
+
+
+
+
+ Type +
+
+ +Error + + + +
+
+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/PythonEscaper.html b/packages/ilib-tools-common/docs/PythonEscaper.html new file mode 100644 index 000000000..bec809e27 --- /dev/null +++ b/packages/ilib-tools-common/docs/PythonEscaper.html @@ -0,0 +1,450 @@ + + + + + + PythonEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

PythonEscaper

+ + + + + + + +
+ +
+ +

+ + PythonEscaper + +

+ +
Escaper for Python
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new PythonEscaper(style)

+ + + + + + +
+ +
Description:
+
  • Can support the following styles: +- python (default): single or double-quoted strings +- python-raw: python raw strings like r"foo" +- python-byte: python byte strings like b"foo" +- python-multi: python multi-line strings like """foo"""
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +string + + + + + the style to use for escaping
+ + + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+ if the style is not supported +
+
+
+
+
+
+ Type +
+
+ +Error + + + +
+
+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/RegexBasedEscaper.html b/packages/ilib-tools-common/docs/RegexBasedEscaper.html new file mode 100644 index 000000000..55ceb66d8 --- /dev/null +++ b/packages/ilib-tools-common/docs/RegexBasedEscaper.html @@ -0,0 +1,447 @@ + + + + + + RegexBasedEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

RegexBasedEscaper

+ + + + + + + +
+ +
+ +

+ + RegexBasedEscaper + +

+ +
Escaper for various string formats based on regular expressions.
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new RegexBasedEscaper(style)

+ + + + + + +
+ +
Description:
+
  • Create a new escaper instance that escapes and unescapes strings based +on regular expressions.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +string + + + + + the style to use to determine how to escape
+ + + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+ if the style is not supported +
+
+
+
+
+
+ Type +
+
+ +Error + + + +
+
+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/Resource.html b/packages/ilib-tools-common/docs/Resource.html index 1ba7674cd..4190569f9 100644 --- a/packages/ilib-tools-common/docs/Resource.html +++ b/packages/ilib-tools-common/docs/Resource.html @@ -29,7 +29,7 @@ @@ -4407,7 +4407,7 @@
Parameters:

diff --git a/packages/ilib-tools-common/docs/Resource.js.html b/packages/ilib-tools-common/docs/Resource.js.html index eb267f34d..2e2e55b59 100644 --- a/packages/ilib-tools-common/docs/Resource.js.html +++ b/packages/ilib-tools-common/docs/Resource.js.html @@ -29,7 +29,7 @@ @@ -597,7 +597,7 @@

Resource.js


diff --git a/packages/ilib-tools-common/docs/ResourceArray.html b/packages/ilib-tools-common/docs/ResourceArray.html index af0a4f57a..0a65d567b 100644 --- a/packages/ilib-tools-common/docs/ResourceArray.html +++ b/packages/ilib-tools-common/docs/ResourceArray.html @@ -29,7 +29,7 @@ @@ -2808,7 +2808,7 @@
Returns:

diff --git a/packages/ilib-tools-common/docs/ResourceArray.js.html b/packages/ilib-tools-common/docs/ResourceArray.js.html index 043039b06..ca31a0ae7 100644 --- a/packages/ilib-tools-common/docs/ResourceArray.js.html +++ b/packages/ilib-tools-common/docs/ResourceArray.js.html @@ -29,7 +29,7 @@ @@ -462,7 +462,7 @@

ResourceArray.js


diff --git a/packages/ilib-tools-common/docs/ResourceConvert.js.html b/packages/ilib-tools-common/docs/ResourceConvert.js.html index ea0c0d4c3..31e0f4d57 100644 --- a/packages/ilib-tools-common/docs/ResourceConvert.js.html +++ b/packages/ilib-tools-common/docs/ResourceConvert.js.html @@ -29,7 +29,7 @@ @@ -562,7 +562,7 @@

ResourceConvert.js


diff --git a/packages/ilib-tools-common/docs/ResourcePlural.html b/packages/ilib-tools-common/docs/ResourcePlural.html index d54b25fbd..f385b1bf2 100644 --- a/packages/ilib-tools-common/docs/ResourcePlural.html +++ b/packages/ilib-tools-common/docs/ResourcePlural.html @@ -29,7 +29,7 @@ @@ -3246,7 +3246,7 @@
Returns:

diff --git a/packages/ilib-tools-common/docs/ResourcePlural.js.html b/packages/ilib-tools-common/docs/ResourcePlural.js.html index 4be0e8b2e..6c79a7687 100644 --- a/packages/ilib-tools-common/docs/ResourcePlural.js.html +++ b/packages/ilib-tools-common/docs/ResourcePlural.js.html @@ -29,7 +29,7 @@ @@ -484,7 +484,7 @@

ResourcePlural.js


diff --git a/packages/ilib-tools-common/docs/ResourceString.html b/packages/ilib-tools-common/docs/ResourceString.html index f13fdeeee..b8bfab697 100644 --- a/packages/ilib-tools-common/docs/ResourceString.html +++ b/packages/ilib-tools-common/docs/ResourceString.html @@ -29,7 +29,7 @@ @@ -2215,7 +2215,7 @@
Returns:

diff --git a/packages/ilib-tools-common/docs/ResourceString.js.html b/packages/ilib-tools-common/docs/ResourceString.js.html index ef54614cc..edd2fcd0d 100644 --- a/packages/ilib-tools-common/docs/ResourceString.js.html +++ b/packages/ilib-tools-common/docs/ResourceString.js.html @@ -29,7 +29,7 @@ @@ -287,7 +287,7 @@

ResourceString.js


diff --git a/packages/ilib-tools-common/docs/ResourceXliff.html b/packages/ilib-tools-common/docs/ResourceXliff.html index b73faca06..744c9bedc 100644 --- a/packages/ilib-tools-common/docs/ResourceXliff.html +++ b/packages/ilib-tools-common/docs/ResourceXliff.html @@ -29,7 +29,7 @@ @@ -588,7 +588,7 @@
Returns:

diff --git a/packages/ilib-tools-common/docs/ResourceXliff.js.html b/packages/ilib-tools-common/docs/ResourceXliff.js.html index e5674775a..d93423ea7 100644 --- a/packages/ilib-tools-common/docs/ResourceXliff.js.html +++ b/packages/ilib-tools-common/docs/ResourceXliff.js.html @@ -29,7 +29,7 @@ @@ -533,7 +533,7 @@

ResourceXliff.js


diff --git a/packages/ilib-tools-common/docs/SmartyEscaper.html b/packages/ilib-tools-common/docs/SmartyEscaper.html new file mode 100644 index 000000000..e3a49059f --- /dev/null +++ b/packages/ilib-tools-common/docs/SmartyEscaper.html @@ -0,0 +1,449 @@ + + + + + + SmartyEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

SmartyEscaper

+ + + + + + + +
+ +
+ +

+ + SmartyEscaper + +

+ +
Escaper for Smarty
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new SmartyEscaper(style)

+ + + + + + +
+ +
Description:
+
  • Can support the following styles: +- smarty (default): double-quoted strings +- smarty-double: double-quoted strings +- smarty-single: single-quoted strings
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +string + + + + + the style to use for escaping
+ + + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+ if the style is not supported +
+
+
+
+
+
+ Type +
+
+ +Error + + + +
+
+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/SwiftEscaper.html b/packages/ilib-tools-common/docs/SwiftEscaper.html new file mode 100644 index 000000000..089feb60f --- /dev/null +++ b/packages/ilib-tools-common/docs/SwiftEscaper.html @@ -0,0 +1,449 @@ + + + + + + SwiftEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

SwiftEscaper

+ + + + + + + +
+ +
+ +

+ + SwiftEscaper + +

+ +
Escaper for Swift
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new SwiftEscaper(style)

+ + + + + + +
+ +
Description:
+
  • Can support the following styles: +- swift (default): single or double-quoted strings +- swift-multi: swift multi-line strings like """foo""" +- swift-extended: swift raw strings like #"foo"#
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +string + + + + + the style to use for escaping
+ + + + + + + + + + + + + + +
Throws:
+ + + +
+
+
+ if the style is not supported +
+
+
+
+
+
+ Type +
+
+ +Error + + + +
+
+
+
+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/TranslationSet.html b/packages/ilib-tools-common/docs/TranslationSet.html index a88a1c50b..16f097b6e 100644 --- a/packages/ilib-tools-common/docs/TranslationSet.html +++ b/packages/ilib-tools-common/docs/TranslationSet.html @@ -29,7 +29,7 @@ @@ -2678,7 +2678,7 @@
Returns:

diff --git a/packages/ilib-tools-common/docs/TranslationSet.js.html b/packages/ilib-tools-common/docs/TranslationSet.js.html index b7868e276..b022ca2f3 100644 --- a/packages/ilib-tools-common/docs/TranslationSet.js.html +++ b/packages/ilib-tools-common/docs/TranslationSet.js.html @@ -29,7 +29,7 @@ @@ -458,7 +458,7 @@

TranslationSet.js


diff --git a/packages/ilib-tools-common/docs/TranslationUnit.html b/packages/ilib-tools-common/docs/TranslationUnit.html index c16cd07a6..0500f0daa 100644 --- a/packages/ilib-tools-common/docs/TranslationUnit.html +++ b/packages/ilib-tools-common/docs/TranslationUnit.html @@ -29,7 +29,7 @@ @@ -1175,7 +1175,7 @@
Returns:

diff --git a/packages/ilib-tools-common/docs/TranslationUnit.js.html b/packages/ilib-tools-common/docs/TranslationUnit.js.html index 4d0438a23..162cf345f 100644 --- a/packages/ilib-tools-common/docs/TranslationUnit.js.html +++ b/packages/ilib-tools-common/docs/TranslationUnit.js.html @@ -29,7 +29,7 @@ @@ -245,7 +245,7 @@

TranslationUnit.js


diff --git a/packages/ilib-tools-common/docs/TranslationVariant.html b/packages/ilib-tools-common/docs/TranslationVariant.html index aef9107cc..cf7ee2809 100644 --- a/packages/ilib-tools-common/docs/TranslationVariant.html +++ b/packages/ilib-tools-common/docs/TranslationVariant.html @@ -29,7 +29,7 @@ @@ -350,7 +350,7 @@
Returns:

diff --git a/packages/ilib-tools-common/docs/TranslationVariant.js.html b/packages/ilib-tools-common/docs/TranslationVariant.js.html index d255ab594..2874b3acf 100644 --- a/packages/ilib-tools-common/docs/TranslationVariant.js.html +++ b/packages/ilib-tools-common/docs/TranslationVariant.js.html @@ -29,7 +29,7 @@ @@ -109,7 +109,7 @@

TranslationVariant.js


diff --git a/packages/ilib-tools-common/docs/URIEscaper.html b/packages/ilib-tools-common/docs/URIEscaper.html new file mode 100644 index 000000000..fbf0c155c --- /dev/null +++ b/packages/ilib-tools-common/docs/URIEscaper.html @@ -0,0 +1,366 @@ + + + + + + URIEscaper - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

URIEscaper

+ + + + + + + +
+ +
+ +

+ + URIEscaper + +

+ +
Escaper for URIs
+ + +
+ +
+ +
+ + + + +

Constructor

+ + +

new URIEscaper()

+ + + + + + +
+ +
Description:
+
  • Create a new escaper instance for URIs.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

escape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

unescape()

+ + + + + + +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/packages/ilib-tools-common/docs/escapes_CSharpEscaper.js.html b/packages/ilib-tools-common/docs/escapes_CSharpEscaper.js.html new file mode 100644 index 000000000..d23c037e7 --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_CSharpEscaper.js.html @@ -0,0 +1,174 @@ + + + + + + escapes/CSharpEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/CSharpEscaper.js

+ + + + + + + +
+
+
/*
+ * CSharpEscaper.js - class that escapes and unescapes strings in CSharp
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+import {
+    escapeRules,
+    escapeUnicode,
+    escapeUnicodeExtended,
+    escapeRegexes,
+    unescapeRules,
+    unescapeUnicode,
+    unescapeUnicodeExtended,
+    unescapeHex,
+    unindent
+} from './EscapeCommon.js';
+
+const validStyles = new Set([
+    "csharp",           // regular single or double-quoted strings
+    "csharp-raw",       // raw strings like """foo"""
+    "csharp-verbatim"   // verbatim strings like @"foo"
+]);
+
+const styleMap = {
+    "c#": "csharp",
+    "c#-raw": "csharp-raw",
+    "c#-verbatim": "csharp-verbatim"
+};
+
+/**
+ * @class Escaper for CSharp
+ */
+class CSharpEscaper extends Escaper {
+    /**
+     * Can support the following styles:
+     * - csharp (default): single or double-quoted strings
+     * - csharp-raw: csharp multi-line strings like """foo"""
+     * - csharp-verbatim: csharp raw strings like @"foo"
+     *
+     * @param {string} style the style to use for escaping
+     * @constructor
+     * @throws {Error} if the style is not supported
+     */
+    constructor(style) {
+        super(style);
+        const effectiveStyle = styleMap[style.toLowerCase()] ?? style;
+        if (!validStyles.has(effectiveStyle)) {
+            throw new Error(`invalid c# escape style ${style}`);
+        }
+        this.style = effectiveStyle;
+        this.name = "csharp-escaper";
+        this.description = "Escapes and unescapes various types of strings in C#";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        let escaped = string;
+
+        escaped = escapeRules(escaped, escapeRegexes[this.style]);
+        if (this.style === "csharp" || this.style === "csharp-raw") {
+            escaped = escapeUnicode(escaped);
+            escaped = escapeUnicodeExtended(escaped);
+        }
+        return escaped;
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        let unescaped = string;
+
+        if (this.style === "csharp-raw") {
+            unescaped = unindent(unescaped);
+        }
+        if (this.style === "csharp" || this.style === "csharp-raw") {
+            unescaped = unescapeUnicodeExtended(unescaped);
+            unescaped = unescapeUnicode(unescaped);
+            unescaped = unescapeHex(unescaped);
+        }
+        unescaped = unescapeRules(unescaped, escapeRegexes[this.style]);
+        return unescaped;
+    }
+}
+
+export default CSharpEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_EscapeCommon.js.html b/packages/ilib-tools-common/docs/escapes_EscapeCommon.js.html new file mode 100644 index 000000000..79e248463 --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_EscapeCommon.js.html @@ -0,0 +1,870 @@ + + + + + + escapes/EscapeCommon.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/EscapeCommon.js

+ + + + + + + +
+
+
/*
+ * JSCommon.js - common functions between JS and JSON that unescape strings
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import IString from 'ilib-istring';
+
+const reUnicodeChar = /\\u([a-fA-F0-9]{1,5})/g;
+const reUnicodeBracketedChar = /\\u\{([a-fA-F0-9]{1,5})\}/g;
+const reUnicodeExtendedChar = /\\U([a-fA-F0-9]{1,8})/g;
+const reHexadecimalChar = /\\x([a-fA-F0-9]{1,2})/g;
+const reOctalChar = /\\([0-7]{1,3})/g;
+
+/**
+ * Unescape a string that has sequences like \uXXXX
+ * @param {string} string the string to unescape
+ * @returns {string} the unescaped string
+ * @static
+ */
+export function unescapeUnicode(string) {
+    if (!string) {
+        return "";
+    }
+    let unescaped = string;
+    let match;
+
+    while ((match = reUnicodeChar.exec(unescaped))) {
+        if (match && match.length > 1) {
+            const value = parseInt(match[1], 16);
+            unescaped = unescaped.replace(match[0], IString.fromCodePoint(value));
+            reUnicodeChar.lastIndex = 0;
+        }
+    }
+
+    return unescaped;
+};
+
+/**
+ * Unescape a string that has sequences like \u{XXXXX}
+ * @param {string} string the string to unescape
+ * @returns {string} the unescaped string
+ * @static
+ */
+export function unescapeUnicodeWithBrackets(string) {
+    if (!string) {
+        return "";
+    }
+    let unescaped = string;
+    let match;
+
+    while ((match = reUnicodeBracketedChar.exec(unescaped))) {
+        if (match && match.length > 1) {
+            const value = parseInt(match[1], 16);
+            unescaped = unescaped.replace(match[0], IString.fromCodePoint(value));
+            reUnicodeBracketedChar.lastIndex = 0;
+        }
+    }
+
+    return unescaped;
+};
+
+/**
+ * Unescape a string that has sequences like \U000XXXXXX
+ * @param {string} string the string to unescape
+ * @returns {string} the unescaped string
+ * @static
+ */
+export function unescapeUnicodeExtended(string) {
+    if (!string) {
+        return "";
+    }
+    let unescaped = string;
+    let match;
+
+    while ((match = reUnicodeExtendedChar.exec(unescaped))) {
+        if (match && match.length > 1) {
+            const value = parseInt(match[1], 16);
+            unescaped = unescaped.replace(match[0], IString.fromCodePoint(value));
+            reUnicodeExtendedChar.lastIndex = 0;
+        }
+    }
+
+    return unescaped;
+};
+
+/**
+ * Unescape a string that has hexadecimal escape sequences in it
+ * of the form \xXX.
+ *
+ * @param {string} string the string to escape
+ * @returns {string} the escaped string
+ * @static
+ */
+export function unescapeHex(string) {
+    if (!string) {
+        return "";
+    }
+    let unescaped = string;
+    let match;
+
+    while ((match = reHexadecimalChar.exec(unescaped))) {
+        if (match && match.length > 1) {
+            const value = parseInt(match[1], 16);
+            unescaped = unescaped.replace(match[0], IString.fromCodePoint(value));
+            reHexadecimalChar.lastIndex = 0;
+        }
+    }
+
+    return unescaped;
+};
+
+/**
+ * Unescape a string that has octal escape sequences in it of the form \XXX.
+ *
+ * @param {string} string the string to escape
+ * @returns {string} the escaped string
+ * @static
+ */
+export function unescapeOctal(string) {
+    let unescaped = string;
+    let match;
+
+    while ((match = reOctalChar.exec(unescaped))) {
+        if (match && match.length > 1) {
+            const value = parseInt(match[1], 8);
+            unescaped = unescaped.replace(match[0], IString.fromCodePoint(value));
+            reOctalChar.lastIndex = 0;
+        }
+    }
+
+    return unescaped;
+};
+
+export const escapeRegexes = {
+    // from https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/
+    "csharp": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            "^\\\\'": "'",                   // unescape quotes
+            "([^\\\\])\\\\'": "$1'",
+            '^\\\\"': '"',
+            '([^\\\\])\\\\"': '$1"',
+            "\\\\0": "\x00",
+            "\\\\a": "\x07",
+            "\\\\b": "\x08",
+            "\\\\e": "\x1B",
+            "\\\\f": "\f",
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+            "\\\\v": "\v"
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+            '^"': '\\"',
+            '([^\\\\])"': '$1\\"',
+            "^'": "\\'",
+            "([^\\\\])'": "$1\\'",
+            "\x00": "\\0",
+            "\x07": "\\a",
+            "\x08": "\\b",
+            "\x1B": "\\e",
+            "\f": "\\f",
+            "\n": "\\n",
+            "\r": "\\r",
+            "\t": "\\t",
+            "\v": "\\v"
+        }
+    },
+    "csharp-verbatim": {
+        "unescape": {
+            '""': '"'                        // unescape quotes
+        },
+        "escape": {
+            '"': '""'                        // escape quotes
+        }
+    },
+    "csharp-raw": {
+        "unescape": {
+            // none
+        },
+        "escape": {
+            // none
+        }
+    },
+    "java": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            "^\\\\'": "'",                   // unescape quotes
+            "([^\\\\])\\\\'": "$1'",
+            '^\\\\"': '"',
+            '([^\\\\])\\\\"': '$1"',
+            "\\\\b": "\x08",
+            "\\\\f": "\f",
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t"
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+            '^"': '\\"',
+            '([^\\\\])"': '$1\\"',
+            "^'": "\\'",
+            "([^\\\\])'": "$1\\'",
+            "\x08": "\\b",
+            "\f": "\\f",
+            "\n": "\\n",
+            "\r": "\\r",
+            "\t": "\\t"
+        }
+    },
+    "java-raw": {
+        "unescape": {
+            "\\\\\\\\n": "",                 // line continuation
+            "\\\\\\n": ""                    // line continuation
+        },
+        "escape": {
+            // none
+        }
+    },
+    "js": {
+        "unescape": {
+            "\\\\\\\\n": "",                 // line continuation
+            "\\\\\\n": "",                   // line continuation
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",
+            "^\\\\'": "'",                   // unescape quotes
+            "([^\\\\])\\\\'": "$1'",
+            '^\\\\"': '"',
+            '([^\\\\])\\\\"': '$1"',
+            "\\\\0": "\0",
+            "\\\\b": "\b",
+            "\\\\f": "\f",
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+            "\\\\v": "\v"
+        },
+        "escape": {
+            "\\\\": "\\\\",
+            "'": "\\'",
+            '"': '\\"',
+            "\0": "\\0",
+            "\x08": "\\b",
+            "\f": "\\f",
+            "\n": "\\n",
+            "\r": "\\r",
+            "\t": "\\t",
+            "\v": "\\v",
+        }
+    },
+    "js-template": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",
+            "^\\\\'": "'",                   // unescape quotes
+            "([^\\\\])\\\\'": "$1'",
+            '^\\\\"': '"',
+            '([^\\\\])\\\\"': '$1"',
+            "\\\\0": "\0",
+            "\\\\b": "\b",
+            "\\\\f": "\f",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+            "\\\\v": "\v",
+            "\\\\`": "`"
+        },
+        "escape": {
+            "^\\\\\\\\": "\\\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\\\",
+            "\\0": "\\0",
+            "\x08": "\\b",
+            "\f": "\\f",
+            "\r": "\\r",
+            "\t": "\\t",
+            "\v": "\\v",
+            "`": "\\`"
+        }
+    },
+    "php-double": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            '^\\\\"': '"',                   // unescape double quotes only, not single
+            '([^\\\\])\\\\"': '$1"',         // unescape double quotes only, not single
+            "\\\\\\$": "$",
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+            "\\\\e": "\u001B",
+            "\\\\f": "\f",
+            "\\\\v": "\v"
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\\\",
+            '^"': '\\"',
+            '([^\\\\])"': '$1\\"',
+            "\\$": "\\$",
+            "\\n": "\\n",
+            "\\r": "\\r",
+            "\\t": "\\t",
+            "\u001B": "\\e",
+            "\\f": "\\f",
+            "\\v": "\\v"
+        }
+    },
+    "php-single": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            "^\\\\'": "'",                   // unescape quotes
+            "([^\\\\])\\\\'": "$1'"
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+            "'": "\\'"
+        }
+    },
+    "php-heredoc": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            "\\\\\\$": "$",
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+            "\\\\e": "\u001B",
+            "\\\\f": "\f",
+            "\\\\v": "\v"
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+            "\\$": "\\$",
+            "\\n": "\\n",
+            "\\r": "\\r",
+            "\\t": "\\t",
+            "\u001B": "\\e",
+            "\\f": "\\f",
+            "\\v": "\\v"
+        }
+    },
+    "php-nowdoc": { // no escaping or unescaping whatsoever!!!
+        "unescape": {
+        },
+        "escape": {
+        }
+    },
+    "python": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            "^\\\\'": "'",                   // unescape quotes
+            "([^\\\\])\\\\'": "$1'",
+            '^\\\\"': '"',
+            '([^\\\\])\\\\"': '$1"',
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+            "\\\\b": "\x08",
+            "\\\\f": "\f",
+            "\\\\v": "\v",
+            "\\\\a": "\x07"
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+            '^"': '\\"',
+            '([^\\\\])"': '$1\\"',
+            "^'": "\\'",
+            "([^\\\\])'": "$1\\'",
+            "\\n": "\\n",
+            "\\r": "\\r",
+            "\\t": "\\t",
+            "\x08": "\\b",
+            "\\f": "\\f",
+            "\\v": "\\v",
+            "\x07": "\\a"
+        }
+    },
+    "python-raw": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            "^\\\\'": "'",                   // unescape quotes
+            "([^\\\\])\\\\'": "$1'"
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+            "'": "\\'"
+        }
+    },
+    "python-byte": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            "^\\\\'": "'",                   // unescape quotes
+            "([^\\\\])\\\\'": "$1'"
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+            "'": "\\'"
+        }
+    },
+    "python-multi": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            '^\\\\"': '"',                   // unescape double quotes only, not single
+            '([^\\\\])\\\\"': '$1"',         // unescape double quotes only, not single
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+            "\\\\b": "\x08",
+            "\\\\f": "\f",
+            "\\\\v": "\v",
+            "\\\\a": "\x07"
+        },
+        "escape": {
+            "([^\\\\])\\\\": "$1\\\\",
+            '^"': '\\"',
+            '([^\\\\])"': '$1\\"',
+            "\\n": "\\n",
+            "\\r": "\\r",
+            "\\t": "\\t",
+            "\x08": "\\b",
+            "\\f": "\\f",
+            "\\v": "\\v",
+            "\x07": "\\a"
+         }
+    },
+    // from https://docs.swift.org/swift-book/documentation/the-swift-programming-language/stringsandcharacters
+    "swift": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            "^\\\\'": "'",                   // unescape single quotes
+            "([^\\\\])\\\\'": "$1'",
+            '^\\\\"': '"',                   // unescape double quotes
+            '([^\\\\])\\\\"': '$1"',
+            "\\\\0": "\x00",
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+            '^"': '\\"',
+            '([^\\\\])"': '$1\\"',
+            "^'": "\\'",
+            "([^\\\\])'": "$1\\'",
+            "\\x00": "\\0",
+            "\n": "\\n",
+            "\r": "\\r",
+            "\t": "\\t"
+        }
+    },
+    "swift-multi": {
+        "unescape": {
+            "^\\\\\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\\\\\": "$1\\",     // unescape backslashes
+            "^\\\\'": "'",                   // unescape single quotes
+            "([^\\\\])\\\\'": "$1'",
+            '^\\\\"': '"',                   // unescape double quotes
+            '([^\\\\])\\\\"': '$1"',
+            "\\\\0": "\x00",
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+            "\\\\\n": ""                     // remove line continuation
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+        }
+    },
+    "swift-extended": {
+        "unescape": {
+            "^\\\\#+\\\\": "\\",               // unescape backslashes
+            "([^\\\\])\\\\#+\\\\": "$1\\",     // unescape backslashes
+            "^\\\\#+'": "'",                   // unescape single quotes
+            "([^\\\\])\\\\#+'": "$1'",
+            '^\\\\#+"': '"',                   // unescape double quotes
+            '([^\\\\])\\\\#+"': '$1"',
+            "\\\\#+0": "\x00",
+            "\\\\#+n": "\n",
+            "\\\\#+r": "\r",
+            "\\\\#+t": "\t",
+            "\\\\#+\n": ""                     // remove line continuation
+        },
+        "escape": {
+            "^\\\\": "\\\\",
+            "([^\\\\])\\\\": "$1\\\\",
+        }
+    },
+    "xml": {
+        "unescape": {
+            "&lt;": "<",
+            "&gt;": ">",
+            "&quot;": "\"",
+            "&apos;": "'",
+            "&amp;": "&"
+        },
+        "escape": {
+            "&": "&amp;",
+            "<": "&lt;",
+            ">": "&gt;",
+            "\"": "&quot;",
+            "'": "&apos;"
+        }
+    },
+    "xml-attr": {
+        "unescape": {
+            "&lt;": "<",
+            "&gt;": ">",
+            "&quot;": "\"",
+            "&apos;": "'",
+            "&amp;": "&",
+            "\\\\n": "\n",
+            "\\\\r": "\r",
+            "\\\\t": "\t",
+            "\\\\b": "\x08",
+            "\\\\f": "\f",
+            "\\\\v": "\v"
+        },
+        "escape": {
+            "&": "&amp;",
+            "<": "&lt;",
+            ">": "&gt;",
+            "\"": "&quot;",
+            "'": "&apos;",
+            "\n": "\\n",
+            "\r": "\\r",
+            "\t": "\\t",
+            "\x08": "\\b",
+            "\f": "\\f",
+            "\v": "\\v"
+        }
+    }
+};
+
+/**
+ * Convert all code points above U+00FF and below U+10000
+ * to \uXXXX form.
+ *
+ * @param {string} string the string to unescape
+ * @returns {string} the unescaped string
+ * @static
+ */
+export function escapeUnicode(string) {
+    if (!string) {
+        return "";
+    }
+    let output = "";
+
+    for (const ch of string) {
+        const code = IString.toCodePoint(ch, 0);
+        if (code < 0x10000 && code > 0x00FF) {
+            const str = code.toString(16).toUpperCase();
+            output += "\\u" + str;
+        } else {
+            output += ch;
+        }
+    }
+
+    return output;
+}
+
+/**
+ * Convert all code points above U+FFFF to \uXXXXX form.
+ *
+ * @param {string} string the string to unescape
+ * @returns {string} the unescaped string
+ * @static
+ */
+export function escapeUnicodeAstral(string) {
+    if (!string) {
+        return "";
+    }
+    let output = "";
+
+    for (const ch of string) {
+        const code = IString.toCodePoint(ch, 0);
+        if (code > 0xFFFF) {
+            const str = code.toString(16).toUpperCase();
+            output += "\\u" + str;
+        } else {
+            output += ch;
+        }
+    }
+
+    return output;
+}
+
+/**
+ * Convert all code points above U+FFFF to \u{XXXXX} form
+ *
+ * @param {string} string the string to escape
+ * @returns {string} the escaped string
+ * @static
+ */
+export function escapeUnicodeWithBrackets(string) {
+    if (!string) {
+        return "";
+    }
+    let output = "";
+
+    for (const ch of string) {
+        const code = IString.toCodePoint(ch, 0);
+        if (code > 0x00FF) {
+            const str = code.toString(16).toUpperCase();
+            output += "\\u{" + str + "}";
+        } else {
+            output += ch;
+        }
+    }
+
+    return output;
+}
+
+/**
+ * Convert all code points above U+FFFF to \U000XXXXXX form
+ *
+ * @param {string} string the string to escape
+ * @returns {string} the escaped string
+ * @static
+ */
+export function escapeUnicodeExtended(string) {
+    if (!string) {
+        return "";
+    }
+    let output = "";
+
+    for (const ch of string) {
+        const code = IString.toCodePoint(ch, 0);
+        if (code > 0xFFFF) {
+            const str = code.toString(16).toUpperCase().padStart(8, "0");
+            output += `\\U${str}`;
+        } else {
+            output += ch;
+        }
+    }
+
+    return output;
+}
+
+/**
+ * Convert all code points above U+00FF as \uXXXX and
+ * all code points above U+FFFF as surrogate pairs in that
+ * same format.
+ *
+ * @param {string} string the string to escape
+ * @returns {string} the escaped string
+ * @static
+ */
+export function escapeUnicodeAsSurrogatePairs(string) {
+    if (!string) {
+        return "";
+    }
+    let output = "";
+
+    // access the original string character by character to get
+    // the surrogate pairs for code points above U+FFFF
+    for (let i = 0; i < string.length; i++) {
+        const ch = string[i];
+        const code = ch.charCodeAt(0);
+        if (code < 0x10000 && code > 0x00FF) {
+            const str = code.toString(16).toUpperCase();
+            output += "\\u" + str;
+        } else {
+            output += ch;
+        }
+    }
+    return output;
+}
+
+/**
+ * Escape a string so that it has hexadecimal escape sequences
+ * in it instead of the characters themselves. This function
+ * will only convert characters from U+0000 to U+001F. The rest
+ * of the characters will be left alone. If you have characters
+ * that are less than U+001F that have special escape sequences
+ * in the target programming language, you should escape them
+ * first before calling this function.
+ *
+ * @param {string} string the string to escape
+ * @returns {string} the escaped string
+ * @static
+ */
+export function escapeHex(string) {
+    if (!string) {
+        return "";
+    }
+    let output = "";
+    for (const ch of string) {
+        const code = IString.toCodePoint(ch, 0);
+        if (code < 0x20) {
+            output += `\\x${code.toString(16).padStart(2, "0")}`;
+        } else {
+            output += ch;
+        }
+    }
+    return output;
+}
+
+/**
+ * Escape a string according to the rules given.
+ * @param {string} string the string to escape
+ * @param {object} rules the rules to use for escaping
+ * @returns {string} the escaped string
+ */
+export function escapeRules(string, rules) {
+    if (!string) {
+        return "";
+    }
+    let escaped = string;
+    for (const [key, value] of Object.entries(rules.escape)) {
+        escaped = escaped.replace(new RegExp(key, "g"), value);
+    }
+    return escaped;
+}
+
+/**
+ * Unescape a string according to the rules given.
+ * @param {string} string the string to unescape
+ * @param {object} rules the rules to use for unescaping
+ * @returns {string} the unescaped string
+ */
+export function unescapeRules(string, rules) {
+    if (!string) {
+        return "";
+    }
+    let unescaped = string;
+    for (const [key, value] of Object.entries(rules.unescape)) {
+        unescaped = unescaped.replace(new RegExp(key, "g"), value);
+    }
+    return unescaped;
+}
+
+/**
+ * Remove leading whitespace from each line of a string.
+ * This is used for things like "raw" strings
+ * to remove the leading whitespace that is used to align
+ * and indent the contents of the string with the rest of
+ * the code.
+ *
+ * @param {string} string the string to unindent
+ * @returns {string} the unindented string
+ */
+export function unindent(string) {
+    if (!string) {
+        return "";
+    }
+    // Remove leading whitespace from each line
+    const lines = string.split('\n');
+    if (lines.length < 2) {
+        return string;
+    }
+    // Find the minimum indentation level amongst all lines, ignoring empty lines
+    // and lines that only contain whitespace, as that will give us the amount
+    // of indentation to remove from each line
+    const minIndent = Math.min(...lines.map(line => {
+        const indent = line.search(/\S/);
+        return indent > -1 ? indent : (line.length > 0 ? line.length : Number.MAX_SAFE_INTEGER);
+    }));
+    if (minIndent === Number.MAX_SAFE_INTEGER) {
+        // No indentation found, so return the original string
+        return string;
+    }
+    // Remove the minimum indentation from each line
+    const unindentedLines = lines.map(line => line.slice(minIndent));
+    return unindentedLines.join('\n');
+}
+
+
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_Escaper.js.html b/packages/ilib-tools-common/docs/escapes_Escaper.js.html new file mode 100644 index 000000000..643fc3737 --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_Escaper.js.html @@ -0,0 +1,175 @@ + + + + + + escapes/Escaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/Escaper.js

+ + + + + + + +
+
+
/*
+ * Escaper.js - class that escapes and unescapes strings
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * A class that escapes and unescapes strings.
+ * @abstract
+ */
+class Escaper {
+    /**
+     * The style to use to determine how to escape
+     * @type {string}
+     */
+    style;
+
+    /**
+     * The unique name of the escaper instance
+     * @type {string}
+     */
+    name;
+
+    /**
+     * A short description of this escaper instance
+     * @type {string}
+     */
+    description;
+
+    /**
+     * Create a new escaper instance.
+     * @param {Object} style the style object to use to determine how to escape
+     * @constructor
+     */
+    constructor(style) {
+        this.style = style;
+    }
+
+    /**
+     * Get the style object for this escaper.
+     *
+     * @returns {Object} the style object for this escaper
+     */
+    getStyle() {
+        return this.style;
+    }
+
+    /**
+     * Get the name of this escaper.
+     *
+     * @returns {String} the name of this escaper
+     */
+    getName() {
+        return this.name;
+    }
+
+    /**
+     * Get a short description of this escaper.
+     *
+     * @returns {String} the description of this escaper
+     */
+    getDescription() {
+        return this.description;
+    }
+
+    /**
+     * Escape the given string for the given style. The escaped string is what
+     * the programming language would use in source code.
+     *
+     * @abstract
+     * @param {String} str the string to escape
+     * @returns {String} the escaped string
+     */
+    escape(string) {
+        throw new Error("abstract method called");
+    }
+
+    /**
+     * Unescape the given string for the given style. The unescaped
+     * string is what the programming language would use in memory as it is running.
+     *
+     * @abstract
+     * @param {String} str the string to unescape
+     * @returns {String} the unescaped string
+     */
+    unescape(string) {
+        throw new Error("abstract method called");
+    }
+}
+
+export default Escaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_JavaEscaper.js.html b/packages/ilib-tools-common/docs/escapes_JavaEscaper.js.html new file mode 100644 index 000000000..fe2984578 --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_JavaEscaper.js.html @@ -0,0 +1,176 @@ + + + + + + escapes/JavaEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/JavaEscaper.js

+ + + + + + + +
+
+
/*
+ * JavaEscaper.js - class that escapes and unescapes strings in Java
+ * and Kotlin
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+import {
+    escapeUnicodeAsSurrogatePairs,
+    escapeRules,
+    unescapeUnicode,
+    unescapeRules,
+    escapeRegexes,
+    unindent
+} from './EscapeCommon.js';
+
+const validStyles = new Set([
+    "java",            // regular single or double-quoted strings
+    "java-raw",        // Java raw strings like """foo"""
+    "kotlin",          // regular single or double-quoted strings"
+    "kotlin-raw",      // Kotlin raw strings like """foo"""
+]);
+
+/**
+ * @class Escaper for Java and Kotlin
+ */
+class JavaEscaper extends Escaper {
+   /**
+    * Can support the following styles:
+    * - java: single or double-quoted strings
+    * - java-raw: raw strings like """foo"""
+    * - kotlin: regular single or double-quoted strings
+    * - kotlin-raw: Kotlin raw strings like """foo"""
+    *
+    * @param {string} style the style to use for escaping
+    * @constructor
+    * @throws {Error} if the style is not supported
+    */
+    constructor(style) {
+        super(style);
+        if (!validStyles.has(style)) {
+            throw new Error(`invalid java/kotlin escape style ${style}`);
+        }
+        this.name = "java-escaper";
+        this.description = "Escapes and unescapes strings in Java or Kotlin";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        let escaped = string;
+
+        if (this.style === "java" || this.style === "kotlin") {
+            // these share the same escape rules
+            escaped = escapeRules(escaped, escapeRegexes.java);
+            escaped = escapeUnicodeAsSurrogatePairs(escaped);
+        } else if (this.style === "java-raw") {
+            // java raw strings only support line continuation characters and Unicode
+            escaped = escapeRules(escaped, escapeRegexes["java-raw"]);
+            escaped = escapeUnicodeAsSurrogatePairs(escaped);
+        }
+
+        return escaped;
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        let unescaped = string;
+
+        if (this.style === "java-raw" || this.style === "kotlin-raw") {
+            unescaped = unindent(unescaped);
+        }
+
+        if (this.style === "java" || this.style === "kotlin") {
+            // these share the same escape rules
+            unescaped = unescapeRules(unescaped, escapeRegexes.java);
+            // unescapeUnicode does the whole range of Unicode
+            unescaped = unescapeUnicode(unescaped);
+        } else if (this.style === "java-raw") {
+            // java raw strings only support line continuation characters and Unicode
+            unescaped = unescapeRules(unescaped, escapeRegexes["java-raw"]);
+            unescaped = unescapeUnicode(unescaped);
+        }
+        return unescaped;
+    }
+}
+
+export default JavaEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_JavascriptEscaper.js.html b/packages/ilib-tools-common/docs/escapes_JavascriptEscaper.js.html new file mode 100644 index 000000000..44a1f6ddc --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_JavascriptEscaper.js.html @@ -0,0 +1,169 @@ + + + + + + escapes/JavascriptEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/JavascriptEscaper.js

+ + + + + + + +
+
+
/*
+ * JavascriptEscaper.js - class that escapes and unescapes strings in Java
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+import {
+    escapeHex,
+    escapeUnicode,
+    escapeUnicodeWithBrackets,
+    escapeRules,
+    escapeRegexes,
+    unescapeRules,
+    unescapeHex,
+    unescapeOctal,
+    unescapeUnicode,
+    unescapeUnicodeWithBrackets
+} from './EscapeCommon.js';
+
+const validStyles = new Set([
+    "js",                   // regular single or double-quoted strings
+    "js-template"           // JS template strings like `foo`
+]);
+
+/**
+ * @class Escaper for JavaScript
+ */
+class JavascriptEscaper extends Escaper {
+    /**
+     * Can support the following styles:
+     * - js: single or double-quoted strings
+     * - js-template: JS template strings like `foo`
+     *
+     * @param {string} style the style to use for escaping
+     * @constructor
+     * @throws {Error} if the style is not supported
+     */
+    constructor(style) {
+        super(style);
+        if (style === "javascript") {
+            this.style = "js";
+        } else if (style === "javascript-template") {
+            this.style = "js-template";
+        }
+        if (!validStyles.has(this.style)) {
+            throw new Error(`invalid escape style ${style}`);
+        }
+        this.name = "javascript-escaper";
+        this.description = "Escapes and unescapes strings in Javascript";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        let escaped = string;
+
+        escaped = escapeRules(escaped, escapeRegexes[this.style]);
+        escaped = escapeUnicode(escaped);
+        escaped = escapeUnicodeWithBrackets(escaped);
+        if (this.style === "js") {
+            escaped = escapeHex(escaped);
+        }
+
+        return escaped;
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        let unescaped = string;
+
+        unescaped = unescapeUnicode(unescaped);
+        unescaped = unescapeUnicodeWithBrackets(unescaped);
+        unescaped = unescapeHex(unescaped);
+        unescaped = unescapeOctal(unescaped);
+        unescaped = unescapeRules(unescaped, escapeRegexes[this.style]);
+
+        return unescaped;
+    }
+}
+
+export default JavascriptEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_JsonEscaper.js.html b/packages/ilib-tools-common/docs/escapes_JsonEscaper.js.html new file mode 100644 index 000000000..535f6389c --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_JsonEscaper.js.html @@ -0,0 +1,131 @@ + + + + + + escapes/JsonEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/JsonEscaper.js

+ + + + + + + +
+
+
/*
+ * JsonEscaper.js - class that escapes and unescapes strings in json files
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+import { unescapeUnicode,
+    escapeRegexes,
+    escapeRules,
+    unescapeRules
+} from './EscapeCommon.js';
+
+/**
+ * @class Escaper for Java
+ */
+class JsonEscaper extends Escaper {
+    /**
+     * @constructor
+     */
+    constructor() {
+        super("json");
+        this.name = "json-escaper";
+        this.description = "Escapes and unescapes strings in json files";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        return escapeRules(string, escapeRegexes.js);
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        let unescaped = string;
+
+        unescaped = unescapeUnicode(unescaped);
+        unescaped = unescapeRules(unescaped, escapeRegexes.js);
+
+        return unescaped;
+    }
+}
+
+export default JsonEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_PHPEscaper.js.html b/packages/ilib-tools-common/docs/escapes_PHPEscaper.js.html new file mode 100644 index 000000000..54febfb06 --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_PHPEscaper.js.html @@ -0,0 +1,168 @@ + + + + + + escapes/PHPEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/PHPEscaper.js

+ + + + + + + +
+
+
/*
+ * PHPEscaper.js - class that escapes and unescapes strings in PHP
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+import {
+    escapeHex,
+    escapeRules,
+    escapeRegexes,
+    escapeUnicodeWithBrackets,
+    unescapeRules,
+    unescapeHex,
+    unescapeUnicodeWithBrackets
+} from './EscapeCommon.js';
+
+const validStyles = new Set([
+    "php",           // defaults to double-quoted strings
+    "php-double",    // double-quoted strings (default)
+    "php-single",    // single-quoted strings
+    "php-heredoc",   // heredoc strings
+    "php-nowdoc"     // nowdoc strings
+]);
+
+/**
+ * @class Escaper for PHP
+ */
+class PHPEscaper extends Escaper {
+    /**
+     * Can support the following styles:
+     * - php (default): double-quoted strings
+     * - php-double: double-quoted strings
+     * - php-single: single-quoted strings
+     * - php-heredoc: heredoc strings
+     * - php-nowdoc: nowdoc strings
+     *
+     * @param {string} style the style to use for escaping
+     * @constructor
+     * @throws {Error} if the style is not supported
+     */
+    constructor(style) {
+        super(style);
+        if (!validStyles.has(style)) {
+            throw new Error(`invalid php escape style ${style}`);
+        }
+        if (this.style === "php") {
+            // use the double-quoted style by default
+            this.style = "php-double";
+        }
+        this.name = "php-escaper";
+        this.description = "Escapes and unescapes various types of strings in PHP";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        let escaped = string;
+
+        escaped = escapeRules(escaped, escapeRegexes[this.style]);
+        if (this.style === "php-double" || this.style === "php-heredoc") {
+            escaped = escapeHex(escaped);
+            escaped = escapeUnicodeWithBrackets(escaped);
+        }
+        return escaped;
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        let unescaped = string;
+
+        if (this.style === "php-double" || this.style === "php-heredoc") {
+            unescaped = unescapeUnicodeWithBrackets(unescaped);
+            unescaped = unescapeHex(unescaped);
+        }
+        unescaped = unescapeRules(unescaped, escapeRegexes[this.style]);
+        return unescaped;
+    }
+}
+
+export default PHPEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_PythonEscaper.js.html b/packages/ilib-tools-common/docs/escapes_PythonEscaper.js.html new file mode 100644 index 000000000..c5635ed89 --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_PythonEscaper.js.html @@ -0,0 +1,167 @@ + + + + + + escapes/PythonEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/PythonEscaper.js

+ + + + + + + +
+
+
/*
+ * PythonEscaper.js - class that escapes and unescapes strings in Python
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+import {
+    escapeUnicode,
+    escapeUnicodeExtended,
+    escapeHex,
+    escapeRules,
+    unescapeRules,
+    unescapeHex,
+    unescapeUnicode,
+    unescapeUnicodeExtended,
+    escapeRegexes
+} from './EscapeCommon.js';
+
+const validStyles = new Set([
+    "python",           // regular single or double-quoted strings
+    "python-raw",       // raw strings like r"foo"
+    "python-byte",      // byte strings like b"foo"
+    "python-multi"      // multi-line strings like """foo"""
+]);
+
+/**
+ * @class Escaper for Python
+ */
+class PythonEscaper extends Escaper {
+    /**
+     * Can support the following styles:
+     * - python (default): single or double-quoted strings
+     * - python-raw: python raw strings like r"foo"
+     * - python-byte: python byte strings like b"foo"
+     * - python-multi: python multi-line strings like """foo"""
+     *
+     * @param {string} style the style to use for escaping
+     * @constructor
+     * @throws {Error} if the style is not supported
+     */
+    constructor(style) {
+        super(style);
+        this.description = "Escapes and unescapes strings in Python";
+        if (!validStyles.has(style)) {
+            throw new Error(`invalid python escape style ${style}`);
+        }
+        this.name = "python-escaper";
+        this.description = "Escapes and unescapes various types of strings in Python";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        let escaped = string;
+
+        escaped = escapeRules(escaped, escapeRegexes[this.style]);
+        if (this.style === "python" || this.style === "python-multi") {
+            escaped = escapeHex(escaped);
+            escaped = escapeUnicode(escaped);
+            escaped = escapeUnicodeExtended(escaped);
+        }
+        return escaped;
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        let unescaped = string;
+
+        if (this.style === "python" || this.style === "python-multi") {
+            unescaped = unescapeUnicodeExtended(unescaped);
+            unescaped = unescapeUnicode(unescaped);
+            unescaped = unescapeHex(unescaped);
+        }
+        unescaped = unescapeRules(unescaped, escapeRegexes[this.style]);
+        return unescaped;
+    }
+}
+
+export default PythonEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_RegexBasedEscaper.js.html b/packages/ilib-tools-common/docs/escapes_RegexBasedEscaper.js.html new file mode 100644 index 000000000..3880ce2cc --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_RegexBasedEscaper.js.html @@ -0,0 +1,138 @@ + + + + + + escapes/RegexBasedEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/RegexBasedEscaper.js

+ + + + + + + +
+
+
/*
+ * RegexBasedEscaper.js - class that escapes and unescapes strings
+ * in various styles using regular expressions
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+import { escapeRegexes } from './EscapeCommon.js';
+
+/**
+ * @class Escaper for various string formats based on regular expressions.
+ */
+class RegexBasedEscaper extends Escaper {
+    /**
+     * Create a new escaper instance that escapes and unescapes strings based
+     * on regular expressions.
+     * @constructor
+     * @param {string} style the style to use to determine how to escape
+     * @throws {Error} if the style is not supported
+     */
+    constructor(style) {
+        super(style);
+        this.escapeMap = escapeRegexes[style];
+        if (!this.escapeMap) {
+            throw new Error(`No escape map for style ${style}`);
+        }
+        this.description = "Escapes and unescapes strings in various styles using regular expressions.";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        let escaped = string;
+        for (const [key, value] of Object.entries(this.escapeMap.escape)) {
+            escaped = escaped.replace(new RegExp(key, "g"), value);
+        }
+        return escaped;
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        let unescaped = string;
+        for (const [key, value] of Object.entries(this.escapeMap.unescape)) {
+            unescaped = unescaped.replace(new RegExp(key, "g"), value);
+        }
+        return unescaped;
+    }
+}
+
+export default RegexBasedEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_SmartyEscaper.js.html b/packages/ilib-tools-common/docs/escapes_SmartyEscaper.js.html new file mode 100644 index 000000000..c07c86be1 --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_SmartyEscaper.js.html @@ -0,0 +1,163 @@ + + + + + + escapes/SmartyEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/SmartyEscaper.js

+ + + + + + + +
+
+
/*
+ * SmartyEscaper.js - class that escapes and unescapes strings in Smarty
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+import {
+    escapeRules,
+    unescapeRules,
+    escapeRegexes
+} from './EscapeCommon.js';
+
+const validStyles = new Set([
+    "smarty",           // defaults to double-quoted strings
+    "smarty-double",    // double-quoted strings (default)
+    "smarty-single",    // single-quoted strings
+]);
+
+
+/**
+ * @class Escaper for Smarty
+ */
+class SmartyEscaper extends Escaper {
+    /**
+     * Can support the following styles:
+     * - smarty (default): double-quoted strings
+     * - smarty-double: double-quoted strings
+     * - smarty-single: single-quoted strings
+     *
+     * @param {string} style the style to use for escaping
+     * @constructor
+     * @throws {Error} if the style is not supported
+     */
+    constructor(style) {
+        super(style);
+        if (!validStyles.has(style)) {
+            throw new Error(`invalid smarty escape style ${style}`);
+        }
+        if (this.style === "smarty") {
+            // use the double-quoted style by default
+            this.style = "smarty-double";
+        }
+        // Smarty uses php underneath, so we can reuse the php rules
+        switch (this.style) {
+            default:
+            case 'smarty-double':
+                this.regexName = "php-double";
+                break;
+            case 'smarty-single':
+                this.regexName = "php-single";
+                break;
+        }
+        this.name = "smarty-escaper";
+        this.description = "Escapes and unescapes various types of strings in Smarty";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        let escaped = string;
+
+        escaped = escapeRules(escaped, escapeRegexes[this.regexName]);
+        return escaped;
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        let unescaped = string;
+
+        unescaped = unescapeRules(unescaped, escapeRegexes[this.regexName]);
+        return unescaped;
+    }
+}
+
+export default SmartyEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_SwiftEscaper.js.html b/packages/ilib-tools-common/docs/escapes_SwiftEscaper.js.html new file mode 100644 index 000000000..9e1e0dbe3 --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_SwiftEscaper.js.html @@ -0,0 +1,158 @@ + + + + + + escapes/SwiftEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/SwiftEscaper.js

+ + + + + + + +
+
+
/*
+ * SwiftEscaper.js - class that escapes and unescapes strings in Swift
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+import {
+    escapeRules,
+    escapeUnicodeWithBrackets,
+    unescapeRules,
+    unescapeUnicodeWithBrackets,
+    escapeRegexes,
+    unindent
+} from './EscapeCommon.js';
+
+const validStyles = new Set([
+    "swift",           // regular single or double-quoted strings
+    "swift-multi",     // multi-line strings like """foo"""
+    "swift-extended"   // extended strings like #"""foo"""#
+]);
+
+/**
+ * @class Escaper for Swift
+ */
+class SwiftEscaper extends Escaper {
+    /**
+     * Can support the following styles:
+     * - swift (default): single or double-quoted strings
+     * - swift-multi: swift multi-line strings like """foo"""
+     * - swift-extended: swift raw strings like #"foo"#
+     *
+     * @param {string} style the style to use for escaping
+     * @constructor
+     * @throws {Error} if the style is not supported
+     */
+    constructor(style) {
+        super(style);
+        if (!validStyles.has(style)) {
+            throw new Error(`invalid swift escape style ${style}`);
+        }
+        this.name = "swift-escaper";
+        this.description = "Escapes and unescapes various types of strings in Swift";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        let escaped = string;
+
+        escaped = escapeRules(escaped, escapeRegexes[this.style]);
+        if (this.style === "swift") {
+            escaped = escapeUnicodeWithBrackets(escaped);
+        }
+        return escaped;
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        let unescaped = string;
+
+        if (this.style === "swift-multi" || this.style === "swift-extended") {
+            unescaped = unindent(unescaped);
+        }
+        unescaped = unescapeUnicodeWithBrackets(unescaped);
+        unescaped = unescapeRules(unescaped, escapeRegexes[this.style]);
+        return unescaped;
+    }
+}
+
+export default SwiftEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/escapes_URIEscaper.js.html b/packages/ilib-tools-common/docs/escapes_URIEscaper.js.html new file mode 100644 index 000000000..d6024a207 --- /dev/null +++ b/packages/ilib-tools-common/docs/escapes_URIEscaper.js.html @@ -0,0 +1,124 @@ + + + + + + escapes/URIEscaper.js - Documentation + + + + + + + + + + + + + + + + + + + + +
+ +

escapes/URIEscaper.js

+ + + + + + + +
+
+
/*
+ * URIEscaper.js - class that escapes and unescapes strings in uri files
+ *
+ * Copyright © 2025 JEDLSoft
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Escaper from './Escaper.js';
+
+/**
+ * @class Escaper for URIs
+ */
+class URIEscaper extends Escaper {
+    /**
+     * Create a new escaper instance for URIs.
+     * @constructor
+     */
+    constructor() {
+        super("uri");
+        this.name = "uri-escaper";
+        this.description = "Escapes and unescapes strings in URIs and URLs";
+    }
+
+    /**
+     * @override
+     */
+    escape(string) {
+        // rely on nodejs to do the right thing
+        return encodeURI(string);
+    }
+
+    /**
+     * @override
+     */
+    unescape(string) {
+        // rely on nodejs to do the right thing
+        return decodeURI(string);
+    }
+}
+
+export default URIEscaper;
+
+
+ + + + + + +
+ +
+ + + + + + + + + + + diff --git a/packages/ilib-tools-common/docs/global.html b/packages/ilib-tools-common/docs/global.html index 64a66b431..7d80f28f2 100644 --- a/packages/ilib-tools-common/docs/global.html +++ b/packages/ilib-tools-common/docs/global.html @@ -29,7 +29,7 @@ @@ -1091,6 +1091,1336 @@
Returns:
+

escapeHex(string) → {string}

+ + + + + + +
+ +
Description:
+
  • Escape a string so that it has hexadecimal escape sequences +in it instead of the characters themselves. This function +will only convert characters from U+0000 to U+001F. The rest +of the characters will be left alone. If you have characters +that are less than U+001F that have special escape sequences +in the target programming language, you should escape them +first before calling this function.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
string + + +string + + + + + the string to escape
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the escaped string +
+ + + +
+
+ Type +
+
+ +string + + + +
+
+ + + + + + + + + + +

escapeRules(string, rules) → {string}

+ + + + + + +
+ +
Description:
+
  • Escape a string according to the rules given.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
string + + +string + + + + + the string to escape
rules + + +object + + + + + the rules to use for escaping
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the escaped string +
+ + + +
+
+ Type +
+
+ +string + + + +
+
+ + + + + + + + + + +

escapeUnicode(string) → {string}

+ + + + + + +
+ +
Description:
+
  • Convert all code points above U+00FF and below U+10000 +to \uXXXX form.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
string + + +string + + + + + the string to unescape
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the unescaped string +
+ + + +
+
+ Type +
+
+ +string + + + +
+
+ + + + + + + + + + +

escapeUnicodeAsSurrogatePairs(string) → {string}

+ + + + + + +
+ +
Description:
+
  • Convert all code points above U+00FF as \uXXXX and +all code points above U+FFFF as surrogate pairs in that +same format.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
string + + +string + + + + + the string to escape
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the escaped string +
+ + + +
+
+ Type +
+
+ +string + + + +
+
+ + + + + + + + + + +

escapeUnicodeAstral(string) → {string}

+ + + + + + +
+ +
Description:
+
  • Convert all code points above U+FFFF to \uXXXXX form.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
string + + +string + + + + + the string to unescape
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the unescaped string +
+ + + +
+
+ Type +
+
+ +string + + + +
+
+ + + + + + + + + + +

escapeUnicodeExtended(string) → {string}

+ + + + + + +
+ +
Description:
+
  • Convert all code points above U+FFFF to \U000XXXXXX form
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
string + + +string + + + + + the string to escape
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the escaped string +
+ + + +
+
+ Type +
+
+ +string + + + +
+
+ + + + + + + + + + +

escapeUnicodeWithBrackets(string) → {string}

+ + + + + + +
+ +
Description:
+
  • Convert all code points above U+FFFF to \u{XXXXX} form
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
string + + +string + + + + + the string to escape
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the escaped string +
+ + + +
+
+ Type +
+
+ +string + + + +
+
+ + + + + + + + + + +

escaperFactory(style) → {Escaper}

+ + + + + + +
+ +
Description:
+
  • Return an Escaper instance for the given style. The style must be one of the +following: +
      +
    • csharp - escape for C#
    • +
    • csharp-raw - escape for C# raw strings
    • +
    • csharp-verbatim - escape for C# verbatim strings
    • +
    • java - escape for Java
    • +
    • java-raw - escape for JSON raw strings
    • +
    • js - escape for JavaScript
    • +
    • javascript-template - escape for JavaScript template strings
    • +
    • json - escape for JSON
    • +
    • kotlin - escape for Kotlin
    • +
    • kotlin-raw - escape for Kotlin raw strings
    • +
    • php - escape for PHP (default, same as php-double)
    • +
    • php-double - escape for double-quoted PHP strings
    • +
    • php-single - escape for single-quoted PHP strings
    • +
    • php-heredoc - escape for PHP heredoc strings
    • +
    • php-nowdoc - escape for PHP nowdoc strings
    • +
    • python - escape for Python regular strings (default)
    • +
    • python-raw - escape for Python raw strings
    • +
    • python-byte - escape for Python byte strings
    • +
    • python-multi - escape for Python multi-line strings
    • +
    • regexp - escape for regular expressions
    • +
    • smarty - escape for Smarty templates (default, same as smarty-double)
    • +
    • smarty-double - escape for double-quoted Smarty strings
    • +
    • smarty-single - escape for single-quoted Smarty strings
    • +
    • swift - escape for regular Swift strings
    • +
    • swift-multi - escape for Swift multi-line strings
    • +
    • swift-extended - escape for Swift extended strings
    • +
    • uri - escape for URLs and URIs
    • +
    • xml - escape for XML text, including HTML
    • +
    • xml-attr - escape for XML attributes, including HTML
    • +
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
style + + +string + + + + + the style to use to determine how to escape
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ a new Escaper instance, or undefined if the style +is not recognized +
+ + + +
+
+ Type +
+
+ +Escaper + + + +
+
+ + + + + + + + + +

formatPath(template, parameters) → {string}

@@ -1101,51 +2431,1103 @@

formatPath<
Description:
-
  • Format a file path using a path template and parameters. +
    • Format a file path using a path template and parameters. + +This function is used to generate an output file path for a given +source file path and a locale specifier. +The template replaces strings in square brackets with special values, +and keeps any characters intact that are not in square brackets. +This function recognizes and replaces the following strings in +templates: +- [dir] the original directory where the source file + came from. This is given as a directory that is relative + to the root of the project. eg. "foo/bar/strings.json" -> "foo/bar" +- [filename] the file name of the source file. + eg. "foo/bar/strings.json" -> "strings.json" +- [basename] the basename of the source file without any extension + eg. "foo/bar/strings.json" -> "strings" +- [extension] the extension part of the file name of the source file. + etc. "foo/bar/strings.json" -> "json" +- [locale] the full BCP-47 locale specification for the target locale + eg. "zh-Hans-CN" -> "zh-Hans-CN" +- [language] the language portion of the full locale + eg. "zh-Hans-CN" -> "zh" +- [script] the script portion of the full locale + eg. "zh-Hans-CN" -> "Hans" +- [region] the region portion of the full locale + eg. "zh-Hans-CN" -> "CN" +- [localeDir] the full locale where each portion of the locale + is a directory in this order: [langage], [script], [region]. + eg, "zh-Hans-CN" -> "zh/Hans/CN", but "en" -> "en". +- [localeUnder] the full BCP-47 locale specification, but using + underscores to separate the locale parts instead of dashes. + eg. "zh-Hans-CN" -> "zh_Hans_CN" +- [localeLower] the full BCP-47 locale specification, but makes + all locale parts lowercased. + eg. "zh-Hans-CN" -> "zh-hans-cn" + +The parameters may include the following: +- sourcepath - the path to the source file, relative to the root of + the project +- locale - the locale for the output file path
    + + + +
    Source:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +

Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
template + + +string + + + + + the string to escape
parameters + + +Object + + + + + the parameters to format into the template
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the formatted file path +
+ + + +
+
+ Type +
+
+ +string + + + +
+
+ + + + + + + + + + +

getLocaleFromPath(template, pathname) → {String}

+ + + + + + +
+ +
Description:
+
  • Return a locale encoded in the path using template to parse that path. +See {#formatPath} for the full description of the syntax of the template.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
template + + +String + + + + + template for the output file
pathname + + +String + + + + + path to the source file
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the locale within the path, or undefined if no locale found +
+ + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + + + + + + +

hashKey(source) → {String}

+ + + + + + +
+ +
Description:
+
  • Return a standard hash of the given source string.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
source + + +String + + + + + the source string as extracted from the +source code, unmodified
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the hash key +
+ + + +
+
+ Type +
+
+ +String + + + +
+
+ + + + + + + + + + +

isEmpty(obj) → {Boolean}

+ + + + + + +
+ +
Description:
+
  • Is an empty object or not
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + + object to test
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ true if there are no properties, false otherwise +
+ + + +
+
+ Type +
+
+ +Boolean + + + +
+
+ + + + + + + + + + +

objectMap(object, visitor) → {*}

+ + + + + + +
+ +
Description:
+
  • Recursively visit every node in an object and call the visitor on any +primitive values.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
object + + +* + + + + + any object, arrary, or primitive
visitor + + +function + + + + + function to call on any primitive
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the same type as the original object, but with every +primitive processed by the visitor function +
+ + + +
+
+ Type +
+
+ +* + + + +
+
+ + + + + + + + + + +

parsePath(template, pathname) → {Object}

+ + + + + + +
+ +
Description:
+
  • Parse a path according to the given template, and return the parts. +The parts can be any of the fields mentioned in the formatPath +documentation. If any field is not parsed, the result is an empty object
+ -This function is used to generate an output file path for a given -source file path and a locale specifier. -The template replaces strings in square brackets with special values, -and keeps any characters intact that are not in square brackets. -This function recognizes and replaces the following strings in -templates: -- [dir] the original directory where the source file - came from. This is given as a directory that is relative - to the root of the project. eg. "foo/bar/strings.json" -> "foo/bar" -- [filename] the file name of the source file. - eg. "foo/bar/strings.json" -> "strings.json" -- [basename] the basename of the source file without any extension - eg. "foo/bar/strings.json" -> "strings" -- [extension] the extension part of the file name of the source file. - etc. "foo/bar/strings.json" -> "json" -- [locale] the full BCP-47 locale specification for the target locale - eg. "zh-Hans-CN" -> "zh-Hans-CN" -- [language] the language portion of the full locale - eg. "zh-Hans-CN" -> "zh" -- [script] the script portion of the full locale - eg. "zh-Hans-CN" -> "Hans" -- [region] the region portion of the full locale - eg. "zh-Hans-CN" -> "CN" -- [localeDir] the full locale where each portion of the locale - is a directory in this order: [langage], [script], [region]. - eg, "zh-Hans-CN" -> "zh/Hans/CN", but "en" -> "en". -- [localeUnder] the full BCP-47 locale specification, but using - underscores to separate the locale parts instead of dashes. - eg. "zh-Hans-CN" -> "zh_Hans_CN" -- [localeLower] the full BCP-47 locale specification, but makes - all locale parts lowercased. - eg. "zh-Hans-CN" -> "zh-hans-cn" + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
template + + +String + + + + + the ilib template for matching against the path
pathname + + +String + + + + + the path name to match against the template
+ + + + + + + + + + + + + + + + +
Returns:
+ + +
+ an object mapping the fields to their values in the +the pathname +
+ + + +
+
+ Type +
+
+ +Object + + + +
+
+ + + + + + + + + + +

unescapeHex(string) → {string}

+ + -The parameters may include the following: -- sourcepath - the path to the source file, relative to the root of - the project -- locale - the locale for the output file path + + + +
+ +
Description:
+
  • Unescape a string that has hexadecimal escape sequences in it +of the form \xXX.
Source:
@@ -1217,7 +3599,7 @@
Parameters:
- template + string @@ -1238,16 +3620,150 @@
Parameters:
+ + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+ the escaped string +
+ + + +
+
+ Type +
+
+ +string + + + +
+
+ + + + + + + + + + +

unescapeOctal(string) → {string}

+ + + + + + +
+ +
Description:
+
  • Unescape a string that has octal escape sequences in it of the form \XXX.
+ + + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + - + + @@ -1284,7 +3800,7 @@
Returns:
- the formatted file path + the escaped string
@@ -1311,7 +3827,7 @@
Returns:
-

getLocaleFromPath(template, pathname) → {String}

+

unescapeRules(string, rules) → {string}

@@ -1321,14 +3837,13 @@

getL
Description:
-
  • Return a locale encoded in the path using template to parse that path. -See {#formatPath} for the full description of the syntax of the template.
+
  • Unescape a string according to the rules given.
Source:
@@ -1400,13 +3915,13 @@
Parameters:

- + + - + + @@ -1467,7 +3982,7 @@
Returns:
- the locale within the path, or undefined if no locale found + the unescaped string
@@ -1478,7 +3993,7 @@
Returns:
-String +string @@ -1494,7 +4009,7 @@
Returns:
-

hashKey(source) → {String}

+

unescapeUnicode(string) → {string}

@@ -1504,13 +4019,13 @@

hashKey
Description:
-
  • Return a standard hash of the given source string.
+
  • Unescape a string that has sequences like \uXXXX
Source:
@@ -1582,13 +4097,13 @@
Parameters:

- + + @@ -1626,7 +4140,7 @@
Returns:
- the hash key + the unescaped string
@@ -1637,7 +4151,7 @@
Returns:
-String +string @@ -1653,7 +4167,7 @@
Returns:
-

isEmpty(obj) → {Boolean}

+

unescapeUnicodeExtended(string) → {string}

@@ -1663,13 +4177,13 @@

isEmpty
Description:
-
  • Is an empty object or not
+
  • Unescape a string that has sequences like \U000XXXXXX
Source:
@@ -1741,13 +4255,13 @@
Parameters:

- + + @@ -1784,7 +4298,7 @@
Returns:
- true if there are no properties, false otherwise + the unescaped string
@@ -1795,7 +4309,7 @@
Returns:
-Boolean +string @@ -1811,7 +4325,7 @@
Returns:
-

objectMap(object, visitor) → {*}

+

unescapeUnicodeWithBrackets(string) → {string}

@@ -1821,14 +4335,13 @@

objectMap
Description:
-
  • Recursively visit every node in an object and call the visitor on any -primitive values.
+
  • Unescape a string that has sequences like \u{XXXXX}
Source:
@@ -1900,37 +4413,13 @@
Parameters:

- - - - - - - - - - - - - - - - - + + @@ -1967,8 +4456,7 @@
Returns:
- the same type as the original object, but with every -primitive processed by the visitor function + the unescaped string
@@ -1979,7 +4467,7 @@
Returns:
-* +string @@ -1995,7 +4483,7 @@
Returns:
-

parsePath(template, pathname) → {Object}

+

unindent(string) → {string}

@@ -2005,15 +4493,17 @@

parsePath
Description:
-
  • Parse a path according to the given template, and return the parts. -The parts can be any of the fields mentioned in the formatPath -documentation. If any field is not parsed, the result is an empty object
+
  • Remove leading whitespace from each line of a string. +This is used for things like "raw" strings +to remove the leading whitespace that is used to align +and indent the contents of the string with the rest of +the code.
Source:
@@ -2085,37 +4575,13 @@
Parameters:

- - - - - - - - - - - - - - - - - + + @@ -2152,8 +4618,7 @@
Returns:
- an object mapping the fields to their values in the -the pathname + the unindented string
@@ -2164,7 +4629,7 @@
Returns:
-Object +string @@ -2448,7 +4913,7 @@
Returns:

- Documentation generated by JSDoc 4.0.4 on Fri Feb 14 2025 18:30:31 GMT+0100 (Central European Standard Time) using the docdash theme. + Documentation generated by JSDoc 4.0.4 on Mon Mar 03 2025 22:01:57 GMT-0800 (Pacific Standard Time) using the docdash theme.
diff --git a/packages/ilib-tools-common/docs/ilibToolsCommon.md b/packages/ilib-tools-common/docs/ilibToolsCommon.md index 8f844b0de..4d67db027 100644 --- a/packages/ilib-tools-common/docs/ilibToolsCommon.md +++ b/packages/ilib-tools-common/docs/ilibToolsCommon.md @@ -38,6 +38,39 @@ phrase in the source language, depending on the context.

TranslationVariant

A class that represents a translation unit variant.

+
CSharpEscaper
+

Escaper for CSharp

+
+
Escaper
+

A class that escapes and unescapes strings.

+
+
JavaEscaper
+

Escaper for Java and Kotlin

+
+
JavascriptEscaper
+

Escaper for JavaScript

+
+
JsonEscaper
+

Escaper for Java

+
+
PHPEscaper
+

Escaper for PHP

+
+
PythonEscaper
+

Escaper for Python

+
+
RegexBasedEscaper
+

Escaper for various string formats based on regular expressions.

+
+
SmartyEscaper
+

Escaper for Smarty

+
+
SwiftEscaper
+

Escaper for Swift

+
+
URIEscaper
+

Escaper for URIs

+
## Constants @@ -112,6 +145,40 @@ still want to include the "config.json" file.

property that contains an array of the children of that directory. The path property is the full path to the file or directory relative to the root directory.

+
escaperFactory(style)Escaper
+

Return an Escaper instance for the given style. The style must be one of the +following:

+
    +
  • csharp - escape for C#
  • +
  • csharp-raw - escape for C# raw strings
  • +
  • csharp-verbatim - escape for C# verbatim strings
  • +
  • java - escape for Java
  • +
  • java-raw - escape for JSON raw strings
  • +
  • js - escape for JavaScript
  • +
  • javascript-template - escape for JavaScript template strings
  • +
  • json - escape for JSON
  • +
  • kotlin - escape for Kotlin
  • +
  • kotlin-raw - escape for Kotlin raw strings
  • +
  • php - escape for PHP (default, same as php-double)
  • +
  • php-double - escape for double-quoted PHP strings
  • +
  • php-single - escape for single-quoted PHP strings
  • +
  • php-heredoc - escape for PHP heredoc strings
  • +
  • php-nowdoc - escape for PHP nowdoc strings
  • +
  • python - escape for Python regular strings (default)
  • +
  • python-raw - escape for Python raw strings
  • +
  • python-byte - escape for Python byte strings
  • +
  • python-multi - escape for Python multi-line strings
  • +
  • regexp - escape for regular expressions
  • +
  • smarty - escape for Smarty templates (default, same as smarty-double)
  • +
  • smarty-double - escape for double-quoted Smarty strings
  • +
  • smarty-single - escape for single-quoted Smarty strings
  • +
  • swift - escape for regular Swift strings
  • +
  • swift-multi - escape for Swift multi-line strings
  • +
  • swift-extended - escape for Swift extended strings
  • +
  • uri - escape for URLs and URIs
  • +
  • xml - escape for XML text, including HTML
  • +
  • xml-attr - escape for XML attributes, including HTML
  • +
convertPluralResToICU(resource)ResourceString | undefined

Convert a plural resource to an ICU-style plural string resource. This allows for shoe-horning plurals into systems that do not @@ -130,6 +197,62 @@ parameter into the returned resource plural unchanged. The complement function is convertPluralResToICU() which does the opposite.

+
unescapeUnicode(string)string
+

Unescape a string that has sequences like \uXXXX

+
+
unescapeUnicodeWithBrackets(string)string
+

Unescape a string that has sequences like \u{XXXXX}

+
+
unescapeUnicodeExtended(string)string
+

Unescape a string that has sequences like \U000XXXXXX

+
+
unescapeHex(string)string
+

Unescape a string that has hexadecimal escape sequences in it +of the form \xXX.

+
+
unescapeOctal(string)string
+

Unescape a string that has octal escape sequences in it of the form \XXX.

+
+
escapeUnicode(string)string
+

Convert all code points above U+00FF and below U+10000 +to \uXXXX form.

+
+
escapeUnicodeAstral(string)string
+

Convert all code points above U+FFFF to \uXXXXX form.

+
+
escapeUnicodeWithBrackets(string)string
+

Convert all code points above U+FFFF to \u{XXXXX} form

+
+
escapeUnicodeExtended(string)string
+

Convert all code points above U+FFFF to \U000XXXXXX form

+
+
escapeUnicodeAsSurrogatePairs(string)string
+

Convert all code points above U+00FF as \uXXXX and +all code points above U+FFFF as surrogate pairs in that +same format.

+
+
escapeHex(string)string
+

Escape a string so that it has hexadecimal escape sequences +in it instead of the characters themselves. This function +will only convert characters from U+0000 to U+001F. The rest +of the characters will be left alone. If you have characters +that are less than U+001F that have special escape sequences +in the target programming language, you should escape them +first before calling this function.

+
+
escapeRules(string, rules)string
+

Escape a string according to the rules given.

+
+
unescapeRules(string, rules)string
+

Unescape a string according to the rules given.

+
+
unindent(string)string
+

Remove leading whitespace from each line of a string. +This is used for things like "raw" strings +to remove the leading whitespace that is used to align +and indent the contents of the string with the rest of +the code.

+
cleanString(str)String

Clean a string for matching against other strings by removing differences that are inconsequential for translation.

@@ -895,7 +1018,7 @@ Set the array of target strings for this resource. ### ~~resourceArray.getSourceArray() ⇒ Array.<String>~~ -***Use getSource() instead*** +***Deprecated*** Return the array of source strings. This method is here for backwards compatilibity with the loctool plugins. @@ -908,7 +1031,7 @@ for backwards compatilibity with the loctool plugins. ### ~~resourceArray.getTargetArray() ⇒ Array.<String>~~ -***Use getTarget() instead*** +***Deprecated*** Return the array of target strings. This method is here for backwards compatilibity with the loctool plugins. @@ -1219,7 +1342,7 @@ Set the source plurals hash of this plurals resource. ### ~~resourcePlural.getSourcePlurals() ⇒ Array.<String>~~ -***Use getSource() instead*** +***Deprecated*** Return the array of source strings. This method is here for backwards compatilibity with the loctool plugins. @@ -1232,7 +1355,7 @@ for backwards compatilibity with the loctool plugins. ### ~~resourcePlural.getTargetPlurals() ⇒ Array.<String>~~ -***Use getTarget() instead*** +***Deprecated*** Return the array of target strings. This method is here for backwards compatilibity with the loctool plugins. @@ -1245,7 +1368,7 @@ for backwards compatilibity with the loctool plugins. ### ~~resourcePlural.getSourceStrings() ⇒ Array.<String>~~ -***Use getSource() instead*** +***Deprecated*** Return the array of source strings. This method is here for backwards compatilibity with the loctool plugins. @@ -1258,7 +1381,7 @@ for backwards compatilibity with the loctool plugins. ### ~~resourcePlural.getTargetStrings() ⇒ Array.<String>~~ -***Use getTarget() instead*** +***Deprecated*** Return the array of target strings. This method is here for backwards compatilibity with the loctool plugins. @@ -1307,7 +1430,7 @@ plural category ### ~~resourcePlural.getClasses() ⇒ Array.<string>~~ -***Use getCategories instead*** +***Deprecated*** Return an array of names of source categories of plurals that are used in this resource. @@ -2343,6 +2466,587 @@ hash key is calculated from the source string and locale. * * * + + +## CSharpEscaper +Escaper for CSharp + +**Kind**: global class + +* [CSharpEscaper](#CSharpEscaper) + * [new CSharpEscaper(style)](#new_CSharpEscaper_new) + * [.escape()](#CSharpEscaper+escape) + * [.unescape()](#CSharpEscaper+unescape) + + +* * * + + + +### new CSharpEscaper(style) +Can support the following styles: +- csharp (default): single or double-quoted strings +- csharp-raw: csharp multi-line strings like """foo""" +- csharp-verbatim: csharp raw strings like @"foo" + +**Throws**: + +- Error if the style is not supported + + +| Param | Type | Description | +| --- | --- | --- | +| style | string | the style to use for escaping | + + +* * * + + + +### cSharpEscaper.escape() +**Kind**: instance method of [CSharpEscaper](#CSharpEscaper) + +* * * + + + +### cSharpEscaper.unescape() +**Kind**: instance method of [CSharpEscaper](#CSharpEscaper) + +* * * + + + +## *Escaper* +A class that escapes and unescapes strings. + +**Kind**: global abstract class + +* *[Escaper](#Escaper)* + * *[new Escaper(style)](#new_Escaper_new)* + * *[.style](#Escaper+style) : string* + * *[.name](#Escaper+name) : string* + * *[.description](#Escaper+description) : string* + * *[.getStyle()](#Escaper+getStyle) ⇒ Object* + * *[.getName()](#Escaper+getName) ⇒ String* + * *[.getDescription()](#Escaper+getDescription) ⇒ String* + * **[.escape(str)](#Escaper+escape) ⇒ String** + * **[.unescape(str)](#Escaper+unescape) ⇒ String** + + +* * * + + + +### *new Escaper(style)* +Create a new escaper instance. + + +| Param | Type | Description | +| --- | --- | --- | +| style | Object | the style object to use to determine how to escape | + + +* * * + + + +### *escaper.style : string* +The style to use to determine how to escape + +**Kind**: instance property of [Escaper](#Escaper) + +* * * + + + +### *escaper.name : string* +The unique name of the escaper instance + +**Kind**: instance property of [Escaper](#Escaper) + +* * * + + + +### *escaper.description : string* +A short description of this escaper instance + +**Kind**: instance property of [Escaper](#Escaper) + +* * * + + + +### *escaper.getStyle() ⇒ Object* +Get the style object for this escaper. + +**Kind**: instance method of [Escaper](#Escaper) +**Returns**: Object - the style object for this escaper + +* * * + + + +### *escaper.getName() ⇒ String* +Get the name of this escaper. + +**Kind**: instance method of [Escaper](#Escaper) +**Returns**: String - the name of this escaper + +* * * + + + +### *escaper.getDescription() ⇒ String* +Get a short description of this escaper. + +**Kind**: instance method of [Escaper](#Escaper) +**Returns**: String - the description of this escaper + +* * * + + + +### **escaper.escape(str) ⇒ String** +Escape the given string for the given style. The escaped string is what +the programming language would use in source code. + +**Kind**: instance abstract method of [Escaper](#Escaper) +**Returns**: String - the escaped string + +| Param | Type | Description | +| --- | --- | --- | +| str | String | the string to escape | + + +* * * + + + +### **escaper.unescape(str) ⇒ String** +Unescape the given string for the given style. The unescaped +string is what the programming language would use in memory as it is running. + +**Kind**: instance abstract method of [Escaper](#Escaper) +**Returns**: String - the unescaped string + +| Param | Type | Description | +| --- | --- | --- | +| str | String | the string to unescape | + + +* * * + + + +## JavaEscaper +Escaper for Java and Kotlin + +**Kind**: global class + +* [JavaEscaper](#JavaEscaper) + * [new JavaEscaper(style)](#new_JavaEscaper_new) + * [.escape()](#JavaEscaper+escape) + * [.unescape()](#JavaEscaper+unescape) + + +* * * + + + +### new JavaEscaper(style) +Can support the following styles: +- java: single or double-quoted strings +- java-raw: raw strings like """foo""" +- kotlin: regular single or double-quoted strings +- kotlin-raw: Kotlin raw strings like """foo""" + +**Throws**: + +- Error if the style is not supported + + +| Param | Type | Description | +| --- | --- | --- | +| style | string | the style to use for escaping | + + +* * * + + + +### javaEscaper.escape() +**Kind**: instance method of [JavaEscaper](#JavaEscaper) + +* * * + + + +### javaEscaper.unescape() +**Kind**: instance method of [JavaEscaper](#JavaEscaper) + +* * * + + + +## JavascriptEscaper +Escaper for JavaScript + +**Kind**: global class + +* [JavascriptEscaper](#JavascriptEscaper) + * [new JavascriptEscaper(style)](#new_JavascriptEscaper_new) + * [.escape()](#JavascriptEscaper+escape) + * [.unescape()](#JavascriptEscaper+unescape) + + +* * * + + + +### new JavascriptEscaper(style) +Can support the following styles: +- js: single or double-quoted strings +- js-template: JS template strings like `foo` + +**Throws**: + +- Error if the style is not supported + + +| Param | Type | Description | +| --- | --- | --- | +| style | string | the style to use for escaping | + + +* * * + + + +### javascriptEscaper.escape() +**Kind**: instance method of [JavascriptEscaper](#JavascriptEscaper) + +* * * + + + +### javascriptEscaper.unescape() +**Kind**: instance method of [JavascriptEscaper](#JavascriptEscaper) + +* * * + + + +## JsonEscaper +Escaper for Java + +**Kind**: global class + +* [JsonEscaper](#JsonEscaper) + * [.escape()](#JsonEscaper+escape) + * [.unescape()](#JsonEscaper+unescape) + + +* * * + + + +### jsonEscaper.escape() +**Kind**: instance method of [JsonEscaper](#JsonEscaper) + +* * * + + + +### jsonEscaper.unescape() +**Kind**: instance method of [JsonEscaper](#JsonEscaper) + +* * * + + + +## PHPEscaper +Escaper for PHP + +**Kind**: global class + +* [PHPEscaper](#PHPEscaper) + * [new PHPEscaper(style)](#new_PHPEscaper_new) + * [.escape()](#PHPEscaper+escape) + * [.unescape()](#PHPEscaper+unescape) + + +* * * + + + +### new PHPEscaper(style) +Can support the following styles: +- php (default): double-quoted strings +- php-double: double-quoted strings +- php-single: single-quoted strings +- php-heredoc: heredoc strings +- php-nowdoc: nowdoc strings + +**Throws**: + +- Error if the style is not supported + + +| Param | Type | Description | +| --- | --- | --- | +| style | string | the style to use for escaping | + + +* * * + + + +### phpEscaper.escape() +**Kind**: instance method of [PHPEscaper](#PHPEscaper) + +* * * + + + +### phpEscaper.unescape() +**Kind**: instance method of [PHPEscaper](#PHPEscaper) + +* * * + + + +## PythonEscaper +Escaper for Python + +**Kind**: global class + +* [PythonEscaper](#PythonEscaper) + * [new PythonEscaper(style)](#new_PythonEscaper_new) + * [.escape()](#PythonEscaper+escape) + * [.unescape()](#PythonEscaper+unescape) + + +* * * + + + +### new PythonEscaper(style) +Can support the following styles: +- python (default): single or double-quoted strings +- python-raw: python raw strings like r"foo" +- python-byte: python byte strings like b"foo" +- python-multi: python multi-line strings like """foo""" + +**Throws**: + +- Error if the style is not supported + + +| Param | Type | Description | +| --- | --- | --- | +| style | string | the style to use for escaping | + + +* * * + + + +### pythonEscaper.escape() +**Kind**: instance method of [PythonEscaper](#PythonEscaper) + +* * * + + + +### pythonEscaper.unescape() +**Kind**: instance method of [PythonEscaper](#PythonEscaper) + +* * * + + + +## RegexBasedEscaper +Escaper for various string formats based on regular expressions. + +**Kind**: global class + +* [RegexBasedEscaper](#RegexBasedEscaper) + * [new RegexBasedEscaper(style)](#new_RegexBasedEscaper_new) + * [.escape()](#RegexBasedEscaper+escape) + * [.unescape()](#RegexBasedEscaper+unescape) + + +* * * + + + +### new RegexBasedEscaper(style) +Create a new escaper instance that escapes and unescapes strings based +on regular expressions. + +**Throws**: + +- Error if the style is not supported + + +| Param | Type | Description | +| --- | --- | --- | +| style | string | the style to use to determine how to escape | + + +* * * + + + +### regexBasedEscaper.escape() +**Kind**: instance method of [RegexBasedEscaper](#RegexBasedEscaper) + +* * * + + + +### regexBasedEscaper.unescape() +**Kind**: instance method of [RegexBasedEscaper](#RegexBasedEscaper) + +* * * + + + +## SmartyEscaper +Escaper for Smarty + +**Kind**: global class + +* [SmartyEscaper](#SmartyEscaper) + * [new SmartyEscaper(style)](#new_SmartyEscaper_new) + * [.escape()](#SmartyEscaper+escape) + * [.unescape()](#SmartyEscaper+unescape) + + +* * * + + + +### new SmartyEscaper(style) +Can support the following styles: +- smarty (default): double-quoted strings +- smarty-double: double-quoted strings +- smarty-single: single-quoted strings + +**Throws**: + +- Error if the style is not supported + + +| Param | Type | Description | +| --- | --- | --- | +| style | string | the style to use for escaping | + + +* * * + + + +### smartyEscaper.escape() +**Kind**: instance method of [SmartyEscaper](#SmartyEscaper) + +* * * + + + +### smartyEscaper.unescape() +**Kind**: instance method of [SmartyEscaper](#SmartyEscaper) + +* * * + + + +## SwiftEscaper +Escaper for Swift + +**Kind**: global class + +* [SwiftEscaper](#SwiftEscaper) + * [new SwiftEscaper(style)](#new_SwiftEscaper_new) + * [.escape()](#SwiftEscaper+escape) + * [.unescape()](#SwiftEscaper+unescape) + + +* * * + + + +### new SwiftEscaper(style) +Can support the following styles: +- swift (default): single or double-quoted strings +- swift-multi: swift multi-line strings like """foo""" +- swift-extended: swift raw strings like #"foo"# + +**Throws**: + +- Error if the style is not supported + + +| Param | Type | Description | +| --- | --- | --- | +| style | string | the style to use for escaping | + + +* * * + + + +### swiftEscaper.escape() +**Kind**: instance method of [SwiftEscaper](#SwiftEscaper) + +* * * + + + +### swiftEscaper.unescape() +**Kind**: instance method of [SwiftEscaper](#SwiftEscaper) + +* * * + + + +## URIEscaper +Escaper for URIs + +**Kind**: global class + +* [URIEscaper](#URIEscaper) + * [new URIEscaper()](#new_URIEscaper_new) + * [.escape()](#URIEscaper+escape) + * [.unescape()](#URIEscaper+unescape) + + +* * * + + + +### new URIEscaper() +Create a new escaper instance for URIs. + + +* * * + + + +### uriEscaper.escape() +**Kind**: instance method of [URIEscaper](#URIEscaper) + +* * * + + + +### uriEscaper.unescape() +**Kind**: instance method of [URIEscaper](#URIEscaper) + +* * * + ## nonBreakingTags @@ -2449,6 +3153,54 @@ by the excludes and includes list | excludes | Array.<String> | A list of micromatch patterns to exclude from the walk. If a pattern matches a directory, that directory will not be recursively searched. | +* * * + + + +## escaperFactory(style) ⇒ [Escaper](#Escaper) +Return an Escaper instance for the given style. The style must be one of the +following: +
    +
  • csharp - escape for C#
  • +
  • csharp-raw - escape for C# raw strings
  • +
  • csharp-verbatim - escape for C# verbatim strings
  • +
  • java - escape for Java
  • +
  • java-raw - escape for JSON raw strings
  • +
  • js - escape for JavaScript
  • +
  • javascript-template - escape for JavaScript template strings
  • +
  • json - escape for JSON
  • +
  • kotlin - escape for Kotlin
  • +
  • kotlin-raw - escape for Kotlin raw strings
  • +
  • php - escape for PHP (default, same as php-double)
  • +
  • php-double - escape for double-quoted PHP strings
  • +
  • php-single - escape for single-quoted PHP strings
  • +
  • php-heredoc - escape for PHP heredoc strings
  • +
  • php-nowdoc - escape for PHP nowdoc strings
  • +
  • python - escape for Python regular strings (default)
  • +
  • python-raw - escape for Python raw strings
  • +
  • python-byte - escape for Python byte strings
  • +
  • python-multi - escape for Python multi-line strings
  • +
  • regexp - escape for regular expressions
  • +
  • smarty - escape for Smarty templates (default, same as smarty-double)
  • +
  • smarty-double - escape for double-quoted Smarty strings
  • +
  • smarty-single - escape for single-quoted Smarty strings
  • +
  • swift - escape for regular Swift strings
  • +
  • swift-multi - escape for Swift multi-line strings
  • +
  • swift-extended - escape for Swift extended strings
  • +
  • uri - escape for URLs and URIs
  • +
  • xml - escape for XML text, including HTML
  • +
  • xml-attr - escape for XML attributes, including HTML
  • +
+ +**Kind**: global function +**Returns**: [Escaper](#Escaper) - a new Escaper instance, or undefined if the style +is not recognized + +| Param | Type | Description | +| --- | --- | --- | +| style | string | the style to use to determine how to escape | + + * * * @@ -2504,6 +3256,232 @@ plural resource, or undefined if the resource is not a string resource | resource | [ResourceString](#ResourceString) | the ICU-style plural resource string to convert into a plural resource | +* * * + + + +## unescapeUnicode(string) ⇒ string +Unescape a string that has sequences like \uXXXX + +**Kind**: global function +**Returns**: string - the unescaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to unescape | + + +* * * + + + +## unescapeUnicodeWithBrackets(string) ⇒ string +Unescape a string that has sequences like \u{XXXXX} + +**Kind**: global function +**Returns**: string - the unescaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to unescape | + + +* * * + + + +## unescapeUnicodeExtended(string) ⇒ string +Unescape a string that has sequences like \U000XXXXXX + +**Kind**: global function +**Returns**: string - the unescaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to unescape | + + +* * * + + + +## unescapeHex(string) ⇒ string +Unescape a string that has hexadecimal escape sequences in it +of the form \xXX. + +**Kind**: global function +**Returns**: string - the escaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to escape | + + +* * * + + + +## unescapeOctal(string) ⇒ string +Unescape a string that has octal escape sequences in it of the form \XXX. + +**Kind**: global function +**Returns**: string - the escaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to escape | + + +* * * + + + +## escapeUnicode(string) ⇒ string +Convert all code points above U+00FF and below U+10000 +to \uXXXX form. + +**Kind**: global function +**Returns**: string - the unescaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to unescape | + + +* * * + + + +## escapeUnicodeAstral(string) ⇒ string +Convert all code points above U+FFFF to \uXXXXX form. + +**Kind**: global function +**Returns**: string - the unescaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to unescape | + + +* * * + + + +## escapeUnicodeWithBrackets(string) ⇒ string +Convert all code points above U+FFFF to \u{XXXXX} form + +**Kind**: global function +**Returns**: string - the escaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to escape | + + +* * * + + + +## escapeUnicodeExtended(string) ⇒ string +Convert all code points above U+FFFF to \U000XXXXXX form + +**Kind**: global function +**Returns**: string - the escaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to escape | + + +* * * + + + +## escapeUnicodeAsSurrogatePairs(string) ⇒ string +Convert all code points above U+00FF as \uXXXX and +all code points above U+FFFF as surrogate pairs in that +same format. + +**Kind**: global function +**Returns**: string - the escaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to escape | + + +* * * + + + +## escapeHex(string) ⇒ string +Escape a string so that it has hexadecimal escape sequences +in it instead of the characters themselves. This function +will only convert characters from U+0000 to U+001F. The rest +of the characters will be left alone. If you have characters +that are less than U+001F that have special escape sequences +in the target programming language, you should escape them +first before calling this function. + +**Kind**: global function +**Returns**: string - the escaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to escape | + + +* * * + + + +## escapeRules(string, rules) ⇒ string +Escape a string according to the rules given. + +**Kind**: global function +**Returns**: string - the escaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to escape | +| rules | object | the rules to use for escaping | + + +* * * + + + +## unescapeRules(string, rules) ⇒ string +Unescape a string according to the rules given. + +**Kind**: global function +**Returns**: string - the unescaped string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to unescape | +| rules | object | the rules to use for unescaping | + + +* * * + + + +## unindent(string) ⇒ string +Remove leading whitespace from each line of a string. +This is used for things like "raw" strings +to remove the leading whitespace that is used to align +and indent the contents of the string with the rest of +the code. + +**Kind**: global function +**Returns**: string - the unindented string + +| Param | Type | Description | +| --- | --- | --- | +| string | string | the string to unindent | + + * * * diff --git a/packages/ilib-tools-common/docs/index.html b/packages/ilib-tools-common/docs/index.html index 301ac0785..e8da1cb99 100644 --- a/packages/ilib-tools-common/docs/index.html +++ b/packages/ilib-tools-common/docs/index.html @@ -29,7 +29,7 @@ @@ -71,7 +71,7 @@


- Documentation generated by JSDoc 4.0.4 on Fri Feb 14 2025 18:30:31 GMT+0100 (Central European Standard Time) using the docdash theme. + Documentation generated by JSDoc 4.0.4 on Mon Mar 03 2025 22:01:57 GMT-0800 (Pacific Standard Time) using the docdash theme.
diff --git a/packages/ilib-tools-common/docs/utils.js.html b/packages/ilib-tools-common/docs/utils.js.html index 5c6ff1d0a..9f1272f88 100644 --- a/packages/ilib-tools-common/docs/utils.js.html +++ b/packages/ilib-tools-common/docs/utils.js.html @@ -29,7 +29,7 @@ @@ -594,7 +594,7 @@

utils.js


- Documentation generated by JSDoc 4.0.4 on Fri Feb 14 2025 18:30:31 GMT+0100 (Central European Standard Time) using the docdash theme. + Documentation generated by JSDoc 4.0.4 on Mon Mar 03 2025 22:01:57 GMT-0800 (Pacific Standard Time) using the docdash theme.
NameTypeDescription
parametersstring -Object +string @@ -1258,7 +3774,7 @@
Parameters:
-
the parameters to format into the templatethe string to escape
templatestring -String +string @@ -1417,20 +3932,20 @@
Parameters:
-
template for the output filethe string to unescape
pathnamerules -String +object @@ -1441,7 +3956,7 @@
Parameters:
-
path to the source filethe rules to use for unescaping
sourcestring -String +string @@ -1599,8 +4114,7 @@
Parameters:
-
the source string as extracted from the -source code, unmodifiedthe string to unescape
objstring -Object +string @@ -1758,7 +4272,7 @@
Parameters:
-
object to testthe string to unescape
object - - -* - - - - - any object, arrary, or primitive
visitorstring -function +string @@ -1941,7 +4430,7 @@
Parameters:
-
function to call on any primitivethe string to unescape
template - - -String - - - - - the ilib template for matching against the path
pathnamestring -String +string @@ -2126,7 +4592,7 @@
Parameters:
-
the path name to match against the templatethe string to unindent