From be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 Mon Sep 17 00:00:00 2001
From: Daniel Baumann <daniel.baumann@progress-linux.org>
Date: Fri, 19 Apr 2024 04:57:58 +0200
Subject: Adding upstream version 1.44.3.

Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
---
 .../h2o/libh2o/misc/oktavia/src/query-parser.jsx   | 60 ++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 web/server/h2o/libh2o/misc/oktavia/src/query-parser.jsx

(limited to 'web/server/h2o/libh2o/misc/oktavia/src/query-parser.jsx')

diff --git a/web/server/h2o/libh2o/misc/oktavia/src/query-parser.jsx b/web/server/h2o/libh2o/misc/oktavia/src/query-parser.jsx
new file mode 100644
index 00000000..86308bcb
--- /dev/null
+++ b/web/server/h2o/libh2o/misc/oktavia/src/query-parser.jsx
@@ -0,0 +1,60 @@
+import "query.jsx";
+
+
+class QueryParser
+{
+    var queries : Query[];
+    function constructor()
+    {
+        this.queries = [] : Query[];
+    }
+
+    function parse (queryStrings : string[]) : Query[]
+    {
+        var nextOr = false;
+        for (var i = 0; i < queryStrings.length; i++)
+        {
+            var word = queryStrings[i];
+            if (word == 'OR')
+            {
+                nextOr = true;
+            }
+            else
+            {
+                var query = new Query();
+                if (nextOr)
+                {
+                    query.or = true;
+                    nextOr = false;
+                }
+                if (word.slice(0, 1) == '-')
+                {
+                    query.not = true;
+                    word = word.slice(1);
+                }
+                if (word.slice(0, 1) == '"' && word.slice(word.length -1) == '"')
+                {
+                    query.raw = true;
+                    word = word.slice(1, word.length -1);
+                }
+                query.word = word;
+                this.queries.push(query);
+            }
+        }
+        return this.queries;
+    }
+
+    function highlight () : string
+    {
+        var result = [] : string[];
+        for (var i = 0; i < this.queries.length; i++)
+        {
+            var query = this.queries[i];
+            if (!query.not)
+            {
+                result.push("highlight=" + String.encodeURIComponent(query.word));
+            }
+        }
+        return '?' + result.join('&');
+    }
+}
-- 
cgit v1.2.3

