1 //===- llvm/Support/StringSaver.h -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_SUPPORT_STRINGSAVER_H
11 #define LLVM_SUPPORT_STRINGSAVER_H
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/Allocator.h"
19 /// \brief Saves strings in the inheritor's stable storage and returns a stable
20 /// raw character pointer.
21 class StringSaver final {
22 BumpPtrAllocator &Alloc;
25 StringSaver(BumpPtrAllocator &Alloc) : Alloc(Alloc) {}
26 const char *save(const char *S) { return save(StringRef(S)); }
27 const char *save(StringRef S);
28 const char *save(const Twine &S) { return save(StringRef(S.str())); }
29 const char *save(std::string &S) { return save(StringRef(S)); }