tag: added function tag_name_parse()
Convert a string into a tag_type enum.
This commit is contained in:
		@@ -42,9 +42,9 @@ locate_parse_type(const char *str)
 | 
				
			|||||||
	if (0 == g_ascii_strcasecmp(str, LOCATE_TAG_ANY_KEY))
 | 
						if (0 == g_ascii_strcasecmp(str, LOCATE_TAG_ANY_KEY))
 | 
				
			||||||
		return LOCATE_TAG_ANY_TYPE;
 | 
							return LOCATE_TAG_ANY_TYPE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++)
 | 
						i = tag_name_parse_i(str);
 | 
				
			||||||
		if (0 == g_ascii_strcasecmp(str, tag_item_names[i]))
 | 
						if (i != TAG_NUM_OF_ITEM_TYPES)
 | 
				
			||||||
			return i;
 | 
							return i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										50
									
								
								src/tag.c
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								src/tag.c
									
									
									
									
									
								
							@@ -64,6 +64,36 @@ const char *tag_item_names[TAG_NUM_OF_ITEM_TYPES] = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool ignore_tag_items[TAG_NUM_OF_ITEM_TYPES];
 | 
					bool ignore_tag_items[TAG_NUM_OF_ITEM_TYPES];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum tag_type
 | 
				
			||||||
 | 
					tag_name_parse(const char *name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						assert(name != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
 | 
				
			||||||
 | 
							assert(tag_item_names[i] != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (strcmp(name, tag_item_names[i]) == 0)
 | 
				
			||||||
 | 
								return (enum tag_type)i;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return TAG_NUM_OF_ITEM_TYPES;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum tag_type
 | 
				
			||||||
 | 
					tag_name_parse_i(const char *name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						assert(name != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
 | 
				
			||||||
 | 
							assert(tag_item_names[i] != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (g_ascii_strcasecmp(name, tag_item_names[i]) == 0)
 | 
				
			||||||
 | 
								return (enum tag_type)i;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return TAG_NUM_OF_ITEM_TYPES;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static size_t items_size(const struct tag *tag)
 | 
					static size_t items_size(const struct tag *tag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return tag->num_items * sizeof(struct tag_item *);
 | 
						return tag->num_items * sizeof(struct tag_item *);
 | 
				
			||||||
@@ -76,7 +106,7 @@ void tag_lib_init(void)
 | 
				
			|||||||
	char *temp;
 | 
						char *temp;
 | 
				
			||||||
	char *s;
 | 
						char *s;
 | 
				
			||||||
	char *c;
 | 
						char *c;
 | 
				
			||||||
	int i;
 | 
						enum tag_type type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* parse the "metadata_to_use" config parameter below */
 | 
						/* parse the "metadata_to_use" config parameter below */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -98,16 +128,18 @@ void tag_lib_init(void)
 | 
				
			|||||||
			if (*s == '\0')
 | 
								if (*s == '\0')
 | 
				
			||||||
				quit = 1;
 | 
									quit = 1;
 | 
				
			||||||
			*s = '\0';
 | 
								*s = '\0';
 | 
				
			||||||
			for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) {
 | 
					
 | 
				
			||||||
				if (g_ascii_strcasecmp(c, tag_item_names[i]) == 0) {
 | 
								c = g_strstrip(c);
 | 
				
			||||||
					ignore_tag_items[i] = false;
 | 
								if (*c == 0)
 | 
				
			||||||
					break;
 | 
									continue;
 | 
				
			||||||
				}
 | 
					
 | 
				
			||||||
			}
 | 
								type = tag_name_parse_i(c);
 | 
				
			||||||
			if (strlen(c) && i == TAG_NUM_OF_ITEM_TYPES) {
 | 
								if (type == TAG_NUM_OF_ITEM_TYPES)
 | 
				
			||||||
				g_error("error parsing metadata item \"%s\"",
 | 
									g_error("error parsing metadata item \"%s\"",
 | 
				
			||||||
					c);
 | 
										c);
 | 
				
			||||||
			}
 | 
					
 | 
				
			||||||
 | 
								ignore_tag_items[type] = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			s++;
 | 
								s++;
 | 
				
			||||||
			c = s;
 | 
								c = s;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								src/tag.h
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/tag.h
									
									
									
									
									
								
							@@ -93,6 +93,22 @@ struct tag {
 | 
				
			|||||||
	unsigned num_items;
 | 
						unsigned num_items;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Parse the string, and convert it into a #tag_type.  Returns
 | 
				
			||||||
 | 
					 * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					enum tag_type
 | 
				
			||||||
 | 
					tag_name_parse(const char *name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Parse the string, and convert it into a #tag_type.  Returns
 | 
				
			||||||
 | 
					 * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Case does not matter.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					enum tag_type
 | 
				
			||||||
 | 
					tag_name_parse_i(const char *name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Creates an empty #tag.
 | 
					 * Creates an empty #tag.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user