Anonymous avatar Anonymous committed 1befab8

_moo_convert_string_to_uint()

Comments (0)

Files changed (5)

moo/mooedit/mooeditor.c

 
             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;
         }
     }
 
             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;
         }
 

moo/mooutils/moomarkup.c

 
 
 int
-moo_markup_get_int_prop (MooMarkupNode      *node,
-                         const char         *prop_name,
-                         int                 default_val)
+moo_markup_int_prop (MooMarkupNode *node,
+                     const char    *prop_name,
+                     int            default_val)
 {
     g_return_val_if_fail (MOO_MARKUP_IS_ELEMENT (node), default_val);
     g_return_val_if_fail (prop_name != NULL, default_val);
                                        default_val);
 }
 
-
-void
-moo_markup_set_int_prop (MooMarkupNode      *node,
-                         const char         *prop_name,
-                         int                 val)
+guint
+moo_markup_uint_prop (MooMarkupNode *node,
+                      const char    *prop_name,
+                      guint          default_val)
 {
-    moo_markup_set_prop (node, prop_name,
-                         _moo_convert_int_to_string (val));
+    g_return_val_if_fail (MOO_MARKUP_IS_ELEMENT (node), default_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
-moo_markup_get_bool_prop (MooMarkupNode      *node,
-                          const char         *prop_name,
-                          gboolean            default_val)
+moo_markup_bool_prop (MooMarkupNode *node,
+                      const char    *prop_name,
+                      gboolean       default_val)
 {
     g_return_val_if_fail (MOO_MARKUP_IS_ELEMENT (node), default_val);
     g_return_val_if_fail (prop_name != NULL, default_val);
 
 
 void
-moo_markup_set_bool_prop (MooMarkupNode      *node,
-                          const char         *prop_name,
-                          gboolean            val)
+moo_markup_set_bool_prop (MooMarkupNode *node,
+                          const char    *prop_name,
+                          gboolean       val)
 {
     moo_markup_set_prop (node, prop_name,
                          _moo_convert_bool_to_string (val));

moo/mooutils/moomarkup.h

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

moo/mooutils/mooutils-gobject.c

     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
 _moo_value_convert_to_double (const GValue *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
 _moo_convert_string_to_bool (const char *string,
 }
 
 
-const char*
+const char *
 _moo_convert_int_to_string (int value)
 {
     GValue int_val = {0};

moo/mooutils/mooutils-gobject.h

                                              gboolean        default_val);
 int             _moo_convert_string_to_int  (const char     *string,
                                              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_int_to_string  (int             value);
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.