builder: Move a function

Move _gtk_builder_boolean_from_string in the same source file
as the other _from_functions.
This commit is contained in:
Matthias Clasen 2015-09-07 12:43:19 -04:00
parent 20079a9960
commit 3d01f29bd9
2 changed files with 46 additions and 46 deletions

View File

@ -2265,6 +2265,52 @@ _gtk_builder_flags_from_string (GType type,
return ret;
}
gboolean
_gtk_builder_boolean_from_string (const gchar *string,
gboolean *value,
GError **error)
{
gboolean retval = TRUE;
int length;
g_assert (string != NULL);
length = strlen (string);
if (length == 0)
retval = FALSE;
else if (length == 1)
{
gchar c = g_ascii_tolower (string[0]);
if (c == 'y' || c == 't' || c == '1')
*value = TRUE;
else if (c == 'n' || c == 'f' || c == '0')
*value = FALSE;
else
retval = FALSE;
}
else
{
gchar *lower = g_ascii_strdown (string, length);
if (strcmp (lower, "yes") == 0 || strcmp (lower, "true") == 0)
*value = TRUE;
else if (strcmp (lower, "no") == 0 || strcmp (lower, "false") == 0)
*value = FALSE;
else
retval = FALSE;
g_free (lower);
}
if (!retval)
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
"Could not parse boolean '%s'",
string);
return retval;
}
/**
* gtk_builder_get_type_from_name:
* @builder: a #GtkBuilder

View File

@ -120,52 +120,6 @@ error_unhandled_tag (ParserData *data,
data->filename, line, col, tag);
}
gboolean
_gtk_builder_boolean_from_string (const gchar *string,
gboolean *value,
GError **error)
{
gboolean retval = TRUE;
int length;
g_assert (string != NULL);
length = strlen (string);
if (length == 0)
retval = FALSE;
else if (length == 1)
{
gchar c = g_ascii_tolower (string[0]);
if (c == 'y' || c == 't' || c == '1')
*value = TRUE;
else if (c == 'n' || c == 'f' || c == '0')
*value = FALSE;
else
retval = FALSE;
}
else
{
gchar *lower = g_ascii_strdown (string, length);
if (strcmp (lower, "yes") == 0 || strcmp (lower, "true") == 0)
*value = TRUE;
else if (strcmp (lower, "no") == 0 || strcmp (lower, "false") == 0)
*value = FALSE;
else
retval = FALSE;
g_free (lower);
}
if (!retval)
g_set_error (error,
GTK_BUILDER_ERROR,
GTK_BUILDER_ERROR_INVALID_VALUE,
"Could not parse boolean '%s'",
string);
return retval;
}
static GObject *
builder_construct (ParserData *data,
ObjectInfo *object_info,