/***
This file is part of systemd.
+ Copyright 2008-2011 Kay Sievers
Copyright 2012 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-/* This file is based on the GLIB utf8 validation functions. The
+/* Parts of this file are based on the GLIB utf8 validation functions. The
* original license text follows. */
/* gutf8.c - Operations on UTF-8 strings.
}
/* decode one unicode char */
-static int utf8_encoded_to_unichar(const char *str) {
+int utf8_encoded_to_unichar(const char *str) {
int unichar;
int len;
int i;
assert(str);
- for (p = (const uint8_t*) str; length; p++) {
+ for (p = (const uint8_t*) str; length;) {
int encoded_len = utf8_encoded_valid_unichar((const char *)p);
- int32_t val = utf8_encoded_to_unichar((const char*)p);
+ int val = utf8_encoded_to_unichar((const char*)p);
if (encoded_len < 0 || val < 0 || is_unicode_control(val))
return false;
length -= encoded_len;
+ p += encoded_len;
}
return true;
assert(str);
for (p = (const uint8_t*) str; *p; ) {
- int len = utf8_encoded_valid_unichar((const char *)p);
+ int len;
+
+ len = utf8_encoded_valid_unichar((const char *)p);
if (len < 0)
return NULL;
return (char*) str;
}
-char *ascii_filter(const char *str) {
- const char *s;
- char *r, *d;
- size_t l;
-
- assert(str);
-
- l = strlen(str);
- r = malloc(l + 1);
- if (!r)
- return NULL;
-
- for (s = str, d = r; *s; s++)
- if ((unsigned char) *s < 128)
- *(d++) = *s;
-
- *d = 0;
-
- return r;
-}
-
char *utf16_to_utf8(const void *s, size_t length) {
char *r;
const uint8_t *f;