aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Constants.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2006-10-26 19:15:05 +0000
committerEvan Cheng <evan.cheng@apple.com>2006-10-26 19:15:05 +0000
commit22c7030a0c535ed48d8465994f8f8aaf8fa76813 (patch)
tree361f270598ca81a422853471981d9a04a8935ce2 /lib/VMCore/Constants.cpp
parent4d3839ded2f434c67bc5f5cc7803978a727defb3 (diff)
downloadexternal_llvm-22c7030a0c535ed48d8465994f8f8aaf8fa76813.zip
external_llvm-22c7030a0c535ed48d8465994f8f8aaf8fa76813.tar.gz
external_llvm-22c7030a0c535ed48d8465994f8f8aaf8fa76813.tar.bz2
Add isCString() - returns true if a ConstantArray is a CString.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31201 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r--lib/VMCore/Constants.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 2c996f5..ce29a21 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -1073,6 +1073,19 @@ bool ConstantArray::isString() const {
return true;
}
+/// isCString - This method returns true if the array is a string (see
+/// isString) and it ends in a null byte \0 and does not contains any other
+/// null bytes except its terminator.
+bool ConstantArray::isCString() const {
+ if (!isString()) return false;
+ // This is safe because a ConstantArray cannot be a zero array.
+ for (unsigned i = 0, e = getNumOperands()-1; i != e; ++i)
+ if (cast<ConstantInt>(getOperand(i))->getZExtValue() == 0)
+ return false;
+ return true;
+}
+
+
// getAsString - If the sub-element type of this array is either sbyte or ubyte,
// then this method converts the array to an std::string and returns it.
// Otherwise, it asserts out.