utf8: update utf8_is_valid() a bit

Let's avoid a few casts in the function. Also, let's drop the "const"
when returning the string, for similar reasons as strchr() and friends
drop it: so that we don't add a const if the user passes in a non-const
string.
This commit is contained in:
Lennart Poettering
2018-09-25 15:57:47 +02:00
parent 2b5d05fdfe
commit e71fb4b302
2 changed files with 7 additions and 6 deletions
+6 -5
View File
@@ -154,22 +154,23 @@ bool utf8_is_printable_newline(const char* str, size_t length, bool newline) {
return true;
}
const char *utf8_is_valid(const char *str) {
const uint8_t *p;
char *utf8_is_valid(const char *str) {
const char *p;
assert(str);
for (p = (const uint8_t*) str; *p; ) {
p = str;
while (*p) {
int len;
len = utf8_encoded_valid_unichar((const char *)p);
len = utf8_encoded_valid_unichar(p);
if (len < 0)
return NULL;
p += len;
}
return str;
return (char*) str;
}
char *utf8_escape_invalid(const char *str) {
+1 -1
View File
@@ -14,7 +14,7 @@
bool unichar_is_valid(char32_t c);
const char *utf8_is_valid(const char *s) _pure_;
char *utf8_is_valid(const char *s) _pure_;
char *ascii_is_valid(const char *s) _pure_;
char *ascii_is_valid_n(const char *str, size_t len);