本文整理汇总了C++中StringPiece::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::toString方法的具体用法?C++ StringPiece::toString怎么用?C++ StringPiece::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringPiece
的用法示例。
在下文中一共展示了StringPiece::toString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
ErrorCode WdtUri::process(const string& url) {
if (url.size() < WDT_URL_PREFIX.size()) {
LOG(ERROR) << "Url doesn't specify wdt protocol";
return URI_PARSE_ERROR;
}
StringPiece urlPiece(url, 0, WDT_URL_PREFIX.size());
StringPiece wdtPrefix(WDT_URL_PREFIX);
if (urlPiece != wdtPrefix) {
LOG(ERROR) << "Url does not specify wdt protocol " << url;
return URI_PARSE_ERROR;
}
urlPiece = StringPiece(url, WDT_URL_PREFIX.size());
size_t paramsIndex = urlPiece.find("?");
if (paramsIndex == string::npos) {
paramsIndex = urlPiece.size();
}
ErrorCode status = OK;
hostName_.assign(urlPiece.data(), paramsIndex);
if (hostName_.size() == 0) {
LOG(ERROR) << "URL doesn't have a valid host name " << url;
status = URI_PARSE_ERROR;
}
urlPiece.advance(paramsIndex + (paramsIndex < urlPiece.size()));
while (!urlPiece.empty()) {
StringPiece keyValuePair = urlPiece.split_step('&');
if (keyValuePair.empty()) {
// Last key value pair
keyValuePair = urlPiece;
urlPiece.advance(urlPiece.size());
}
StringPiece key = keyValuePair.split_step('=');
StringPiece value = keyValuePair;
if (key.empty()) {
// Value can be empty but key can't be empty
LOG(ERROR) << "Errors parsing params, url = " << url;
status = URI_PARSE_ERROR;
break;
}
queryParams_[key.toString()] = value.toString();
}
return status;
}
示例2: ZipFileCollection
std::unique_ptr<ZipFileCollection> ZipFileCollection::create(const StringPiece& path,
std::string* outError) {
constexpr static const int32_t kEmptyArchive = -6;
std::unique_ptr<ZipFileCollection> collection = std::unique_ptr<ZipFileCollection>(
new ZipFileCollection());
int32_t result = OpenArchive(path.data(), &collection->mHandle);
if (result != 0) {
// If a zip is empty, result will be an error code. This is fine and we should
// return an empty ZipFileCollection.
if (result == kEmptyArchive) {
return collection;
}
if (outError) *outError = ErrorCodeString(result);
return {};
}
void* cookie = nullptr;
result = StartIteration(collection->mHandle, &cookie, nullptr, nullptr);
if (result != 0) {
if (outError) *outError = ErrorCodeString(result);
return {};
}
using IterationEnder = std::unique_ptr<void, decltype(EndIteration)*>;
IterationEnder iterationEnder(cookie, EndIteration);
ZipString zipEntryName;
ZipEntry zipData;
while ((result = Next(cookie, &zipData, &zipEntryName)) == 0) {
std::string zipEntryPath = std::string(reinterpret_cast<const char*>(zipEntryName.name),
zipEntryName.name_length);
std::string nestedPath = path.toString() + "@" + zipEntryPath;
collection->mFiles[zipEntryPath] = util::make_unique<ZipFile>(collection->mHandle,
zipData,
Source(nestedPath));
}
if (result != -1) {
if (outError) *outError = ErrorCodeString(result);
return {};
}
return collection;
}
示例3: FbossError
shared_ptr<SwitchState> applyThriftConfigFile(
const shared_ptr<SwitchState>& state,
StringPiece path,
const Platform* platform) {
// Parse the JSON config.
//
// This is basically what configerator's getConfigAndParse() code does,
// except that we manually read the file from disk for now.
// We may not be able to rely on the configerator infrastructure for
// distributing the config files.
cfg::SwitchConfig config;
std::string contents;
if (!folly::readFile(path.toString().c_str(), contents)) {
throw FbossError("unable to read ", path);
}
config.readFromJson(contents.c_str());
return ThriftConfigApplier(state, &config, platform).run();
}