Lexer: Implemented ::commonLength for word root comparison

This commit is contained in:
Paul Beckingham 2015-07-26 23:43:40 -04:00
parent f5792a03fb
commit 244c81a647
2 changed files with 19 additions and 0 deletions

View file

@ -367,6 +367,24 @@ int Lexer::hexToInt (int c0, int c1, int c2, int c3)
hexToInt (c3);
}
////////////////////////////////////////////////////////////////////////////////
// Compares two strings, and returns the number bytes in common.
//
// left: wonderful
// right: wonderbread
// returns: ^ 6
int Lexer::commonLength (const std::string& left, const std::string& right)
{
std::string::size_type l = 0;
std::string::size_type r = 0;
while (left[l] == right[r] &&
utf8_next_char (left, l) &&
utf8_next_char (right, r))
;
return (int) l;
}
////////////////////////////////////////////////////////////////////////////////
// Lexer::Type::string
// '|"

View file

@ -85,6 +85,7 @@ public:
static int hexToInt (int);
static int hexToInt (int, int);
static int hexToInt (int, int, int, int);
static int commonLength (const std::string&, const std::string&);
bool isEOS () const;