• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- llvm/Support/StringSaver.h -------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_SUPPORT_STRINGSAVER_H
11 #define LLVM_SUPPORT_STRINGSAVER_H
12 
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/Allocator.h"
16 
17 namespace llvm {
18 
19 /// \brief Saves strings in the inheritor's stable storage and returns a
20 /// StringRef with a stable character pointer.
21 class StringSaver final {
22   BumpPtrAllocator &Alloc;
23 
24 public:
StringSaver(BumpPtrAllocator & Alloc)25   StringSaver(BumpPtrAllocator &Alloc) : Alloc(Alloc) {}
save(const char * S)26   StringRef save(const char *S) { return save(StringRef(S)); }
27   StringRef save(StringRef S);
save(const Twine & S)28   StringRef save(const Twine &S) { return save(StringRef(S.str())); }
save(std::string & S)29   StringRef save(std::string &S) { return save(StringRef(S)); }
30 };
31 }
32 #endif
33