From 11ef52b5dec094d7c32ebb15785cdfcbcc8f759c Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 19 May 2016 12:52:21 -0400 Subject: [PATCH] core/string: Remove unused string functions Signed-off-by: Anna Schumaker --- core/string.c | 49 ------------------------------------------- gui/playlist.c | 2 +- include/core/string.h | 6 +----- tests/core/string.c | 28 ------------------------- 4 files changed, 2 insertions(+), 83 deletions(-) diff --git a/core/string.c b/core/string.c index 512a1202..8c9d0853 100644 --- a/core/string.c +++ b/core/string.c @@ -46,55 +46,6 @@ gchar *string_tm2str(struct tm *tm) return buf; } -static gunichar __string_get_char(const gchar *str, const gchar *cur, - const gchar *res) -{ - gunichar c = g_utf8_get_char(cur); - gchar *prev = g_utf8_find_prev_char(str, res); - - if (g_unichar_ismark(c)) - return '\0'; - if (g_unichar_ispunct(c)) - return '\0'; - if (g_unichar_isspace(c)) { - if (!prev || (*prev == ' ')) - return '\0'; - return ' '; - } - return g_unichar_tolower(c); -} - -gchar *string_lowercase(const gchar *str) -{ - gchar *res = g_utf8_normalize(str, -1, G_NORMALIZE_DEFAULT); - gchar *i, *j = res; - gunichar c; - - for (i = res; *i != '\0'; i = g_utf8_next_char(i)) { - c = __string_get_char(res, i, j); - if (c) { - *j = c; - j = g_utf8_next_char(j); - } - } - *j = '\0'; - - g_strchomp(res); - return g_realloc(res, strlen(res) + 1); -} - -int string_compare(const gchar *lhs, const gchar *rhs) -{ - if (strlen(lhs) == 0) { - if (strlen(rhs) == 0) - return 0; - return 1; - } - if (strlen(rhs) == 0) - return -1; - return g_utf8_collate(lhs, rhs); -} - int string_compare_tokens(gchar **lhs, gchar **rhs) { unsigned int i, cmp; diff --git a/gui/playlist.c b/gui/playlist.c index 31bf6b23..88b1719d 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -313,7 +313,7 @@ void gui_playlist_add_artist(struct artist *artist) do { name = __playlist_name(&sibling); - match = string_compare(name, artist->ar_name) >= 0; + match = g_utf8_collate(name, artist->ar_name) >= 0; g_free(name); if (match) { diff --git a/include/core/string.h b/include/core/string.h index 1fab6ef7..63f53f9d 100644 --- a/include/core/string.h +++ b/include/core/string.h @@ -21,9 +21,6 @@ gchar *string_sec2str_long(unsigned int); /* Convert a struct tm to a locale-dependant date string. */ gchar *string_tm2str(struct tm *); -/* Convert the input string to lowercase, dropping special characters. */ -gchar *string_lowercase(const gchar *); - /* * Compare two strings. * @@ -31,13 +28,12 @@ gchar *string_lowercase(const gchar *); * if ret = 0: lhs == rhs. * if ret > 0: lhs > rhs, or lhs is empty. */ -int string_compare(const gchar *, const gchar *); int string_compare_tokens(gchar **, gchar **); /* Returns True if the two strings match. */ static inline bool string_match(const gchar *a, const gchar *b) { - return (a && b) ? string_compare(a, b) == 0 : false; + return (a && b) ? g_utf8_collate(a, b) == 0 : false; } /* Returns True if one of the tokens begins with the specified prefix. */ diff --git a/tests/core/string.c b/tests/core/string.c index 9ed35550..6c87cd22 100644 --- a/tests/core/string.c +++ b/tests/core/string.c @@ -75,32 +75,6 @@ void test_date() } -void test_lowercase() -{ - str_test_equal(string_lowercase(""), ""); - str_test_equal(string_lowercase(" "), ""); - str_test_equal(string_lowercase("5:02 PM"), "502 pm"); - str_test_equal(string_lowercase("T.N.T."), "tnt"); - str_test_equal(string_lowercase("#1 Zero"), "1 zero"); - str_test_equal(string_lowercase("Don't Stop"), "dont stop"); - str_test_equal(string_lowercase("100,000 Years"), "100000 years"); - str_test_equal(string_lowercase("Les Misérable"), "les miserable"); - str_test_equal(string_lowercase("Kryptonite (live)"), "kryptonite live"); - str_test_equal(string_lowercase("This Time [Hidden]"), "this time hidden"); -} - -void test_compare() -{ - test_equal(string_compare("A", "A"), 0); - test_equal(string_compare("a", "a"), 0); - test_equal(string_compare("A", "B"), -1); - test_equal(string_compare("B", "A"), 1); - - test_equal(string_compare("", ""), 0); - test_equal(string_compare("", "A"), 1); - test_equal(string_compare("A", ""), -1); -} - void test_compare_tokens() { gchar *a[2] = { "a", NULL }; @@ -157,8 +131,6 @@ DECLARE_UNIT_TESTS( UNIT_TEST("Seconds to String", test_sec2str), UNIT_TEST("Seconds to String (Long)", test_sec2str_long), UNIT_TEST("Date to String", test_date), - UNIT_TEST("String Lowercase", test_lowercase), - UNIT_TEST("String Comparison", test_compare), UNIT_TEST("String Comparison (Tokens)", test_compare_tokens), UNIT_TEST("String Match", test_match), UNIT_TEST("String Match (Tokens)", test_match_tokens),