aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-06-22 18:24:15 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-06-26 19:59:14 +0800
commitc45dbab00cbe3c8af61695a1fc095612e089358a (patch)
treec6a4e11cda19ed2e495b36c65e19226d0c20eea2
parent6488f7e0795a77e4175361e3cb7270b47168a22a (diff)
downloaddexon-solidity-c45dbab00cbe3c8af61695a1fc095612e089358a.tar.gz
dexon-solidity-c45dbab00cbe3c8af61695a1fc095612e089358a.tar.zst
dexon-solidity-c45dbab00cbe3c8af61695a1fc095612e089358a.zip
Rewrite validateUTF8 to use char
-rw-r--r--libdevcore/UTF8.cpp18
1 files changed, 11 insertions, 7 deletions
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<unsigned char const*>(_input.c_str()), _input.length(), _invalidPosition);
+}
+
+}