core/filter: Move filter_add() out of the filter namespace
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
b98b1a5855
commit
90afcd6065
|
@ -16,22 +16,24 @@ static struct database filter_index;
|
|||
void filter_init() { index_init(&filter_index, "", false); }
|
||||
void filter_deinit() { db_deinit(&filter_index); }
|
||||
|
||||
const std::string filter :: add(const std::string &text, unsigned int index)
|
||||
void filter_add(const gchar *text, unsigned int index)
|
||||
{
|
||||
gchar *g_lc = string_lowercase(text.c_str());
|
||||
const std::string lc = g_lc;
|
||||
size_t begin = 0, end;
|
||||
const gchar *c = g_utf8_next_char(text);
|
||||
glong begin, end;
|
||||
gchar *substr;
|
||||
|
||||
g_free(g_lc);
|
||||
for (begin = 0, end = 1; end <= g_utf8_strlen(text, -1); end++) {
|
||||
substr = g_utf8_substring(text, begin, end);
|
||||
index_insert(&filter_index, substr, index);
|
||||
|
||||
for (end = 1; end <= lc.size(); end++) {
|
||||
index_insert(&filter_index,
|
||||
lc.substr(begin, end - begin).c_str(),
|
||||
index);
|
||||
if (lc[end] == ' ')
|
||||
if (g_unichar_isspace(g_utf8_get_char(c))) {
|
||||
c = g_utf8_next_char(c);
|
||||
begin = ++end;
|
||||
}
|
||||
|
||||
c = g_utf8_next_char(c);
|
||||
g_free(substr);
|
||||
}
|
||||
return lc;
|
||||
}
|
||||
|
||||
void filter :: search(const std::string &text, struct set *res)
|
||||
|
|
|
@ -85,9 +85,9 @@ static void track_setup(struct db_entry *dbe)
|
|||
{
|
||||
struct track *track = (struct track *)dbe;
|
||||
|
||||
filter :: add(track->tr_title, track->dbe_index);
|
||||
filter :: add(track->tr_artist->ar_name, track->dbe_index);
|
||||
filter :: add(track->tr_album->al_name, track->dbe_index);
|
||||
filter_add(track->tr_lower.c_str(), track->dbe_index);
|
||||
filter_add(track->tr_artist->ar_lower.c_str(), track->dbe_index);
|
||||
filter_add(track->tr_album->al_lower.c_str(), track->dbe_index);
|
||||
track->tr_library->li_size++;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,22 +23,6 @@ extern "C" {
|
|||
*/
|
||||
namespace filter {
|
||||
|
||||
/**
|
||||
* Convert the key to lowercase and break into individual words.
|
||||
* Generate substrings for each word and add each (substring, index)
|
||||
* pair to the Index.
|
||||
*
|
||||
* To generate substrings: iterate over the word starting from the
|
||||
* first character, and append a character for every iteration. For
|
||||
* example, the word "goron" would contain the substrings:
|
||||
* { g, go, gor, goro, goron }.
|
||||
*
|
||||
* @param text The text to parse.
|
||||
* @param index The track index to pair with the text.
|
||||
* @return The lowercase form of the input text.
|
||||
*/
|
||||
const std::string add(const std::string &, unsigned int);
|
||||
|
||||
/**
|
||||
* Break the input text into lowercase words and search the Index
|
||||
* for matches. The results set should be filled out with the
|
||||
|
@ -63,4 +47,7 @@ namespace filter {
|
|||
void filter_init();
|
||||
void filter_deinit();
|
||||
|
||||
/* Add the input string to the index. */
|
||||
void filter_add(const gchar *, unsigned int);
|
||||
|
||||
#endif /* OCARINA_CORE_FILTER_H */
|
||||
|
|
|
@ -30,7 +30,7 @@ static void test_filter()
|
|||
|
||||
filter_init();
|
||||
for (i = 0; i < NUM_STRINGS; i++) {
|
||||
filter :: add(test_strings[i], i);
|
||||
filter_add(test_strings[i], i);
|
||||
} test_loop_passed();
|
||||
|
||||
/* Search for a word! */
|
||||
|
|
Loading…
Reference in New Issue