本文整理汇总了C++中folly::StringPiece::startsWith方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::startsWith方法的具体用法?C++ StringPiece::startsWith怎么用?C++ StringPiece::startsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类folly::StringPiece
的用法示例。
在下文中一共展示了StringPiece::startsWith方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: simplifyPath
// Simplify a path -- as much as we can while not moving data around...
void simplifyPath(folly::StringPiece& sp) {
// Strip leading slashes and useless patterns (./), leaving one initial
// slash.
for (;;) {
if (sp.empty()) {
return;
}
// Strip leading slashes, leaving one.
while (sp.startsWith("//")) {
sp.advance(1);
}
if (sp.startsWith("/./")) {
// Note 2, not 3, to keep it absolute
sp.advance(2);
continue;
}
if (sp.removePrefix("./")) {
// Also remove any subsequent slashes to avoid making this path absolute.
while (sp.startsWith('/')) {
sp.advance(1);
}
continue;
}
break;
}
// Strip trailing slashes and useless patterns (/.).
for (;;) {
if (sp.empty()) {
return;
}
// Strip trailing slashes, except when this is the root path.
while (sp.size() > 1 && sp.removeSuffix('/')) { }
if (sp.removeSuffix("/.")) {
continue;
}
break;
}
}
示例2: simplifyPath
// Simplify a path -- as much as we can while not moving data around...
void simplifyPath(folly::StringPiece& sp) {
// Strip leading slashes and useless patterns (./), leaving one initial
// slash.
for (;;) {
if (sp.empty()) {
return;
}
// Strip leading slashes, leaving one.
while (sp.startsWith("//")) {
sp.advance(1);
}
if (sp.startsWith("/./")) {
// Note 2, not 3, to keep it absolute
sp.advance(2);
continue;
}
if (sp.removePrefix("./")) {
continue;
}
break;
}
// Strip trailing slashes and useless patterns (/.).
for (;;) {
if (sp.empty()) {
return;
}
// Strip trailing slashes
while (sp.removeSuffix('/')) { }
if (sp.removeSuffix("/.")) {
continue;
}
break;
}
}
示例3: parseByteRangeSpec
bool parseByteRangeSpec(
folly::StringPiece value,
unsigned long& outFirstByte,
unsigned long& outLastByte,
unsigned long& outInstanceLength) {
// We should start with "bytes "
if (!value.startsWith("bytes ")) {
return false;
}
const char* curs = value.begin() + 6 /* strlen("bytes ") */;
const char* end = value.end();
unsigned long firstByte = ULONG_MAX;
unsigned long lastByte = ULONG_MAX;
unsigned long instanceLength = ULONG_MAX;
if (!strtoulWrapper(curs, end, firstByte)) {
if (*curs != '*') {
return false;
}
firstByte = 0;
lastByte = ULONG_MAX;
++curs;
} else {
if (*curs != '-') {
return false;
}
++curs;
if (!strtoulWrapper(curs, end, lastByte)) {
return false;
}
}
if (*curs != '/') {
return false;
}
++curs;
if (*curs != '*') {
if (!strtoulWrapper(curs, end, instanceLength)) {
return false;
}
} else {
++curs;
}
if (curs < end && *curs != '\0') {
return false;
}
if (lastByte < firstByte) {
return false;
}
if ((lastByte - firstByte + 1) > instanceLength) {
return false;
}
outFirstByte = firstByte;
outLastByte = lastByte;
outInstanceLength = instanceLength;
return true;
}