本文整理匯總了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;
}