1 //===-- LVSupport.cpp -----------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This implements the supporting functions. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/DebugInfo/LogicalView/Core/LVSupport.h" 14 #include "llvm/Support/FormatAdapters.h" 15 #include "llvm/Support/FormatVariadic.h" 16 #include <iomanip> 17 18 using namespace llvm; 19 using namespace llvm::logicalview; 20 21 #define DEBUG_TYPE "Support" 22 23 // Perform the following transformations to the given 'Path': 24 // - all characters to lowercase. 25 // - '\\' into '/' (Platform independent). 26 // - '//' into '/' 27 std::string llvm::logicalview::transformPath(StringRef Path) { 28 std::string Name(Path); 29 std::transform(Name.begin(), Name.end(), Name.begin(), tolower); 30 std::replace(Name.begin(), Name.end(), '\\', '/'); 31 32 // Remove all duplicate slashes. 33 size_t Pos = 0; 34 while ((Pos = Name.find("//", Pos)) != std::string::npos) 35 Name.erase(Pos, 1); 36 37 return Name; 38 } 39 40 // Convert the given 'Path' to lowercase and change any matching character 41 // from 'CharSet' into '_'. 42 // The characters in 'CharSet' are: 43 // '/', '\', '<', '>', '.', ':', '%', '*', '?', '|', '"', ' '. 44 std::string llvm::logicalview::flattenedFilePath(StringRef Path) { 45 std::string Name(Path); 46 std::transform(Name.begin(), Name.end(), Name.begin(), tolower); 47 48 const char *CharSet = "/\\<>.:%*?|\" "; 49 char *Input = Name.data(); 50 while (Input && *Input) { 51 Input = strpbrk(Input, CharSet); 52 if (Input) 53 *Input++ = '_'; 54 }; 55 return Name; 56 } 57