summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 95b5a37)
raw | patch | inline | side by side (parent: 95b5a37)
author | Kalle Wallin <kaw@linux.se> | |
Sat, 27 Mar 2004 20:51:28 +0000 (20:51 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Sat, 27 Mar 2004 20:51:28 +0000 (20:51 +0000) |
support.c | patch | blob | history |
diff --git a/support.c b/support.c
index de3d80cef2810e838a3008151713b51445bb6f9a..907c5085f6410c0884a759f2ce35f06905371e54 100644 (file)
--- a/support.c
+++ b/support.c
iconv_t iconv_to_uft8 = (iconv_t)(-1);
#endif
+char *
+trim(char *str)
+{
+ char *end;
+
+ if( str==NULL )
+ return NULL;
+
+ while( IS_WHITESPACE(*str) )
+ str++;
+
+ end=str+strlen(str)-1;
+ while( end>str && IS_WHITESPACE(*end) )
+ {
+ *end = '\0';
+ end--;
+ }
+ return str;
+}
char *
remove_trailing_slash(char *path)
perror("iconv_open");
return -1;
}
+ iconv_to_uft8 = iconv_open("UTF-8", charset);
+ if( iconv_to_uft8 == (iconv_t)(-1) )
+ {
+ perror("iconv_open");
+ return -1;
+ }
#endif
return 0;
return 0;
}
-
-
-char *
-utf8_to_locale(char *str)
-{
#ifdef HAVE_ICONV
+static char *
+charconv(iconv_t iv, char *str)
+{
size_t inleft;
size_t retlen;
char *ret;
- if( iconv_from_uft8 == (iconv_t)(-1) )
+ if( str==NULL )
+ return NULL;
+
+ if( iv == (iconv_t)(-1) )
return strdup(str);
ret = NULL;
size_t outleft = BUFSIZE;
char *bufp = buf;
- if( iconv(iconv_from_uft8, &str, &inleft, &bufp, &outleft) <0 )
+ if( iconv(iv, &str, &inleft, &bufp, &outleft) <0 )
{
perror("iconv");
free(ret);
ret[retlen] = '\0';
}
return ret;
+}
+#endif
+
+char *
+utf8_to_locale(char *str)
+{
+#ifdef HAVE_ICONV
+ return charconv(iconv_from_uft8, str);
+#else
+ return strdup(str);
+#endif
+}
+char *
+locale_to_utf8(char *str)
+{
+#ifdef HAVE_ICONV
+ return charconv(iconv_to_uft8, str);
#else
return strdup(str);
#endif