本文整理汇总了C++中StringPiece::back方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::back方法的具体用法?C++ StringPiece::back怎么用?C++ StringPiece::back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringPiece
的用法示例。
在下文中一共展示了StringPiece::back方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rtrimWhitespace
StringPiece rtrimWhitespace(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.back() == ' '; sp.pop_back()) {
}
if (!sp.empty() && is_oddspace(sp.back())) {
sp.pop_back();
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);
}