Use consts in dev::utf8::validate()

This commit is contained in:
Alex Beregszaszi 2016-08-08 19:12:11 +01:00
parent e8c2e87397
commit c157163441
2 changed files with 7 additions and 7 deletions

View File

@ -31,19 +31,19 @@ namespace utf8
{ {
bool validate(std::string input, int &invalidPosition) bool validate(std::string const& _input, int& _invalidPosition)
{ {
const int length = input.length(); const int length = _input.length();
bool valid = true; bool valid = true;
int i = 0; int i = 0;
for (; i < length; i++) for (; i < length; i++)
{ {
if ((unsigned char)input[i] < 0x80) if ((unsigned char)_input[i] < 0x80)
continue; continue;
int count = 0; int count = 0;
switch(input[i] & 0xe0) { switch(_input[i] & 0xe0) {
case 0xc0: count = 1; break; case 0xc0: count = 1; break;
case 0xe0: count = 2; break; case 0xe0: count = 2; break;
case 0xf0: count = 3; break; case 0xf0: count = 3; break;
@ -65,7 +65,7 @@ bool validate(std::string input, int &invalidPosition)
for (int j = 0; j < count; j++) for (int j = 0; j < count; j++)
{ {
i++; i++;
if ((input[i] & 0xc0) != 0x80) if ((_input[i] & 0xc0) != 0x80)
{ {
valid = false; valid = false;
break; break;
@ -76,7 +76,7 @@ bool validate(std::string input, int &invalidPosition)
if (valid) if (valid)
return true; return true;
invalidPosition = i; _invalidPosition = i;
return false; return false;
} }

View File

@ -33,7 +33,7 @@ namespace utf8
/// Validate an input for UTF8 encoding /// Validate an input for UTF8 encoding
/// @returns true if it is invalid and the first invalid position in invalidPosition /// @returns true if it is invalid and the first invalid position in invalidPosition
bool validate(std::string input, int &invalidPosition); bool validate(std::string const& _input, int& _invalidPosition);
} }