utils: add unescape_tag function

This is added to remove any escape chars from a string.
This will be used in a pending patch, that correctly reads .nfo files that
contain escape chars.

Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
This commit is contained in:
Spencer Oliver 2013-12-05 22:11:09 +00:00 committed by Justin Maggard
parent 7e6b015b05
commit f5ebc22eeb
2 changed files with 21 additions and 0 deletions

20
utils.c
View File

@ -206,6 +206,26 @@ modifyString(char * string, const char * before, const char * after)
return string; return string;
} }
char *
unescape_tag(const char *tag, int force_alloc)
{
char *esc_tag = NULL;
if( strstr(tag, "&amp;") || strstr(tag, "&lt;") || strstr(tag, "&gt;")
|| strstr(tag, "&quot;") )
{
esc_tag = strdup(tag);
esc_tag = modifyString(esc_tag, "&amp;", "&");
esc_tag = modifyString(esc_tag, "&lt;", "<");
esc_tag = modifyString(esc_tag, "&gt;", ">");
esc_tag = modifyString(esc_tag, "&quot;", "\"");
}
else if( force_alloc )
esc_tag = strdup(tag);
return esc_tag;
}
char * char *
escape_tag(const char *tag, int force_alloc) escape_tag(const char *tag, int force_alloc)
{ {

View File

@ -36,6 +36,7 @@ char *strstrc(const char *s, const char *p, const char t);
char *strcasestrc(const char *s, const char *p, const char t); char *strcasestrc(const char *s, const char *p, const char t);
char *modifyString(char * string, const char * before, const char * after); char *modifyString(char * string, const char * before, const char * after);
char *escape_tag(const char *tag, int force_alloc); char *escape_tag(const char *tag, int force_alloc);
char *unescape_tag(const char *tag, int force_alloc);
void strip_ext(char * name); void strip_ext(char * name);
/* Metadata functions */ /* Metadata functions */