]> git.sesse.net Git - vlc/commitdiff
Unduplicate code
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 10 Feb 2011 17:43:58 +0000 (19:43 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 10 Feb 2011 17:50:49 +0000 (19:50 +0200)
src/config/keys.c
src/libvlc.h
src/text/unicode.c

index eb2e42f5529cbf84d3ea0925a7986c1c7c3c14c8..d8c7604e1b2be7d0f7e76dda3c039d47179b45cf 100644 (file)
@@ -32,6 +32,7 @@
 #include <vlc_common.h>
 #include <vlc_keys.h>
 #include "configuration.h"
+#include "libvlc.h"
 
 typedef struct key_descriptor_s
 {
@@ -147,31 +148,6 @@ static char *utf8_cp (uint_fast32_t cp, char *buf)
     return buf;
 }
 
-/* Convert UTF-8 to Unicode code point */
-static uint_fast32_t cp_utf8 (const char *utf8)
-{
-    uint8_t f = utf8[0];
-    size_t l = strlen (utf8);
-
-    if (f < 0x80) /* ASCII (7 bits) */
-        return f;
-    if (f < 0xC0 || l < 2) /* bad */
-        return 0;
-    if (f < 0xE0) /* two bytes (11 bits) */
-        return ((f & 0x1F) << 6) | (utf8[1] & 0x3F);
-    if (l < 3) /* bad */
-        return 0;
-    if (f < 0xF0) /* three bytes (16 bits) */
-        return ((f & 0x0F) << 12) | ((utf8[1] & 0x3F) << 6)
-               | (utf8[2] & 0x3F);
-    if (l < 4)
-        return 0;
-    if (f < 0xF8) /* four bytes (21 bits) */
-        return ((f & 0x07) << 18) | ((utf8[1] & 0x3F) << 12)
-               | ((utf8[2] & 0x3F) << 6) | (utf8[3] & 0x3F);
-    return 0;
-}
-
 char *KeyToString (uint_fast32_t sym)
 {
     key_descriptor_t *d;
@@ -191,6 +167,7 @@ char *KeyToString (uint_fast32_t sym)
 uint_fast32_t ConfigStringToKey (const char *name)
 {
     uint_fast32_t mods = 0;
+    uint32_t cp;
 
     for (;;)
     {
@@ -213,7 +190,7 @@ uint_fast32_t ConfigStringToKey (const char *name)
         if (!strcasecmp( vlc_keys[i].psz_key_string, name))
             return vlc_keys[i].i_key_code | mods;
 
-    return cp_utf8 (name) | mods;
+    return (vlc_towc (name, &cp) > 0) ? (mods | cp) : 0;
 }
 
 char *ConfigKeyToString (uint_fast32_t i_key)
index b515d611c193d5915e1bdef52e37c5ac924e0bcd..fda0b8fae06275d5e8c9b8230aec761bdc66143b 100644 (file)
@@ -38,6 +38,8 @@ extern const size_t libvlc_actions_count;
 extern int vlc_InitActions (libvlc_int_t *);
 extern void vlc_DeinitActions (libvlc_int_t *);
 
+size_t vlc_towc (const char *str, uint32_t *restrict pwc);
+
 /*
  * OS-specific initialization
  */
index 9745cf2ea7270761f6c2dbefdb95ed7ee17fbaeb..cad5aa7739cd7ddd8accb7020f1cd1f4e3081815 100644 (file)
@@ -221,7 +221,7 @@ int utf8_fprintf( FILE *stream, const char *fmt, ... )
  * number of bytes that the first character occupies (from 1 to 4) otherwise;
  * -1 if the byte sequence was not a valid UTF-8 sequence.
  */
-static size_t vlc_towc (const char *str, uint32_t *restrict pwc)
+size_t vlc_towc (const char *str, uint32_t *restrict pwc)
 {
     uint8_t *ptr = (uint8_t *)str;
     assert (str != NULL);