summaryrefslogtreecommitdiffstats
path: root/build/clang-plugin/mozsearch-plugin/StringOperations.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /build/clang-plugin/mozsearch-plugin/StringOperations.cpp
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'build/clang-plugin/mozsearch-plugin/StringOperations.cpp')
-rw-r--r--build/clang-plugin/mozsearch-plugin/StringOperations.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/build/clang-plugin/mozsearch-plugin/StringOperations.cpp b/build/clang-plugin/mozsearch-plugin/StringOperations.cpp
new file mode 100644
index 0000000000..a2e60e42c6
--- /dev/null
+++ b/build/clang-plugin/mozsearch-plugin/StringOperations.cpp
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "StringOperations.h"
+
+static unsigned long djbHash(const char *Str) {
+ unsigned long Hash = 5381;
+
+ for (const char *P = Str; *P; P++) {
+ // Hash * 33 + c
+ Hash = ((Hash << 5) + Hash) + *P;
+ }
+
+ return Hash;
+}
+
+// This doesn't actually return a hex string of |hash|, but it
+// does... something. It doesn't really matter what.
+static void hashToString(unsigned long Hash, char *Buffer) {
+ const char Table[] = {"0123456789abcdef"};
+ char *P = Buffer;
+ while (Hash) {
+ *P = Table[Hash & 0xf];
+ Hash >>= 4;
+ P++;
+ }
+
+ *P = 0;
+}
+
+std::string hash(const std::string &Str) {
+ static char HashStr[41];
+ unsigned long H = djbHash(Str.c_str());
+ hashToString(H, HashStr);
+ return std::string(HashStr);
+}
+
+std::string toString(int N) {
+ return stringFormat("%d", N);
+}