本文整理汇总了C++中StringPiece::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::empty方法的具体用法?C++ StringPiece::empty怎么用?C++ StringPiece::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringPiece
的用法示例。
在下文中一共展示了StringPiece::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SplitStringKeepEmpty
void SplitStringKeepEmpty(
const StringPiece& full,
const StringPiece& delim,
std::vector<std::string>* result)
{
// 单个字符的分隔符转调字符版本的分割函数,要快一些
if (delim.length() == 1)
{
SplitStringKeepEmpty(full, delim[0], result);
return;
}
result->clear();
if (full.empty() || delim.empty())
return;
size_t prev_pos = 0;
size_t pos;
std::string token;
while ((pos = full.find(delim, prev_pos)) != std::string::npos)
{
token.assign(full.data() + prev_pos, pos - prev_pos);
result->push_back(token);
prev_pos = pos + delim.length();
}
token.assign(full.data() + prev_pos, full.length() - prev_pos);
result->push_back(token);
}
示例2: if
size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
const StringPiece& needles) {
if (UNLIKELY(needles.empty() || haystack.empty())) {
return StringPiece::npos;
} else if (needles.size() <= 16) {
// we can save some unnecessary load instructions by optimizing for
// the common case of needles.size() <= 16
return qfind_first_byte_of_needles16(haystack, needles);
}
size_t index = haystack.size();
for (size_t i = 0; i < haystack.size(); i += 16) {
size_t b = 16;
auto arr1 = __builtin_ia32_loaddqu(haystack.data() + i);
for (size_t j = 0; j < needles.size(); j += 16) {
auto arr2 = __builtin_ia32_loaddqu(needles.data() + j);
auto index = __builtin_ia32_pcmpestri128(arr2, needles.size() - j,
arr1, haystack.size() - i, 0);
b = std::min<size_t>(index, b);
}
if (b < 16) {
return i + b;
}
};
return StringPiece::npos;
}
示例3: qfind_first_of
size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
const StringPiece& needles) {
if (UNLIKELY(needles.empty() || haystack.empty())) {
return StringPiece::npos;
} else if (needles.size() <= 16) {
// we can save some unnecessary load instructions by optimizing for
// the common case of needles.size() <= 16
return qfind_first_byte_of_needles16(haystack, needles);
}
if (haystack.size() < 16 &&
PAGE_FOR(haystack.end() - 1) != PAGE_FOR(haystack.data() + 16)) {
// We can't safely SSE-load haystack. Use a different approach.
if (haystack.size() <= 2) {
return qfind_first_of(haystack, needles, asciiCaseSensitive);
}
return qfind_first_byte_of_byteset(haystack, needles);
}
auto ret = scanHaystackBlock<false>(haystack, needles, 0);
if (ret != StringPiece::npos) {
return ret;
}
size_t i = nextAlignedIndex(haystack.data());
for (; i < haystack.size(); i += 16) {
auto ret = scanHaystackBlock<true>(haystack, needles, i);
if (ret != StringPiece::npos) {
return ret;
}
}
return StringPiece::npos;
}
示例4: 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;
}
示例5: 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;
}
示例6: getParent
StringPiece LogName::getParent(StringPiece name) {
if (name.empty()) {
return name;
}
ssize_t idx = name.size();
// Skip over any trailing separator characters
while (idx > 0 && isSeparator(name[idx - 1])) {
--idx;
}
// Now walk backwards to the next separator character
while (idx > 0 && !isSeparator(name[idx - 1])) {
--idx;
}
// And again skip over any separator characters, in case there are multiple
// repeated characters.
while (idx > 0 && isSeparator(name[idx - 1])) {
--idx;
}
return StringPiece(name.begin(), idx);
}
示例7: wdtUri
WdtTransferRequest::WdtTransferRequest(const string& uriString) {
WdtUri wdtUri(uriString);
errorCode = wdtUri.getErrorCode();
hostName = wdtUri.getHostName();
transferId = wdtUri.getQueryParam(TRANSFER_ID_PARAM);
directory = wdtUri.getQueryParam(DIRECTORY_PARAM);
try {
protocolVersion =
folly::to<int64_t>(wdtUri.getQueryParam(PROTOCOL_VERSION_PARAM));
} catch (std::exception& e) {
LOG(ERROR) << "Error parsing protocol version "
<< wdtUri.getQueryParam(PROTOCOL_VERSION_PARAM);
errorCode = URI_PARSE_ERROR;
}
StringPiece portsList(wdtUri.getQueryParam(PORTS_PARAM));
do {
StringPiece portNum = portsList.split_step(',');
int port = 0;
if (!portNum.empty()) {
try {
port = folly::to<int32_t>(portNum);
ports.push_back(port);
} catch (std::exception& e) {
LOG(ERROR) << "Couldn't convert " << portNum << " to valid port number";
errorCode = URI_PARSE_ERROR;
}
}
} while (!portsList.empty());
}
示例8: StartDocument
bool XmlWriter::StartDocument(StringPiece encoding/*, IOStream *output*/) {
/* unsigned char UTF8_BOM[] = { 0xEF, 0xBB, 0xBF };
output->Write(UTF8_BOM, arraysize(UTF8_BOM)); */
if (encoding.empty())
encoding = StringPieceFromLiteral("UTF-8");
return (xmlTextWriterStartDocument(libxml_stuff->writer, NULL, encoding.data(), NULL) != -1);
}
示例9: TestFailedIterator
void BytesTrieTest::TestFailedIterator() {
UErrorCode failure = U_ILLEGAL_ARGUMENT_ERROR;
BytesTrie::Iterator iter(NULL, 0, failure);
StringPiece sp = iter.getString();
if (!sp.empty()) {
errln("failed iterator returned garbage data");
}
}
示例10: loadNBest
void Data::loadNBest(const string &file, bool oneBest)
{
TRACE_ERR("loading nbest from " << file << endl);
util::FilePiece in(file.c_str());
ScoreStats scoreentry;
string sentence, feature_str, alignment;
int sentence_index;
while (true) {
try {
StringPiece line = in.ReadLine();
if (line.empty()) continue;
// adding statistics for error measures
scoreentry.clear();
util::TokenIter<util::MultiCharacter> it(line, util::MultiCharacter("|||"));
sentence_index = ParseInt(*it);
if (oneBest && m_score_data->exists(sentence_index)) continue;
++it;
sentence = it->as_string();
++it;
feature_str = it->as_string();
++it;
if (it) {
++it; // skip model score.
if (it) {
alignment = it->as_string(); //fifth field (if present) is either phrase or word alignment
++it;
if (it) {
alignment = it->as_string(); //sixth field (if present) is word alignment
}
}
}
//TODO check alignment exists if scorers need it
if (m_scorer->useAlignment()) {
sentence += "|||";
sentence += alignment;
}
m_scorer->prepareStats(sentence_index, sentence, scoreentry);
m_score_data->add(scoreentry, sentence_index);
// examine first line for name of features
if (!existsFeatureNames()) {
InitFeatureMap(feature_str);
}
AddFeatures(feature_str, sentence_index);
} catch (util::EndOfFileException &e) {
PrintUserTime("Loaded N-best lists");
break;
}
}
}
示例11: initLogging
void initLogging(StringPiece configString) {
if (configString.empty()) {
return;
}
// Parse and apply the config string
auto config = parseLogConfig(configString);
LoggerDB::get().updateConfig(config);
}
示例12: 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);
}
}
示例13: qfind_first_byte_of_nosse
size_t qfind_first_byte_of_nosse(const StringPiece& haystack,
const StringPiece& needles) {
if (UNLIKELY(needles.empty() || haystack.empty())) {
return StringPiece::npos;
}
// The thresholds below were empirically determined by benchmarking.
// This is not an exact science since it depends on the CPU, the size of
// needles, and the size of haystack.
if (haystack.size() == 1 ||
(haystack.size() < 4 && needles.size() <= 16)) {
return qfind_first_of(haystack, needles, asciiCaseSensitive);
} else if ((needles.size() >= 4 && haystack.size() <= 10) ||
(needles.size() >= 16 && haystack.size() <= 64) ||
needles.size() >= 32) {
return qfind_first_byte_of_byteset(haystack, needles);
}
return qfind_first_byte_of_memchr(haystack, needles);
}
示例14: 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;
}
示例15: GetUnbinarizedChildren
//get the children of a node in a binarized tree; if a child is virtual, (transitively) replace it with its children
void InternalTree::GetUnbinarizedChildren(std::vector<TreePointer> &ret) const
{
for (std::vector<TreePointer>::const_iterator itx = m_children.begin(); itx != m_children.end(); ++itx) {
const StringPiece label = (*itx)->GetLabel().GetString(0);
if (!label.empty() && label.as_string()[0] == '^') {
(*itx)->GetUnbinarizedChildren(ret);
} else {
ret.push_back(*itx);
}
}
}