diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-01 20:37:30 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-01 20:37:30 +0000 |
commit | 7dc7ac3cb20b7ef8e6febe0ac3bc430230f29893 (patch) | |
tree | 8f8f6241c8d337970dc397842482c4279e1ea9c0 /lib/Support/Twine.cpp | |
parent | f00140c8e16936aac3f51cc5607168f6982a987a (diff) |
Support/ADT/Twine: Add toNullTerminatedStringRef.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120600 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Twine.cpp')
-rw-r--r-- | lib/Support/Twine.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Support/Twine.cpp b/lib/Support/Twine.cpp index 093e29de96..4f6f479a7e 100644 --- a/lib/Support/Twine.cpp +++ b/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) { |