summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Twine.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-12-01 20:37:30 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-12-01 20:37:30 +0000
commitf2cc8287ed6a37a6141a60c83f7e30fe288e9606 (patch)
tree830ab6ab3c3b4adcc9b946100cd7dba94b18c8a7 /llvm/lib/Support/Twine.cpp
parentaa49ecc4586af252e2841c2bc8f5689526da7a4b (diff)
downloadbcm5719-llvm-f2cc8287ed6a37a6141a60c83f7e30fe288e9606.tar.gz
bcm5719-llvm-f2cc8287ed6a37a6141a60c83f7e30fe288e9606.zip
Support/ADT/Twine: Add toNullTerminatedStringRef.
llvm-svn: 120600
Diffstat (limited to 'llvm/lib/Support/Twine.cpp')
-rw-r--r--llvm/lib/Support/Twine.cpp12
1 files changed, 12 insertions, 0 deletions
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<char> &Out) const {
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) {
OpenPOWER on IntegriCloud