Pig: Removed unnecessary _mark, _debug

This commit is contained in:
Paul Beckingham 2015-12-29 15:57:20 -05:00
parent eaf038f50e
commit b19496b63d
3 changed files with 7 additions and 24 deletions

View file

@ -33,15 +33,15 @@
////////////////////////////////////////////////////////////////////////////////
Pig::Pig (const std::string& text)
: _text (text)
, _mark (0)
, _cursor (0)
, _debug (false)
{
}
////////////////////////////////////////////////////////////////////////////////
bool Pig::skipWS ()
{
auto save = _cursor;
int c;
auto prev = _cursor;
while ((c = utf8_next_char (_text, _cursor)))
@ -54,13 +54,7 @@ bool Pig::skipWS ()
prev = _cursor;
}
if (_cursor > _mark)
{
_mark = _cursor;
return true;
}
return false;
return _cursor > save;
}
////////////////////////////////////////////////////////////////////////////////
@ -71,26 +65,18 @@ bool Pig::getDigit (int& result)
{
result = c - '0';
++_cursor;
++_mark;
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
void Pig::debug (bool value)
{
_debug = value;
}
////////////////////////////////////////////////////////////////////////////////
std::string Pig::dump () const
{
std::stringstream out;
out << "" << _text << ""
<< " l" << _text.length ()
<< " m" << _mark
<< " c" << _cursor;
return out.str ();

View file

@ -38,14 +38,11 @@ public:
bool getDigit (int&);
void debug (bool);
std::string dump () const;
private:
const std::string& _text;
std::string::size_type _mark;
std::string::size_type _cursor;
bool _debug;
};
#endif

View file

@ -36,11 +36,11 @@ int main (int, char**)
// Pig::skipWS
Pig p0 (" one");
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.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 ());
// Pig::getDigit
@ -48,11 +48,11 @@ int main (int, char**)
int n;
t.notok (p1.getDigit (n), "getDigit ' 123' --> false");
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.ok (p1.getDigit (n), "getDigit '123' --> true");
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 ());
return 0;