From f2cc8287ed6a37a6141a60c83f7e30fe288e9606 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Wed, 1 Dec 2010 20:37:30 +0000 Subject: Support/ADT/Twine: Add toNullTerminatedStringRef. llvm-svn: 120600 --- llvm/lib/Support/Twine.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/lib/Support/Twine.cpp') diff --git a/llvm/lib/Support/Twine.cpp b/llvm/lib/Support/Twine.cpp index 093e29de96a..4f6f479a7ea 100644 --- a/llvm/lib/Support/Twine.cpp +++ b/llvm/lib/Support/Twine.cpp @@ -30,6 +30,18 @@ StringRef Twine::toStringRef(SmallVectorImpl &Out) const { return StringRef(Out.data(), Out.size()); } +StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl &Out) const { + if (isSingleStringRef()) { + StringRef sr = getSingleStringRef(); + if (*(sr.begin() + sr.size()) == 0) + return sr; + } + toVector(Out); + Out.push_back(0); + Out.pop_back(); + return StringRef(Out.data(), Out.size()); +} + void Twine::printOneChild(raw_ostream &OS, const void *Ptr, NodeKind Kind) const { switch (Kind) { -- cgit v1.2.3