Pig: Added ::getOneOf

This commit is contained in:
Paul Beckingham 2015-12-30 10:59:14 -05:00
parent 544a1d67d0
commit edda82fafe
2 changed files with 22 additions and 0 deletions

View file

@ -263,6 +263,26 @@ bool Pig::getNumber (double& result)
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Assumes that the options are sorted by decreasing length, so that if the
// options contain 'fourteen' and 'four', the stream is first matched against
// the longer entry.
bool Pig::getOneOf (
const std::vector <std::string>& options,
std::string& found)
{
for (auto& option : options)
{
if (skipLiteral (option))
{
found = option;
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool Pig::getRemainder (std::string& result)
{

View file

@ -28,6 +28,7 @@
#define INCLUDED_PIG
#include <string>
#include <vector>
class Pig
{
@ -44,6 +45,7 @@ public:
bool getDigits (int&);
bool getNumber (std::string&);
bool getNumber (double&);
bool getOneOf (const std::vector <std::string>&, std::string&);
bool getRemainder (std::string&);
bool eos () const;