diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 0f53354ed..99a22cb9b 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -385,6 +385,28 @@ int Lexer::commonLength (const std::string& left, const std::string& right) 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 // '|" diff --git a/src/Lexer.h b/src/Lexer.h index f6db6e168..742dedd54 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -86,6 +86,7 @@ public: static int hexToInt (int, int); static int hexToInt (int, int, int, int); 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;