[vlc-commits] Unduplicate code

Rémi Denis-Courmont git at videolan.org
Thu Feb 10 19:21:26 CET 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Feb 10 19:43:58 2011 +0200| [09110552c1734f270521eeb57e2dae3bde13e50f] | committer: Rémi Denis-Courmont

Unduplicate code

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=09110552c1734f270521eeb57e2dae3bde13e50f
---

 src/config/keys.c  |   29 +++--------------------------
 src/libvlc.h       |    2 ++
 src/text/unicode.c |    2 +-
 3 files changed, 6 insertions(+), 27 deletions(-)

diff --git a/src/config/keys.c b/src/config/keys.c
index eb2e42f..d8c7604 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -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)
diff --git a/src/libvlc.h b/src/libvlc.h
index b515d61..fda0b8f 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -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
  */
diff --git a/src/text/unicode.c b/src/text/unicode.c
index 9745cf2..cad5aa7 100644
--- a/src/text/unicode.c
+++ b/src/text/unicode.c
@@ -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);



More information about the vlc-commits mailing list