From c45dbab00cbe3c8af61695a1fc095612e089358a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 22 Jun 2017 11:24:15 +0100 Subject: Rewrite validateUTF8 to use char --- libdevcore/UTF8.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/UTF8.cpp b/libdevcore/UTF8.cpp index ad62c8b0..affe64b2 100644 --- a/libdevcore/UTF8.cpp +++ b/libdevcore/UTF8.cpp @@ -70,18 +70,15 @@ bool isWellFormed(unsigned char byte1, unsigned char byte2) return true; } -} - -bool validateUTF8(std::string const& _input, size_t& _invalidPosition) +bool validateUTF8(const unsigned char *_input, size_t _length, size_t& _invalidPosition) { - const size_t length = _input.length(); bool valid = true; size_t i = 0; - for (; i < length; i++) + for (; i < _length; i++) { // Check for Unicode Chapter 3 Table 3-6 conformity. - if ((unsigned char)_input[i] < 0x80) + if (_input[i] < 0x80) continue; size_t count = 0; @@ -106,7 +103,7 @@ bool validateUTF8(std::string const& _input, size_t& _invalidPosition) break; } - if ((i + count) >= length) + if ((i + count) >= _length) { valid = false; break; @@ -138,3 +135,10 @@ bool validateUTF8(std::string const& _input, size_t& _invalidPosition) } } + +bool validateUTF8(std::string const& _input, size_t& _invalidPosition) +{ + return validateUTF8(reinterpret_cast(_input.c_str()), _input.length(), _invalidPosition); +} + +} -- cgit v1.2.3