本文整理汇总了C++中StringPiece::front方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::front方法的具体用法?C++ StringPiece::front怎么用?C++ StringPiece::front使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringPiece
的用法示例。
在下文中一共展示了StringPiece::front方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ltrimWhitespace
StringPiece ltrimWhitespace(StringPiece sp) {
// Spaces other than ' ' characters are less common but should be
// checked. This configuration where we loop on the ' '
// separately from oddspaces was empirically fastest.
loop:
for (; !sp.empty() && sp.front() == ' '; sp.pop_front()) {
}
if (!sp.empty() && is_oddspace(sp.front())) {
sp.pop_front();
goto loop;
}
return sp;
}
示例2: trim
StringPiece trim(StringPiece sp, StringPiece chars) {
for (; !sp.empty() && chars.find(sp.front()) != StringPiece::npos; ) {
sp.pop_front();
}
for (; !sp.empty() && chars.find(sp.back()) != StringPiece::npos; ) {
sp.pop_back();
}
return sp;
}
示例3:
bool IPAddressV6::validate(StringPiece ip) {
if (ip.size() > 0 && ip.front() == '[' && ip.back() == ']') {
ip = ip.subpiece(1, ip.size() - 2);
}
constexpr size_t kStrMaxLen = INET6_ADDRSTRLEN;
std::array<char, kStrMaxLen + 1> ip_cstr;
const size_t len = std::min(ip.size(), kStrMaxLen);
std::memcpy(ip_cstr.data(), ip.data(), len);
ip_cstr[len] = 0;
struct in6_addr addr;
return 1 == inet_pton(AF_INET6, ip_cstr.data(), &addr);
}
示例4: cmp
int LogName::cmp(StringPiece a, StringPiece b) {
// Ignore trailing separators
auto stripTrailingSeparators = [](StringPiece& s) {
while (!s.empty() && isSeparator(s.back())) {
s.uncheckedSubtract(1);
}
};
stripTrailingSeparators(a);
stripTrailingSeparators(b);
// Advance ptr until it no longer points to a category separator.
// This is used to skip over consecutive sequences of separator characters.
auto skipOverSeparators = [](StringPiece& s) {
while (!s.empty() && isSeparator(s.front())) {
s.uncheckedAdvance(1);
}
};
bool ignoreSeparator = true;
while (true) {
if (ignoreSeparator) {
skipOverSeparators(a);
skipOverSeparators(b);
}
if (a.empty()) {
return b.empty() ? 0 : -1;
} else if (b.empty()) {
return 1;
}
if (isSeparator(a.front())) {
if (!isSeparator(b.front())) {
return '.' - b.front();
}
ignoreSeparator = true;
} else {
if (a.front() != b.front()) {
return a.front() - b.front();
}
ignoreSeparator = false;
}
a.uncheckedAdvance(1);
b.uncheckedAdvance(1);
}
}