mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-04 09:45:00 +00:00
Add isCString() - returns true if a ConstantArray is a CString.
llvm-svn: 31201
This commit is contained in:
parent
53cc483549
commit
9d0bfecda6
@ -334,6 +334,11 @@ public:
|
||||
/// ubyte, and if the elements of the array are all ConstantInt's.
|
||||
bool isString() const;
|
||||
|
||||
/// 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 isCString() const;
|
||||
|
||||
/// getAsString - If this array is isString(), then this method converts the
|
||||
/// array to an std::string and returns it. Otherwise, it asserts out.
|
||||
///
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user