mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Rewrite validateUTF8 to use char
This commit is contained in:
parent
6488f7e079
commit
c45dbab00c
@ -70,18 +70,15 @@ bool isWellFormed(unsigned char byte1, unsigned char byte2)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
bool validateUTF8(const unsigned char *_input, size_t _length, size_t& _invalidPosition)
|
||||||
|
|
||||||
bool validateUTF8(std::string const& _input, size_t& _invalidPosition)
|
|
||||||
{
|
{
|
||||||
const size_t length = _input.length();
|
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
for (; i < length; i++)
|
for (; i < _length; i++)
|
||||||
{
|
{
|
||||||
// Check for Unicode Chapter 3 Table 3-6 conformity.
|
// Check for Unicode Chapter 3 Table 3-6 conformity.
|
||||||
if ((unsigned char)_input[i] < 0x80)
|
if (_input[i] < 0x80)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
@ -106,7 +103,7 @@ bool validateUTF8(std::string const& _input, size_t& _invalidPosition)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((i + count) >= length)
|
if ((i + count) >= _length)
|
||||||
{
|
{
|
||||||
valid = false;
|
valid = false;
|
||||||
break;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user