aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:11 +0000
commite3b557809604d036af6e00c60f012c2025b59a5e (patch)
tree8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp
parent08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff)
Diffstat (limited to 'llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp')
-rw-r--r--llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp b/llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp
new file mode 100644
index 000000000000..9fa1f28eb089
--- /dev/null
+++ b/llvm/lib/DebugInfo/LogicalView/Core/LVSupport.cpp
@@ -0,0 +1,56 @@
+//===-- LVSupport.cpp -----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This implements the supporting functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/DebugInfo/LogicalView/Core/LVSupport.h"
+#include "llvm/Support/FormatAdapters.h"
+#include "llvm/Support/FormatVariadic.h"
+#include <iomanip>
+
+using namespace llvm;
+using namespace llvm::logicalview;
+
+#define DEBUG_TYPE "Support"
+
+// Perform the following transformations to the given 'Path':
+// - all characters to lowercase.
+// - '\\' into '/' (Platform independent).
+// - '//' into '/'
+std::string llvm::logicalview::transformPath(StringRef Path) {
+ std::string Name(Path);
+ std::transform(Name.begin(), Name.end(), Name.begin(), tolower);
+ std::replace(Name.begin(), Name.end(), '\\', '/');
+
+ // Remove all duplicate slashes.
+ size_t Pos = 0;
+ while ((Pos = Name.find("//", Pos)) != std::string::npos)
+ Name.erase(Pos, 1);
+
+ return Name;
+}
+
+// Convert the given 'Path' to lowercase and change any matching character
+// from 'CharSet' into '_'.
+// The characters in 'CharSet' are:
+// '/', '\', '<', '>', '.', ':', '%', '*', '?', '|', '"', ' '.
+std::string llvm::logicalview::flattenedFilePath(StringRef Path) {
+ std::string Name(Path);
+ std::transform(Name.begin(), Name.end(), Name.begin(), tolower);
+
+ const char *CharSet = "/\\<>.:%*?|\" ";
+ char *Input = Name.data();
+ while (Input && *Input) {
+ Input = strpbrk(Input, CharSet);
+ if (Input)
+ *Input++ = '_';
+ };
+ return Name;
+}