summaryrefslogtreecommitdiffstats
path: root/utils/storage
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2010-09-30 15:22:43 +0800
committerPeng Wu <alexepico@gmail.com>2010-09-30 15:22:43 +0800
commit60b9330eb0348642ff414629b48786cd3de3ea18 (patch)
treed0928cd9b9e865d24cf17b54d088f4f499f31abd /utils/storage
parentf84457ea19cf4e402cce86d3d5a4a21baa72dcb8 (diff)
downloadlibpinyin-60b9330eb0348642ff414629b48786cd3de3ea18.tar.gz
libpinyin-60b9330eb0348642ff414629b48786cd3de3ea18.tar.xz
libpinyin-60b9330eb0348642ff414629b48786cd3de3ea18.zip
add some required tags check
Diffstat (limited to 'utils/storage')
-rw-r--r--utils/storage/tag_utility.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/utils/storage/tag_utility.cpp b/utils/storage/tag_utility.cpp
index 456bc62..e172ed8 100644
--- a/utils/storage/tag_utility.cpp
+++ b/utils/storage/tag_utility.cpp
@@ -127,37 +127,38 @@ bool taglib_read(const char * input_line, int & line_type, GPtrArray * values,
g_ptr_array_add(values, value);
}
+ int ignored_len = g_strv_length( cur_entry->m_ignored_tags );
+ int required_len = g_strv_length( cur_entry->m_required_tags);
+
for ( int i = cur_entry->m_num_of_values + 1; i < num_of_tokens; ++i){
g_return_val_if_fail(i < num_of_tokens, false);
const char * tmp = tokens[i];
/* check ignored tags. */
- bool ignored = false;
- int ignored_len = g_strv_length( entry->m_ignored_tags );
+ bool tag_ignored = false;
for ( int m = 0; m < ignored_len; ++m) {
- if ( strcmp(tmp, entry->m_ignored_tags[i]) == 0) {
- ignored = true;
+ if ( strcmp(tmp, cur_entry->m_ignored_tags[i]) == 0) {
+ tag_ignored = true;
break;
}
}
- if ( ignored ) {
+ if ( tag_ignored ) {
++i;
continue;
}
/* check required tags. */
- bool required = false;
- int required_len = g_strv_length( entry->m_required_tags);
+ bool tag_required = false;
for ( int m = 0; m < required_len; ++m) {
- if ( strcmp(tmp, entry->m_required_tags[i]) == 0) {
- required = true;
+ if ( strcmp(tmp, cur_entry->m_required_tags[i]) == 0) {
+ tag_required = true;
break;
}
}
/* warning on the un-expected tags. */
- if ( !required ) {
+ if ( !tag_required ) {
g_warning("un-expected tags:%s.\n", tmp);
++i;
continue;
@@ -170,6 +171,17 @@ bool taglib_read(const char * input_line, int & line_type, GPtrArray * values,
g_hash_table_insert(required, key, value);
}
+ /* check for all required tags. */
+ for ( int i = 0; i < required_len; ++i) {
+ const char * required_tag_str = cur_entry->m_required_tags[i];
+ gboolean result = g_hash_table_lookup_extended(required, required_tag_str, NULL, NULL);
+ if ( !result ) {
+ g_warning("missed required tags: %s.\n", required_tag_str);
+ g_strfreev(tokens);
+ return false;
+ }
+ }
+
g_strfreev(tokens);
return true;
}