本文整理汇总了C++中Nibbler::skipWS方法的典型用法代码示例。如果您正苦于以下问题:C++ Nibbler::skipWS方法的具体用法?C++ Nibbler::skipWS怎么用?C++ Nibbler::skipWS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nibbler
的用法示例。
在下文中一共展示了Nibbler::skipWS方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
t.is (s, "on", " 'one two' : getUntilRx ('e') -> 'on'"); // 30
t.ok (n.getUntilRx ("tw", s), " 'e two' : getUntilRx ('tw') -> true");
t.is (s, "e ", " 'e two' : getUntilRx ('tw') -> 'e '");
t.ok (n.getUntilRx ("$", s), " 'two' : getUntilRx ('$') -> true");
t.is (s, "two", " 'two' : getUntilRx ('$') -> 'two'");
t.ok (n.depleted (), " '' : depleted () -> true");
#endif
// bool getUntilOneOf (const std::string&, std::string&);
t.diag ("Nibbler::getUntilOneOf");
n = Nibbler ("ab.cd");
t.ok (n.getUntilOneOf (".:", s), " 'ab.cd' : getUntilOneOf ('.:') -> true");
t.is (s, "ab", " 'ab.cd' : getUntilOneOf ('.:') -> 'ab'");
t.ok (n.skipN (), " '.cd' : skipN () -> true");
t.ok (n.getUntilOneOf (".:", s), " 'cd' : getUntilOneOf ('.:') -> true");
t.notok (n.getUntilOneOf (".:", s), " '' : getUntilOneOf ('.:') -> false");
t.ok (n.depleted (), " '' : depleted () -> true");
// bool getUntil (const std::string&, std::string&);
t.diag ("Nibbler::getUntil");
n = Nibbler ("ab\r\ncd");
t.ok (n.getUntil ("\r\n", s), "'ab\\r\\ncd' : getUntil ('\\r\\n') -> true");
t.ok (n.skipN (2), " '\\r\\ncd' : skipN (2) -> true");
t.ok (n.getUntil ("\r\n", s), " 'cd' : getUntil ('\\r\\n') -> true");
t.ok (n.depleted (), " '' : depleted () -> true");
// bool getUntilWS (std::string&);
t.diag ("Nibbler::getUntilWS");
n = Nibbler ("ab \t\ncd");
t.ok (n.getUntilWS (s), " 'ab \\t\\ncd' : getUntilWS () -> true");
t.is (s, "ab", " 'ab \\t\\ncd' : getUntilWS () -> 'ab'");
t.ok (n.getUntilWS (s), " ' \\t\\ncd' : getUntilWS () -> true");
t.is (s, "", " ' \\t\\ncd' : getUntilWS () -> ''");
t.ok (n.skipWS (), " 'cd' : skipWS () -> true");
t.ok (n.getUntilWS (s), " '' : getUntilWS () -> true");
t.is (s, "cd", " 'cd' : getUntilWS () -> 'cd'");
t.ok (n.depleted (), " '' : depleted () -> true");
// bool skipN (const int quantity = 1);
t.diag ("Nibbler::skipN");
n = Nibbler ("abcde");
t.ok (n.skipN (), " 'abcde' : skipN () -> true");
t.ok (n.skipN (2), " 'bcde' : skipN (2 -> true");
t.notok (n.skipN (3), " 'de' : skipN (3 -> false");
t.notok (n.depleted (), " 'de' : depleted () -> true");
// bool skip (char);
t.diag ("Nibbler::skip");
n = Nibbler (" a");
t.ok (n.skip (' '), " ' a' : skip (' ') -> true");
t.ok (n.skip (' '), " ' a' : skip (' ') -> true");
t.notok (n.skip (' '), " 'a' : skip (' ') -> false");
t.notok (n.depleted (), " 'a' : depleted () -> false");
t.ok (n.skip ('a'), " 'a' : skip ('a') -> true");
t.ok (n.depleted (), " '' : depleted () -> true");
// bool skipAll (char);
t.diag ("Nibbler::skipAll");
n = Nibbler ("aaaabb");
t.ok (n.skipAll ('a'), " 'aaaabb' : skipAll ('a') -> true");
t.notok (n.skipAll ('a'), " 'bb' : skipAll ('a') -> false");
t.ok (n.skipAll ('b'), " 'bb' : skipAll ('b') -> true");
t.notok (n.skipAll ('b'), " '' : skipAll ('b') -> false");
t.ok (n.depleted (), " '' : depleted () -> true");
// bool skipAllOneOf (const std::string&);
示例2: 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;
}