chiark / gitweb /
journald/server: replace readdir_r with readdir
[elogind.git] / src / shared / utf8.c
index c3d97cc783f06e2805a4a2394a162e87a3b8b0e1..6e5ba9abf4ad115b9fcc2d3e78fbef6e65664815 100644 (file)
@@ -3,6 +3,7 @@
 /***
   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
@@ -19,7 +20,7 @@
   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.
@@ -97,7 +98,7 @@ static int utf8_encoded_expected_len(const char *str) {
 }
 
 /* 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;
@@ -140,14 +141,15 @@ bool utf8_is_printable(const char* str, size_t length) {
 
         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;
@@ -159,7 +161,9 @@ const char *utf8_is_valid(const char *str) {
         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;
@@ -182,27 +186,6 @@ char *ascii_is_valid(const char *str) {
         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;