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
17namespace llvm {
18
19/// \brief Saves strings in the inheritor's stable storage and returns a
20/// StringRef with a stable character pointer.
21class StringSaver final {
22  BumpPtrAllocator &Alloc;
23
24public:
25  StringSaver(BumpPtrAllocator &Alloc) : Alloc(Alloc) {}
26  StringRef save(const char *S) { return save(StringRef(S)); }
27  StringRef save(StringRef S);
28  StringRef save(const Twine &S) { return save(StringRef(S.str())); }
29  StringRef save(const std::string &S) { return save(StringRef(S)); }
30};
31}
32#endif
33