mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Pig: Removed unnecessary _mark, _debug
This commit is contained in:
parent
eaf038f50e
commit
b19496b63d
3 changed files with 7 additions and 24 deletions
20
src/Pig.cpp
20
src/Pig.cpp
|
@ -33,15 +33,15 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Pig::Pig (const std::string& text)
|
Pig::Pig (const std::string& text)
|
||||||
: _text (text)
|
: _text (text)
|
||||||
, _mark (0)
|
|
||||||
, _cursor (0)
|
, _cursor (0)
|
||||||
, _debug (false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Pig::skipWS ()
|
bool Pig::skipWS ()
|
||||||
{
|
{
|
||||||
|
auto save = _cursor;
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
auto prev = _cursor;
|
auto prev = _cursor;
|
||||||
while ((c = utf8_next_char (_text, _cursor)))
|
while ((c = utf8_next_char (_text, _cursor)))
|
||||||
|
@ -54,13 +54,7 @@ bool Pig::skipWS ()
|
||||||
prev = _cursor;
|
prev = _cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_cursor > _mark)
|
return _cursor > save;
|
||||||
{
|
|
||||||
_mark = _cursor;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -71,26 +65,18 @@ bool Pig::getDigit (int& result)
|
||||||
{
|
{
|
||||||
result = c - '0';
|
result = c - '0';
|
||||||
++_cursor;
|
++_cursor;
|
||||||
++_mark;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void Pig::debug (bool value)
|
|
||||||
{
|
|
||||||
_debug = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string Pig::dump () const
|
std::string Pig::dump () const
|
||||||
{
|
{
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "≪" << _text << "≫"
|
out << "≪" << _text << "≫"
|
||||||
<< " l" << _text.length ()
|
<< " l" << _text.length ()
|
||||||
<< " m" << _mark
|
|
||||||
<< " c" << _cursor;
|
<< " c" << _cursor;
|
||||||
|
|
||||||
return out.str ();
|
return out.str ();
|
||||||
|
|
|
@ -38,14 +38,11 @@ public:
|
||||||
|
|
||||||
bool getDigit (int&);
|
bool getDigit (int&);
|
||||||
|
|
||||||
void debug (bool);
|
|
||||||
std::string dump () const;
|
std::string dump () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string& _text;
|
const std::string& _text;
|
||||||
std::string::size_type _mark;
|
|
||||||
std::string::size_type _cursor;
|
std::string::size_type _cursor;
|
||||||
bool _debug;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,11 +36,11 @@ int main (int, char**)
|
||||||
// Pig::skipWS
|
// Pig::skipWS
|
||||||
Pig p0 (" one");
|
Pig p0 (" one");
|
||||||
t.ok (p0.skipWS (), "skipWS ' one' -> true");
|
t.ok (p0.skipWS (), "skipWS ' one' -> true");
|
||||||
t.is (p0.dump (), "≪ one≫ l5 m2 c2", "dump");
|
t.is (p0.dump (), "≪ one≫ l5 c2", "dump");
|
||||||
t.diag (p0.dump ());
|
t.diag (p0.dump ());
|
||||||
|
|
||||||
t.notok (p0.skipWS (), "skipWS 'one' -> false");
|
t.notok (p0.skipWS (), "skipWS 'one' -> false");
|
||||||
t.is (p0.dump (), "≪ one≫ l5 m2 c2", "dump");
|
t.is (p0.dump (), "≪ one≫ l5 c2", "dump");
|
||||||
t.diag (p0.dump ());
|
t.diag (p0.dump ());
|
||||||
|
|
||||||
// Pig::getDigit
|
// Pig::getDigit
|
||||||
|
@ -48,11 +48,11 @@ int main (int, char**)
|
||||||
int n;
|
int n;
|
||||||
t.notok (p1.getDigit (n), "getDigit ' 123' --> false");
|
t.notok (p1.getDigit (n), "getDigit ' 123' --> false");
|
||||||
t.ok (p1.skipWS (), "skipWS ' 123' --> true");
|
t.ok (p1.skipWS (), "skipWS ' 123' --> true");
|
||||||
t.is (p1.dump (), "≪ 123≫ l4 m1 c1", "dump");
|
t.is (p1.dump (), "≪ 123≫ l4 c1", "dump");
|
||||||
t.diag (p1.dump ());
|
t.diag (p1.dump ());
|
||||||
t.ok (p1.getDigit (n), "getDigit '123' --> true");
|
t.ok (p1.getDigit (n), "getDigit '123' --> true");
|
||||||
t.is (n, 1, "getDigit '123' --> '1'");
|
t.is (n, 1, "getDigit '123' --> '1'");
|
||||||
t.is (p1.dump (), "≪ 123≫ l4 m2 c2", "dump");
|
t.is (p1.dump (), "≪ 123≫ l4 c2", "dump");
|
||||||
t.diag (p1.dump ());
|
t.diag (p1.dump ());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue