aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-01-14 08:08:32 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-01-14 08:08:32 +0000
commit13cda7cefaab6b0eef7b4718629f8ce31cd9eff0 (patch)
tree26a6f3ec89fcaf68b0420db33cf2f3b350eeefc3 /src/utils.c
parent01109639c07dc4babec7912a8febfe1f989b1b0d (diff)
fix code conversions, add conv_iconv_strdup_with_cd(), and use EUC-JP-MS for JIS to UTF-8 conversion if available.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@7 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/utils.c b/src/utils.c
index 493c9597..693f86ea 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -518,11 +518,9 @@ gint get_mbs_len(const gchar *s)
return -1;
while (*p != '\0') {
- mb_len = mblen(p, MB_LEN_MAX);
+ mb_len = g_utf8_skip[*(guchar *)p];
if (mb_len == 0)
break;
- else if (mb_len < 0)
- return -1;
else
len++;
@@ -1340,13 +1338,13 @@ gchar *trim_string(const gchar *str, gint len)
if (!str) return NULL;
if (strlen(str) <= len)
return g_strdup(str);
+ if (g_utf8_validate(str, -1, NULL) == FALSE)
+ return g_strdup(str);
while (*p != '\0') {
- mb_len = mblen(p, MB_LEN_MAX);
+ mb_len = g_utf8_skip[*(guchar *)p];
if (mb_len == 0)
break;
- else if (mb_len < 0)
- return g_strdup(str);
else if (new_len + mb_len > len)
break;
@@ -1367,13 +1365,13 @@ gchar *trim_string_before(const gchar *str, gint len)
if (!str) return NULL;
if ((new_len = strlen(str)) <= len)
return g_strdup(str);
+ if (g_utf8_validate(str, -1, NULL) == FALSE)
+ return g_strdup(str);
while (*p != '\0') {
- mb_len = mblen(p, MB_LEN_MAX);
+ mb_len = g_utf8_skip[*(guchar *)p];
if (mb_len == 0)
break;
- else if (mb_len < 0)
- return g_strdup(str);
new_len -= mb_len;
p += mb_len;