本文整理汇总了C++中zstring::length方法的典型用法代码示例。如果您正苦于以下问题:C++ zstring::length方法的具体用法?C++ zstring::length怎么用?C++ zstring::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zstring
的用法示例。
在下文中一共展示了zstring::length方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replace
zstring zstring::replace(zstring const& src, zstring const& dst) const {
zstring result(m_encoding);
if (length() < src.length()) {
return zstring(*this);
}
if (src.length() == 0) {
return zstring(*this);
}
bool found = false;
for (unsigned i = 0; i < length(); ++i) {
bool eq = !found && i + src.length() <= length();
for (unsigned j = 0; eq && j < src.length(); ++j) {
eq = m_buffer[i+j] == src[j];
}
if (eq) {
result.m_buffer.append(dst.m_buffer);
found = true;
i += src.length() - 1;
}
else {
result.m_buffer.push_back(m_buffer[i]);
}
}
return result;
}
示例2: if
bool operator<(const zstring& lhs, const zstring& rhs) {
// This has the same semantics as strcmp()
unsigned len = lhs.length();
if (rhs.length() < len) {
len = rhs.length();
}
for (unsigned i = 0; i < len; ++i) {
unsigned Li = lhs[i];
unsigned Ri = rhs[i];
if (Li < Ri) {
return true;
} else if (Li > Ri) {
return false;
} else {
continue;
}
}
// at this point, all compared characters are equal,
// so decide based on the relative lengths
if (lhs.length() < rhs.length()) {
return true;
} else {
return false;
}
}
示例3: suffixof
bool zstring::suffixof(zstring const& other) const {
if (length() > other.length()) return false;
bool suffix = true;
for (unsigned i = 0; suffix && i < length(); ++i) {
suffix = m_buffer[length()-i-1] == other[other.length()-i-1];
}
return suffix;
}
示例4: contains
bool zstring::contains(zstring const& other) const {
if (other.length() > length()) return false;
unsigned last = length() - other.length();
bool cont = false;
for (unsigned i = 0; !cont && i <= last; ++i) {
cont = true;
for (unsigned j = 0; cont && j < other.length(); ++j) {
cont = other[j] == m_buffer[j+i];
}
}
return cont;
}
示例5: indexof
int zstring::indexof(zstring const& other, int offset) const {
SASSERT(offset >= 0);
if (static_cast<unsigned>(offset) == length()) return -1;
if (other.length() + offset > length()) return -1;
unsigned last = length() - other.length();
for (unsigned i = static_cast<unsigned>(offset); i <= last; ++i) {
bool prefix = true;
for (unsigned j = 0; prefix && j < other.length(); ++j) {
prefix = m_buffer[i + j] == other[j];
}
if (prefix) {
return static_cast<int>(i);
}
}
return -1;
}
示例6: prefixof
bool zstring::prefixof(zstring const& other) const {
if (length() > other.length()) return false;
bool prefix = true;
for (unsigned i = 0; prefix && i < length(); ++i) {
prefix = m_buffer[i] == other[i];
}
return prefix;
}
示例7: while
/**
* Utility function: Given a string aStr and position aPos, populate
* aInt with the integer at that position in the string. aPos will be
* updated to next character.
* @return true if an integer found, false if not.
*/
static bool
getInteger(zstring const& aStr, size_t& aPos, int& aInt)
{
char lChar;
size_t lLen = aStr.length();
size_t const lOrigPos = aPos;
aInt = 0;
while (aPos < lLen && isdigit(lChar = aStr[aPos])) {
aInt = aInt * 10 + (lChar - '0');
aPos++;
}
return (aPos != lOrigPos);
}
示例8:
bool zstring::operator==(const zstring& other) const {
// two strings are equal iff they have the same length and characters
if (length() != other.length()) {
return false;
}
for (unsigned i = 0; i < length(); ++i) {
unsigned Xi = m_buffer[i];
unsigned Yi = other[i];
if (Xi != Yi) {
return false;
}
}
return true;
}
示例9: if
bool
ModuleVersion::initValues(zstring const& aVersionDef)
{
// Parse fragment for legal version specification. If any illegal
// characters found, no versioning to be attempted.
int lMajor, lMinor, lPatch = 0, lMajorB = -1;
bool lExact = false;
size_t lPos = 0;
size_t lLen = aVersionDef.length();
if (!getInteger(aVersionDef, lPos, lMajor)) {
return false;
}
if (lPos >= lLen) {
return false;
}
if (aVersionDef[lPos++] != '.') {
return false;
}
if (!getInteger(aVersionDef, lPos, lMinor)) {
return false;
}
if (lPos < lLen && aVersionDef[lPos] == '.') {
// There's (potentially) a patch version specified as well
lPos ++;
if (lPos >= lLen) {
return false;
}
if (!getInteger(aVersionDef, lPos, lPatch)) {
return false;
}
}
if (lPos < lLen) {
// Found legal major.minor, but there's more to parse - could be "!"
// or "-major.0"
char lChar = aVersionDef[lPos++];
if (lChar == '!' && lPos == lLen) {
lExact = true;
}
else if (lChar == '-') {
if (!getInteger(aVersionDef, lPos, lMajorB)) {
return false;
}
if (lPos >= lLen || aVersionDef[lPos++] != '.') {
return false;
}
if (lPos >= lLen || aVersionDef[lPos++] != '0') {
return false;
}
}
else {
return false;
}
}
// Verify there's no more to read.
if (lPos != lLen) {
return false;
}
// Ok, we successfully parsed a version definition; set all our variables.
theMinMajor = lMajor;
theMinMinor = lMinor;
theMinPatch = lPatch;
theMaxMajor = lMajorB == -1 ? lMajor : lMajorB;
theIsExact = lExact;
theValidVersion = true;
return true;
}