diff --git a/src/Lexer.cpp b/src/Lexer.cpp index d841b6b97..0f53354ed 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -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 // '|" diff --git a/src/Lexer.h b/src/Lexer.h index f92582131..f6db6e168 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -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;