[clangd] Add "str()" method to SymbolID.
authorHaojian Wu <hokein@google.com>
Wed, 25 Apr 2018 15:27:09 +0000 (15:27 +0000)
committerHaojian Wu <hokein@google.com>
Wed, 25 Apr 2018 15:27:09 +0000 (15:27 +0000)
Summary:
This is a convenient function when we try to get std::string of
SymbolID.

Reviewers: ioeric

Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits

Differential Revision: https://reviews.llvm.org/D46065

llvm-svn: 330835

clang-tools-extra/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
clang-tools-extra/clangd/index/Index.cpp
clang-tools-extra/clangd/index/Index.h

index 7d62cf1..2607e2b 100644 (file)
@@ -78,10 +78,7 @@ public:
 
         auto Symbols = Collector->takeSymbols();
         for (const auto &Sym : Symbols) {
-          std::string IDStr;
-          llvm::raw_string_ostream OS(IDStr);
-          OS << Sym.ID;
-          Ctx->reportResult(OS.str(), SymbolToYAML(Sym));
+          Ctx->reportResult(Sym.ID.str(), SymbolToYAML(Sym));
         }
       }
 
index c4e969c..b12507a 100644 (file)
@@ -31,6 +31,13 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolID &ID) {
   return OS;
 }
 
+std::string SymbolID::str() const {
+  std::string ID;
+  llvm::raw_string_ostream OS(ID);
+  OS << *this;
+  return OS.str();
+}
+
 void operator>>(StringRef Str, SymbolID &ID) {
   std::string HexString = fromHex(Str);
   assert(HexString.size() == ID.HashValue.size());
index cb32c0f..610b0e6 100644 (file)
@@ -69,6 +69,9 @@ public:
     return HashValue < Sym.HashValue;
   }
 
+  // Returns a 40-bytes hex encoded string.
+  std::string str() const;
+
 private:
   static constexpr unsigned HashByteLength = 20;