_moo_convert_string_to_uint()

This commit is contained in:
Yevgen Muntyan 2008-11-06 22:33:06 -06:00
parent 5a131e6d3b
commit 69c7e1ceb6
5 changed files with 64 additions and 24 deletions

View File

@ -1657,7 +1657,7 @@ load_window_session (MooEditor *editor,
doc = load_doc_session (editor, window, node, file_is_uri); doc = load_doc_session (editor, window, node, file_is_uri);
if (doc && moo_markup_get_bool_prop (node, "active", FALSE)) if (doc && moo_markup_bool_prop (node, "active", FALSE))
active_doc = doc; active_doc = doc;
} }
} }
@ -1732,7 +1732,7 @@ _moo_editor_load_session (MooEditor *editor,
window = load_window_session (editor, node, !old_format); window = load_window_session (editor, node, !old_format);
if (window && moo_markup_get_bool_prop (node, "active", FALSE)) if (window && moo_markup_bool_prop (node, "active", FALSE))
active_window = window; active_window = window;
} }

View File

@ -822,7 +822,7 @@ moo_markup_set_prop (MooMarkupNode *elm,
int int
moo_markup_get_int_prop (MooMarkupNode *node, moo_markup_int_prop (MooMarkupNode *node,
const char *prop_name, const char *prop_name,
int default_val) int default_val)
{ {
@ -832,19 +832,19 @@ moo_markup_get_int_prop (MooMarkupNode *node,
default_val); default_val);
} }
guint
void moo_markup_uint_prop (MooMarkupNode *node,
moo_markup_set_int_prop (MooMarkupNode *node,
const char *prop_name, const char *prop_name,
int val) guint default_val)
{ {
moo_markup_set_prop (node, prop_name, g_return_val_if_fail (MOO_MARKUP_IS_ELEMENT (node), default_val);
_moo_convert_int_to_string (val)); g_return_val_if_fail (prop_name != NULL, default_val);
return _moo_convert_string_to_uint (moo_markup_get_prop (node, prop_name),
default_val);
} }
gboolean gboolean
moo_markup_get_bool_prop (MooMarkupNode *node, moo_markup_bool_prop (MooMarkupNode *node,
const char *prop_name, const char *prop_name,
gboolean default_val) gboolean default_val)
{ {

View File

@ -179,13 +179,13 @@ void moo_markup_set_prop (MooMarkupNode *node,
const char *prop_name, const char *prop_name,
const char *val); const char *val);
int moo_markup_get_int_prop (MooMarkupNode *node, int moo_markup_int_prop (MooMarkupNode *node,
const char *prop_name, const char *prop_name,
int default_val); int default_val);
void moo_markup_set_int_prop (MooMarkupNode *node, guint moo_markup_uint_prop (MooMarkupNode *node,
const char *prop_name, const char *prop_name,
int val); guint default_val);
gboolean moo_markup_get_bool_prop (MooMarkupNode *node, gboolean moo_markup_bool_prop (MooMarkupNode *node,
const char *prop_name, const char *prop_name,
gboolean default_val); gboolean default_val);
void moo_markup_set_bool_prop (MooMarkupNode *node, void moo_markup_set_bool_prop (MooMarkupNode *node,

View File

@ -744,6 +744,22 @@ _moo_value_convert_to_int (const GValue *val,
return FALSE; return FALSE;
} }
static gboolean
_moo_value_convert_to_uint (const GValue *val,
guint *dest)
{
GValue result = {0};
g_value_init (&result, G_TYPE_UINT);
if (_moo_value_convert (val, &result))
{
*dest = g_value_get_uint (&result);
return TRUE;
}
return FALSE;
}
double double
_moo_value_convert_to_double (const GValue *val) _moo_value_convert_to_double (const GValue *val)
@ -854,6 +870,28 @@ _moo_convert_string_to_int (const char *string,
return int_val; return int_val;
} }
guint
_moo_convert_string_to_uint (const char *string,
guint default_val)
{
guint int_val = default_val;
if (string && string[0])
{
GValue str_val = {0};
g_value_init (&str_val, G_TYPE_STRING);
g_value_set_static_string (&str_val, string);
if (!_moo_value_convert_to_uint (&str_val, &int_val))
g_warning ("%s: could not convert string '%s' to uint",
G_STRFUNC, string);
g_value_unset (&str_val);
}
return int_val;
}
gboolean gboolean
_moo_convert_string_to_bool (const char *string, _moo_convert_string_to_bool (const char *string,

View File

@ -61,6 +61,8 @@ gboolean _moo_convert_string_to_bool (const char *string,
gboolean default_val); gboolean default_val);
int _moo_convert_string_to_int (const char *string, int _moo_convert_string_to_int (const char *string,
int default_val); int default_val);
guint _moo_convert_string_to_uint (const char *string,
guint default_val);
const char *_moo_convert_bool_to_string (gboolean value); const char *_moo_convert_bool_to_string (gboolean value);
const char *_moo_convert_int_to_string (int value); const char *_moo_convert_int_to_string (int value);