本文整理汇总了C++中folly::StringPiece::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::begin方法的具体用法?C++ StringPiece::begin怎么用?C++ StringPiece::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类folly::StringPiece
的用法示例。
在下文中一共展示了StringPiece::begin方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getMemcacheKeyHashValue
void McRequest::Keys::update(folly::StringPiece key) {
keyWithoutRoute = key;
if (!key.empty()) {
if (*key.begin() == '/') {
size_t pos = 1;
for (int i = 0; i < 2; ++i) {
pos = key.find('/', pos);
if (pos == std::string::npos) {
break;
}
++pos;
}
if (pos != std::string::npos) {
keyWithoutRoute.advance(pos);
routingPrefix.reset(key.begin(), pos);
}
}
}
routingKey = keyWithoutRoute;
size_t pos = keyWithoutRoute.find("|#|");
if (pos != std::string::npos) {
routingKey.reset(keyWithoutRoute.begin(), pos);
}
routingKeyHash = getMemcacheKeyHashValue(routingKey);
}
示例2: update
void Keys::update(folly::StringPiece key) {
keyWithoutRoute_ = key;
if (!key.empty()) {
if (*key.begin() == '/') {
size_t pos = 1;
for (int i = 0; i < 2; ++i) {
pos = key.find('/', pos);
if (pos == std::string::npos) {
break;
}
++pos;
}
if (pos != std::string::npos) {
keyWithoutRoute_.advance(pos);
routingPrefix_.reset(key.begin(), pos);
}
}
}
routingKey_ = keyWithoutRoute_;
size_t pos = keyWithoutRoute_.find("|#|");
if (pos != std::string::npos) {
routingKey_.reset(keyWithoutRoute_.begin(), pos);
}
routingKeyHash_ = 0;
}
示例3: it
/**
* Matches all the occurences of "pattern" in "text"
*
* @return A vector of pairs containing the index and size (respectively)
* of all ocurrences.
*/
std::vector<std::pair<size_t, size_t>> MessagePrinter::matchAll(
folly::StringPiece text, const boost::regex& pattern) const {
std::vector<std::pair<size_t, size_t>> result;
boost::cregex_token_iterator it(text.begin(), text.end(), pattern);
boost::cregex_token_iterator end;
while (it != end) {
result.emplace_back(it->first - text.begin(), it->length());
++it;
}
return result;
}
示例4: getSSLContext
std::shared_ptr<SSLContext> getSSLContext(folly::StringPiece pemCertPath,
folly::StringPiece pemKeyPath,
folly::StringPiece pemCaPath) {
static constexpr std::chrono::minutes kSslReloadInterval{5};
thread_local std::unordered_map<CertPaths, ContextInfo, CertPathsHasher>
localContexts;
CertPaths paths;
paths.pemCertPath = pemCertPath;
paths.pemKeyPath = pemKeyPath;
paths.pemCaPath = pemCaPath;
auto iter = localContexts.find(paths);
if (localContexts.find(paths) == localContexts.end()) {
// Copy strings.
ContextInfo info;
info.pemCertPath = pemCertPath.toString();
info.pemKeyPath = pemKeyPath.toString();
info.pemCaPath = pemCaPath.toString();
// Point all StringPiece's to our own strings.
paths.pemCertPath = info.pemCertPath;
paths.pemKeyPath = info.pemKeyPath;
paths.pemCaPath = info.pemCaPath;
iter = localContexts.insert(std::make_pair(paths, std::move(info))).first;
}
auto& contextInfo = iter->second;
auto now = std::chrono::steady_clock::now();
if (contextInfo.context == nullptr ||
now - contextInfo.lastLoadTime > kSslReloadInterval) {
try {
auto sslContext = std::make_shared<SSLContext>();
sslContext->loadCertificate(pemCertPath.begin());
sslContext->loadPrivateKey(pemKeyPath.begin());
sslContext->loadTrustedCertificates(pemCaPath.begin());
sslContext->loadClientCAList(pemCaPath.begin());
// Disable compression if possible to reduce CPU and memory usage.
#ifdef SSL_OP_NO_COMPRESSION
sslContext->setOptions(SSL_OP_NO_COMPRESSION);
#endif
contextInfo.lastLoadTime = now;
contextInfo.context = std::move(sslContext);
} catch (const apache::thrift::transport::TTransportException& ex) {
LOG(ERROR) << "Failed to load certificate, ex: " << ex.what();
}
}
return contextInfo.context;
}
示例5:
TEST(FixedStringConversionTest, ConversionToFollyRange) {
// The following declaraction is static for compilers that haven't implemented
// the resolution of:
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1454
static constexpr folly::FixedString<16> tmp{"This is a string"};
constexpr folly::StringPiece piece = tmp;
static_assert(tmp.begin() == piece.begin(), "");
static_assert(tmp.end() == piece.end(), "");
}
示例6: initThread
void SwSwitch::initThread(folly::StringPiece name) {
// We need a null-terminated string to pass to folly::setThreadName().
// The pthread name can be at most 15 bytes long, so truncate it if necessary
// when creating the string.
size_t pthreadLength = std::min(name.size(), (size_t)15);
char pthreadName[pthreadLength + 1];
memcpy(pthreadName, name.begin(), pthreadLength);
pthreadName[pthreadLength] = '\0';
folly::setThreadName(pthreadName);
}
示例7: hasSameMemoryRegion
bool hasSameMemoryRegion(const folly::IOBuf& buf, folly::StringPiece range) {
return !buf.isChained() &&
(buf.length() == 0 ||
(range.begin() == reinterpret_cast<const char*>(buf.data()) &&
range.size() == buf.length()));
}
示例8: 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;
}