[polypaudio-commits] r931 - in /trunk: configure.ac src/polyp/utf8.c src/polyp/utf8.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Thu May 18 01:19:08 PDT 2006
Author: ossman
Date: Thu May 18 10:19:07 2006
New Revision: 931
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=931&root=polypaudio&view=rev
Log:
And functions for convertion to and from current locale and UTF-8.
Modified:
trunk/configure.ac
trunk/src/polyp/utf8.c
trunk/src/polyp/utf8.h
Modified: trunk/configure.ac
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/configure.ac?rev=931&root=polypaudio&r1=930&r2=931&view=diff
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Thu May 18 10:19:07 2006
@@ -156,7 +156,7 @@
AC_HEADER_STDC
# POSIX
-AC_CHECK_HEADERS([arpa/inet.h glob.h grp.h netdb.h netinet/in.h \
+AC_CHECK_HEADERS([arpa/inet.h glob.h grp.h iconv.h netdb.h netinet/in.h \
netinet/in_systm.h netinet/ip.h netinet/tcp.h pwd.h sched.h \
sys/resource.h sys/select.h sys/socket.h sys/wait.h \
syslog.h])
Modified: trunk/src/polyp/utf8.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/utf8.c?rev=931&root=polypaudio&r1=930&r2=931&view=diff
==============================================================================
--- trunk/src/polyp/utf8.c (original)
+++ trunk/src/polyp/utf8.c Thu May 18 10:19:07 2006
@@ -29,9 +29,14 @@
#endif
#include <assert.h>
+#include <errno.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
+
+#ifdef HAVE_ICONV_H
+#include <iconv.h>
+#endif
#include "utf8.h"
#include "xmalloc.h"
@@ -162,3 +167,70 @@
return utf8_validate(str, new_str);
}
+
+#ifdef HAVE_ICONV_H
+
+static char* iconv_simple(const char *str, const char *to, const char *from) {
+ char *new_str;
+ size_t len, inlen;
+
+ iconv_t cd;
+ char *inbuf, *outbuf;
+ size_t res, inbytes, outbytes;
+
+ cd = iconv_open(to, from);
+ if (cd == (iconv_t)-1)
+ return NULL;
+
+ inlen = len = strlen(str) + 1;
+ new_str = pa_xmalloc(len);
+ assert(new_str);
+
+ while (1) {
+ inbuf = (char*)str; /* Brain dead prototype for iconv() */
+ inbytes = inlen;
+ outbuf = new_str;
+ outbytes = len;
+
+ res = iconv(cd, &inbuf, &inbytes, &outbuf, &outbytes);
+
+ if (res != (size_t)-1)
+ break;
+
+ if (errno != E2BIG) {
+ pa_xfree(new_str);
+ new_str = NULL;
+ break;
+ }
+
+ assert(inbytes != 0);
+
+ len += inbytes;
+ new_str = pa_xrealloc(new_str, len);
+ assert(new_str);
+ }
+
+ iconv_close(cd);
+
+ return new_str;
+}
+
+char* pa_utf8_to_locale (const char *str) {
+ return iconv_simple(str, "", "UTF-8");
+}
+
+char* pa_locale_to_utf8 (const char *str) {
+ return iconv_simple(str, "UTF-8", "");
+}
+
+#else
+
+char* pa_utf8_to_locale (const char *str) {
+ return NULL;
+}
+
+char* pa_locale_to_utf8 (const char *str) {
+ return NULL;
+}
+
+#endif
Modified: trunk/src/polyp/utf8.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/utf8.h?rev=931&root=polypaudio&r1=930&r2=931&view=diff
==============================================================================
--- trunk/src/polyp/utf8.h (original)
+++ trunk/src/polyp/utf8.h Thu May 18 10:19:07 2006
@@ -36,6 +36,12 @@
/** Filter all invalid UTF8 characters from the specified string, returning a new fully UTF8 valid string. Don't forget to free the returned string with pa_xfree() */
char *pa_utf8_filter(const char *str);
+/** Convert a UTF-8 string to the current locale. Free the string using pa_xfree(). */
+char* pa_utf8_to_locale (const char *str);
+
+/** Convert a string in the current locale to UTF-8. Free the string using pa_xfree(). */
+char* pa_locale_to_utf8 (const char *str);
+
PA_C_DECL_END
#endif
More information about the pulseaudio-commits
mailing list