Support/ADT/Twine: Add toNullTerminatedStringRef.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120600 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/Twine.cpp b/lib/Support/Twine.cpp
index 093e29d..4f6f479 100644
--- a/lib/Support/Twine.cpp
+++ b/lib/Support/Twine.cpp
@@ -30,6 +30,18 @@
   return StringRef(Out.data(), Out.size());
 }
 
+StringRef Twine::toNullTerminatedStringRef(SmallVectorImpl<char> &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) {