gitypelib: And another fix for empty strings

This commit is contained in:
Colin Walters 2013-04-08 15:32:15 -04:00
parent d0462e6a3c
commit 5bea9385b0

View File

@ -226,6 +226,7 @@ g_typelib_get_dir_entry_by_gtype_name (GITypelib *typelib,
typedef struct { typedef struct {
const char *s; const char *s;
const char *separator; const char *separator;
gsize sep_len;
GString buf; GString buf;
} StrSplitIter; } StrSplitIter;
@ -236,6 +237,7 @@ strsplit_iter_init (StrSplitIter *iter,
{ {
iter->s = s; iter->s = s;
iter->separator = separator; iter->separator = separator;
iter->sep_len = strlen (separator);
iter->buf.str = NULL; iter->buf.str = NULL;
iter->buf.len = 0; iter->buf.len = 0;
iter->buf.allocated_len = 0; iter->buf.allocated_len = 0;
@ -254,7 +256,7 @@ strsplit_iter_next (StrSplitIter *iter,
next = strstr (s, iter->separator); next = strstr (s, iter->separator);
if (next) if (next)
{ {
iter->s = next + 1; iter->s = next + iter->sep_len;
len = next - s; len = next - s;
} }
else else
@ -262,8 +264,15 @@ strsplit_iter_next (StrSplitIter *iter,
iter->s = NULL; iter->s = NULL;
len = strlen (s); len = strlen (s);
} }
g_string_overwrite_len (&iter->buf, 0, s, (gssize)len); if (len == 0)
*out_val = iter->buf.str; {
*out_val = "";
}
else
{
g_string_overwrite_len (&iter->buf, 0, s, (gssize)len);
*out_val = iter->buf.str;
}
return TRUE; return TRUE;
} }