You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2022/09/12 03:09:43 UTC

[incubator-nlpcraft] branch master updated: Bug fix.

This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/master by this push:
     new b0c907ec Bug fix.
b0c907ec is described below

commit b0c907ec2a32fdb48d7271201770552f7c554829
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sun Sep 11 20:09:37 2022 -0700

    Bug fix.
---
 .../apache/nlpcraft/internal/antlr4/NCCompilerUtils.scala   | 13 ++++++++-----
 .../scala/org/apache/nlpcraft/internal/util/NCUtils.scala   | 12 ++----------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/antlr4/NCCompilerUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/antlr4/NCCompilerUtils.scala
index f76fb879..c5650b6f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/antlr4/NCCompilerUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/antlr4/NCCompilerUtils.scala
@@ -30,9 +30,12 @@ object NCCompilerUtils:
         if in0.isEmpty || charPos < 0 then NCCompilerErrorHolder("<empty>", "<empty>")
         else
             val charPos0 = charPos - (in.length - in.stripLeading().length)
-            val pos = Math.max(0, charPos0)
-            val dash = "-" * in0.length
-            val ptrStr = s"${dash.substring(0, pos)}^${dash.substring(pos + 1)}"
-            val origStr = s"${in0.substring(0, pos)}${in0.charAt(pos)}${in0.substring(pos + 1)}"
+            val len = in0.length
+            val pos = Math.min(Math.max(0, charPos0), len)
 
-            NCCompilerErrorHolder(ptrStr, origStr)
+            if pos == len then
+                NCCompilerErrorHolder(s"${"-" * len}^", in0)
+            else
+                val dash = "-" * len
+                val ptrStr = s"${dash.substring(0, pos)}^${dash.substring(pos + 1)}"
+                NCCompilerErrorHolder(ptrStr, in0)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
index 5bdd9713..8ce01492 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
@@ -279,26 +279,18 @@ object NCUtils extends LazyLogging:
         else
             s
 
-    /**
-      *
-      * @param s
-      * @param sep
-      */
-    def normalize(s: String, sep: String): String =
-        splitTrimFilter(s, sep).mkString(sep)
-
     /**
       * Escapes given string for JSON according to RFC 4627 http://www.ietf.org/rfc/rfc4627.txt.
       *
       * @param s String to escape.
       * @return Escaped string.
       */
-    def escapeJson(s: String): String =
+    private def escapeJson(s: String): String = // TODO: remove?
         val len = s.length
         if len == 0 then
             ""
         else
-            val sb = new StringBuilder
+            val sb = new mutable.StringBuilder
             for (ch <- s.toCharArray)
                 ch match
                     case '\\' | '"' => sb += '\\' += ch