core/string: Remove unused string functions

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-19 12:52:21 -04:00 committed by Anna Schumaker
parent aead4939c3
commit 11ef52b5de
4 changed files with 2 additions and 83 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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. */

View File

@ -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),