void parse_tree(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
{
while (node) {
- struct Callback *c = g_hash_table_lookup(i->callbacks, node->name);
+ if (node->name) {
+ struct Callback *c = g_hash_table_lookup(i->callbacks, node->name);
- if (c)
- c->func(i, doc, node, c->data);
+ if (c)
+ c->func(i, doc, node, c->data);
+ }
node = node->next;
}
gchar *parse_string(xmlDocPtr doc, xmlNodePtr node)
{
xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
- gchar *s = g_strdup(c ? (gchar*)c : "");
+ gchar *s;
+ if (c) g_strstrip((char*)c);
+ s = g_strdup(c ? (gchar*)c : "");
xmlFree(c);
return s;
}
gint parse_int(xmlDocPtr doc, xmlNodePtr node)
{
xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
- gint i = c ? atoi((gchar*)c) : 0;
+ gint i;
+ if (c) g_strstrip((char*)c);
+ i = c ? atoi((gchar*)c) : 0;
xmlFree(c);
return i;
}
{
xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
gboolean b = FALSE;
+ if (c) g_strstrip((char*)c);
if (c && !xmlStrcasecmp(c, (const xmlChar*) "true"))
b = TRUE;
else if (c && !xmlStrcasecmp(c, (const xmlChar*) "yes"))
{
xmlChar *c = xmlNodeListGetString(doc, node->children, TRUE);
gboolean r;
+ if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */
r = !xmlStrcasecmp(c, (const xmlChar*) val);
xmlFree(c);
return r;
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
gboolean r = FALSE;
if (c) {
+ g_strstrip((char*)c); /* strip leading/trailing whitespace */
if (!xmlStrcasecmp(c, (const xmlChar*) "true"))
*value = TRUE, r = TRUE;
else if (!xmlStrcasecmp(c, (const xmlChar*) "yes"))
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
gboolean r = FALSE;
if (c) {
+ g_strstrip((char*)c); /* strip leading/trailing whitespace */
*value = atoi((gchar*)c);
r = TRUE;
}
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
gboolean r = FALSE;
if (c) {
+ g_strstrip((char*)c); /* strip leading/trailing whitespace */
*value = g_strdup((gchar*)c);
r = TRUE;
}
{
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
gboolean r = FALSE;
- if (c)
+ if (c) {
+ g_strstrip((char*)c);
r = !xmlStrcasecmp(c, (const xmlChar*) val);
+ }
xmlFree(c);
return r;
}
gchar *parse_expand_tilde(const gchar *f)
{
- gchar **spl;
gchar *ret;
+ GRegex *regex;
if (!f)
return NULL;
- spl = g_strsplit(f, "~", 0);
- ret = g_strjoinv(g_get_home_dir(), spl);
- g_strfreev(spl);
+
+ regex = g_regex_new("(?:^|(?<=[ \\t]))~(?:(?=[/ \\t])|$)",
+ G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL);
+ ret = g_regex_replace_literal(regex, f, -1, 0, g_get_home_dir(), 0, NULL);
+ g_regex_unref(regex);
+
return ret;
}