summaryrefslogtreecommitdiffstats
path: root/utils/storage
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2010-10-09 10:14:44 +0800
committerPeng Wu <alexepico@gmail.com>2010-10-09 10:14:44 +0800
commit434f731dd015c2b7947a5f20a4c48df7dd5616e2 (patch)
treefc89c08dbd8e28d46ebbd074284eaf45a562c024 /utils/storage
parent93943b03f6d28f9c4f6f531c5976f5a5ebaa321e (diff)
downloadlibpinyin-434f731dd015c2b7947a5f20a4c48df7dd5616e2.tar.gz
libpinyin-434f731dd015c2b7947a5f20a4c48df7dd5616e2.tar.xz
libpinyin-434f731dd015c2b7947a5f20a4c48df7dd5616e2.zip
re-factor taglib_add_tag interface
Diffstat (limited to 'utils/storage')
-rw-r--r--utils/storage/tag_utility.cpp17
-rw-r--r--utils/storage/tag_utility.h25
2 files changed, 12 insertions, 30 deletions
diff --git a/utils/storage/tag_utility.cpp b/utils/storage/tag_utility.cpp
index 5fd0d90..e566a83 100644
--- a/utils/storage/tag_utility.cpp
+++ b/utils/storage/tag_utility.cpp
@@ -74,7 +74,7 @@ bool taglib_init(){
}
bool taglib_add_tag(int line_type, const char * line_tag, int num_of_values,
- const char * required_tags[], const char * ignored_tags[]){
+ const char * required_tags, const char * ignored_tags){
GArray * tag_array = (GArray *) g_ptr_array_index(g_tagutils_stack,
g_tagutils_stack->len - 1);
@@ -86,10 +86,15 @@ bool taglib_add_tag(int line_type, const char * line_tag, int num_of_values,
return false;
}
+ char ** required = g_strsplit_set(required_tags, ",:", -1);
+ char ** ignored = g_strsplit_set(ignored_tags, ",:", -1);
+
tag_entry entry = tag_entry_copy(line_type, line_tag, num_of_values,
- (char **)required_tags,
- (char **)ignored_tags);
+ required, ignored);
g_array_append_val(tag_array, entry);
+
+ g_strfreev(required);
+ g_strfreev(ignored);
return true;
}
@@ -130,6 +135,7 @@ static gchar ** split_line(const gchar * line){
cur = g_utf8_next_char(cur);
}
gchar * tmp = g_strndup( begin, cur - begin);
+ /* TODO: switch to strdup_escape for \"->" transforming. */
token = g_strdup_printf(tmp);
g_free(tmp);
} else {
@@ -295,8 +301,5 @@ bool taglib_fini(){
}
void test(){
- TAGLIB_BEGIN_ADD_TAG(1, "\\data", 0);
- TAGLIB_REQUIRED_TAGS = {"model", NULL};
- TAGLIB_IGNORED_TAGS = {"data", NULL};
- TAGLIB_END_ADD_TAG;
+ assert(taglib_add_tag(2, "\\data", 1, "data", ""));
}
diff --git a/utils/storage/tag_utility.h b/utils/storage/tag_utility.h
index 6ac1992..22a7dd4 100644
--- a/utils/storage/tag_utility.h
+++ b/utils/storage/tag_utility.h
@@ -28,8 +28,8 @@
bool taglib_init();
-/* Note: most string array (const char *) are null pointer terminated. */
-bool taglib_add_tag(int line_type, const char * line_tag, int num_of_values, const char * required_tags[], const char * ignored_tags[]);
+/* Note: most tags are separated by ',' or ':' . */
+bool taglib_add_tag(int line_type, const char * line_tag, int num_of_values, const char * required_tags, const char * ignored_tags);
/* most parameters are hash table of string (const char *). */
bool taglib_read(const char * input_line, int & line_type, GPtrArray * values, GHashTable * required);
@@ -51,25 +51,4 @@ bool taglib_pop_state();
bool taglib_fini();
-/* Useful macros to ease taglib_add_tag call,
- * or else need to use C++0x-features.
- */
-
-#define TAGLIB_BEGIN_ADD_TAG(line_type, line_tag, num_of_values) \
- { \
- int line_type_saved = line_type; \
- const char * line_tag_saved = line_tag; \
- int num_of_values_saved = num_of_values; \
- ;
-
-#define TAGLIB_REQUIRED_TAGS const char * required_tags_saved[]
-/* #define TAGLIB_OPTIONAL_TAGS const char * optional_tags_saved[] */
-#define TAGLIB_IGNORED_TAGS const char * ignored_tags_saved[]
-
-#define TAGLIB_END_ADD_TAG \
- assert(taglib_add_tag(line_type_saved, line_tag_saved, \
- num_of_values_saved, \
- required_tags_saved, ignored_tags_saved)); \
- };
-
#endif