本文整理汇总了C++中Nibbler::cursor方法的典型用法代码示例。如果您正苦于以下问题:C++ Nibbler::cursor方法的具体用法?C++ Nibbler::cursor怎么用?C++ Nibbler::cursor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nibbler
的用法示例。
在下文中一共展示了Nibbler::cursor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
bool Duration::parse (const std::string& input, std::string::size_type& start)
{
std::string::size_type original_start = start;
Nibbler n (input.substr (start));
// Static and so preserved between calls.
static std::vector <std::string> units;
if (units.size () == 0)
for (unsigned int i = 0; i < NUM_DURATIONS; i++)
units.push_back (durations[i].unit);
std::string number;
std::string unit;
if (n.getOneOf (units, unit))
{
if (n.depleted () ||
Lexer::isWhitespace (n.next ()))
{
start = original_start + n.cursor ();
// Linear lookup - should be logarithmic.
for (unsigned int i = 0; i < NUM_DURATIONS; i++)
{
if (durations[i].unit == unit &&
durations[i].standalone == true)
{
_secs = static_cast <int> (durations[i].seconds);
return true;
}
}
}
}
else if (n.getNumber (number))
{
n.skipWS ();
if (n.getOneOf (units, unit))
{
if (n.depleted () ||
Lexer::isWhitespace (n.next ()))
{
start = original_start + n.cursor ();
double quantity = strtod (number.c_str (), NULL);
// Linear lookup - should be logarithmic.
double seconds = 1;
for (unsigned int i = 0; i < NUM_DURATIONS; i++)
{
if (durations[i].unit == unit)
{
seconds = durations[i].seconds;
_secs = static_cast <int> (quantity * static_cast <double> (seconds));
return true;
}
}
}
}
}
return false;
}