summaryrefslogtreecommitdiff
path: root/junklib.c
diff options
context:
space:
mode:
Diffstat (limited to 'junklib.c')
-rw-r--r--junklib.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/junklib.c b/junklib.c
index 0dfa02c9..19411ea2 100644
--- a/junklib.c
+++ b/junklib.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include "playlist.h"
+#include "utf8.h"
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
@@ -918,3 +919,32 @@ junk_read_id3v2 (playItem_t *it, FILE *fp) {
return -1;
}
+const char *
+junk_detect_charset (const char *s) {
+ // check if that's already utf8
+ if (u8_valid (s, strlen (s), NULL)) {
+ return NULL; // means no recoding required
+ }
+ // check if that could be non-latin1 (too many nonascii chars)
+ if (can_be_russian (s)) {
+ return "cp1251";
+ }
+ return "iso8859-1";
+}
+
+void
+junk_recode (const char *in, int inlen, char *out, int outlen, const char *cs) {
+ iconv_t cd = iconv_open ("utf8", cs);
+ if (!cd) {
+ return;
+ }
+ else {
+ size_t inbytesleft = inlen;
+ size_t outbytesleft = outlen;
+ char *pin = (char*)in;
+ char *pout = out;
+ memset (out, 0, outlen);
+ size_t res = iconv (cd, &pin, &inbytesleft, &pout, &outbytesleft);
+ iconv_close (cd);
+ }
+}