Lexer:: Implemented ::commonLength with offsets, for embedded parsing

This commit is contained in:
Paul Beckingham 2015-07-27 00:04:00 -04:00
parent 244c81a647
commit a9b701ae6d
2 changed files with 23 additions and 0 deletions

View file

@ -385,6 +385,28 @@ int Lexer::commonLength (const std::string& left, const std::string& right)
return (int) l; return (int) l;
} }
////////////////////////////////////////////////////////////////////////////////
// Compares two strings with offsets, and returns the number bytes in common.
//
// left: wonderful
// l: ^
// right: prowonderbread
// r: ^
// returns: ^ 6
int Lexer::commonLength (
const std::string& left,
std::string::size_type l,
const std::string& right,
std::string::size_type r)
{
while (left[l] == right[r] &&
utf8_next_char (left, l) &&
utf8_next_char (right, r))
;
return (int) l;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Lexer::Type::string // Lexer::Type::string
// '|" // '|"

View file

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