本文整理汇总了C++中boost::string_ref::remove_prefix方法的典型用法代码示例。如果您正苦于以下问题:C++ string_ref::remove_prefix方法的具体用法?C++ string_ref::remove_prefix怎么用?C++ string_ref::remove_prefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::string_ref
的用法示例。
在下文中一共展示了string_ref::remove_prefix方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: marker
SimpleTemplate::SimpleTemplate(boost::string_ref text)
{
static char const rawMarker[] = "@@";
static boost::string_ref const marker(rawMarker, sizeof(rawMarker) - 1);
auto beg = text.find(marker);
while (beg != boost::string_ref::npos) {
m_literals.emplace_back(text.data(), beg);
text.remove_prefix(beg + marker.size());
auto end = text.find(marker);
if (end == boost::string_ref::npos) {
std::string& lit = m_literals.back();
lit.reserve(lit.size() + marker.size() + text.size());
lit.append(marker.data(), marker.size());
lit.append(text.data(), text.size());
assert(m_literals.size() == m_insertionKeys.size() + 1);
return;
}
m_insertionKeys.emplace_back(text.data(), end);
text.remove_prefix(end + marker.size());
beg = text.find(marker);
}
m_literals.emplace_back(text.data(), text.size());
assert(m_literals.size() == m_insertionKeys.size() + 1);
}
示例2: ParseDouble
double CInfixExpressionCalculator::ParseDouble(boost::string_ref &ref)
{
SkipSpaces(ref);
double value = 0;
bool parsedAny = false;
while (!ref.empty() && std::isdigit(ref[0]))
{
parsedAny = true;
const int digit = ref[0] - '0';
value = value * 10.0 + double(digit);
ref.remove_prefix(1);
}
if (!parsedAny)
{
return std::numeric_limits<double>::quiet_NaN();
}
if (ref.empty() || (ref[0] != '.'))
{
return value;
}
ref.remove_prefix(1);
double factor = 1.0;
while (!ref.empty() && std::isdigit(ref[0]))
{
const int digit = ref[0] - '0';
factor *= 0.1;
value += factor * double(digit);
ref.remove_prefix(1);
}
return value;
}
示例3: ParseExprSum
double CInfixExpressionCalculator::ParseExprSum(boost::string_ref &ref)
{
double value = ParseExprMul(ref);
while (true)
{
SkipSpaces(ref);
if (!ref.empty() && ref[0] == '+')
{
ref.remove_prefix(1);
value += ParseExprMul(ref);
}
else if (!ref.empty() && ref[0] == '-')
{
ref.remove_prefix(1);
value -= ParseExprMul(ref);
}
else
{
break;
}
}
return value;
}
示例4: SkipSpaces
void CInfixExpressionCalculator::SkipSpaces(boost::string_ref &ref)
{
size_t i = 0;
while (i < ref.size() && std::isspace(ref[i]))
++i;
ref.remove_prefix(i);
}
示例5:
inline boost::string_ref remove_leading_spaces(boost::string_ref string, const char* spaces = " \t\r\n")
{
auto pos = string.find_first_not_of(spaces);
if (pos == std::string::npos) pos = string.size();
string.remove_prefix(pos);
return string;
}