From f9f8dd90bd443d43855c8a673100d199a1ac6560 Mon Sep 17 00:00:00 2001 From: hiro Date: Wed, 21 Sep 2005 11:07:51 +0000 Subject: removed mbs/wcs functions which are no longer required. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@596 ee746299-78ed-0310-b773-934348b2243d --- libsylph/utils.c | 211 +------------------------------------------------------ libsylph/utils.h | 39 ---------- 2 files changed, 1 insertion(+), 249 deletions(-) (limited to 'libsylph') diff --git a/libsylph/utils.c b/libsylph/utils.c index 09632f64..5c0ba893 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -29,11 +29,6 @@ #include #include #include - -#if (HAVE_WCTYPE_H && HAVE_WCHAR_H) -# include -# include -#endif #include #include #include @@ -46,6 +41,7 @@ #include #ifdef G_OS_WIN32 +# include # include # include #endif @@ -429,211 +425,6 @@ gchar *strncpy2(gchar *dest, const gchar *src, size_t n) return dest; } -#if !HAVE_ISWALNUM -int iswalnum(wint_t wc) -{ - return g_ascii_isalnum((int)wc); -} -#endif - -#if !HAVE_ISWSPACE -int iswspace(wint_t wc) -{ - return g_ascii_isspace((int)wc); -} -#endif - -#if !HAVE_TOWLOWER -wint_t towlower(wint_t wc) -{ - if (wc >= L'A' && wc <= L'Z') - return wc + L'a' - L'A'; - - return wc; -} -#endif - -#if !HAVE_WCSLEN -size_t wcslen(const wchar_t *s) -{ - size_t len = 0; - - while (*s != L'\0') - ++len, ++s; - - return len; -} -#endif - -#if !HAVE_WCSCPY -/* Copy SRC to DEST. */ -wchar_t *wcscpy(wchar_t *dest, const wchar_t *src) -{ - wint_t c; - wchar_t *s = dest; - - do { - c = *src++; - *dest++ = c; - } while (c != L'\0'); - - return s; -} -#endif - -#if !HAVE_WCSNCPY -/* Copy no more than N wide-characters of SRC to DEST. */ -wchar_t *wcsncpy (wchar_t *dest, const wchar_t *src, size_t n) -{ - wint_t c; - wchar_t *s = dest; - - do { - c = *src++; - *dest++ = c; - if (--n == 0) - return s; - } while (c != L'\0'); - - /* zero fill */ - do - *dest++ = L'\0'; - while (--n > 0); - - return s; -} -#endif - -/* Duplicate S, returning an identical malloc'd string. */ -wchar_t *wcsdup(const wchar_t *s) -{ - wchar_t *new_str; - - if (s) { - new_str = g_new(wchar_t, wcslen(s) + 1); - wcscpy(new_str, s); - } else - new_str = NULL; - - return new_str; -} - -/* Duplicate no more than N wide-characters of S, - returning an identical malloc'd string. */ -wchar_t *wcsndup(const wchar_t *s, size_t n) -{ - wchar_t *new_str; - - if (s) { - new_str = g_new(wchar_t, n + 1); - wcsncpy(new_str, s, n); - new_str[n] = (wchar_t)0; - } else - new_str = NULL; - - return new_str; -} - -wchar_t *strdup_mbstowcs(const gchar *s) -{ - wchar_t *new_str; - - if (s) { - new_str = g_new(wchar_t, strlen(s) + 1); - if (mbstowcs(new_str, s, strlen(s) + 1) < 0) { - g_free(new_str); - new_str = NULL; - } else - new_str = g_realloc(new_str, - sizeof(wchar_t) * (wcslen(new_str) + 1)); - } else - new_str = NULL; - - return new_str; -} - -gchar *strdup_wcstombs(const wchar_t *s) -{ - gchar *new_str; - size_t len; - - if (s) { - len = wcslen(s) * MB_CUR_MAX + 1; - new_str = g_new(gchar, len); - if (wcstombs(new_str, s, len) < 0) { - g_free(new_str); - new_str = NULL; - } else - new_str = g_realloc(new_str, strlen(new_str) + 1); - } else - new_str = NULL; - - return new_str; -} - -/* Compare S1 and S2, ignoring case. */ -gint wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) -{ - wint_t c1; - wint_t c2; - - while (n--) { - c1 = towlower(*s1++); - c2 = towlower(*s2++); - if (c1 != c2) - return c1 - c2; - else if (c1 == 0 && c2 == 0) - break; - } - - return 0; -} - -/* Find the first occurrence of NEEDLE in HAYSTACK, ignoring case. */ -wchar_t *wcscasestr(const wchar_t *haystack, const wchar_t *needle) -{ - register size_t haystack_len, needle_len; - - haystack_len = wcslen(haystack); - needle_len = wcslen(needle); - - if (haystack_len < needle_len || needle_len == 0) - return NULL; - - while (haystack_len >= needle_len) { - if (!wcsncasecmp(haystack, needle, needle_len)) - return (wchar_t *)haystack; - else { - haystack++; - haystack_len--; - } - } - - return NULL; -} - -gint get_mbs_len(const gchar *s) -{ - const gchar *p = s; - gint mb_len; - gint len = 0; - - if (!p) - return -1; - - while (*p != '\0') { - mb_len = g_utf8_skip[*(guchar *)p]; - if (mb_len == 0) - break; - else - len++; - - p += mb_len; - } - - return len; -} - /* Examine if next block is non-ASCII string */ gboolean is_next_nonascii(const gchar *s) { diff --git a/libsylph/utils.h b/libsylph/utils.h index 7301c59b..41760bb5 100644 --- a/libsylph/utils.h +++ b/libsylph/utils.h @@ -35,9 +35,6 @@ #if HAVE_ALLOCA_H # include #endif -#if HAVE_WCHAR_H -# include -#endif /* Wrappers for C library function that take pathname arguments. */ #if GLIB_CHECK_VERSION(2, 6, 0) @@ -237,42 +234,6 @@ gchar *strncpy2 (gchar *dest, const gchar *src, size_t n); -/* wide-character functions */ -#if !HAVE_ISWALNUM -int iswalnum (wint_t wc); -#endif -#if !HAVE_ISWSPACE -int iswspace (wint_t wc); -#endif -#if !HAVE_TOWLOWER -wint_t towlower (wint_t wc); -#endif - -#if !HAVE_WCSLEN -size_t wcslen (const wchar_t *s); -#endif -#if !HAVE_WCSCPY -wchar_t *wcscpy (wchar_t *dest, - const wchar_t *src); -#endif -#if !HAVE_WCSNCPY -wchar_t *wcsncpy (wchar_t *dest, - const wchar_t *src, - size_t n); -#endif - -wchar_t *wcsdup (const wchar_t *s); -wchar_t *wcsndup (const wchar_t *s, - size_t n); -wchar_t *strdup_mbstowcs (const gchar *s); -gchar *strdup_wcstombs (const wchar_t *s); -gint wcsncasecmp (const wchar_t *s1, - const wchar_t *s2, - size_t n); -wchar_t *wcscasestr (const wchar_t *haystack, - const wchar_t *needle); -gint get_mbs_len (const gchar *s); - gboolean is_next_nonascii (const gchar *s); gint get_next_word_len (const gchar *s); -- cgit v1.2.3