[gjs: 1/3] Move hypen_to_underscore to jsapi-util-string.cpp



commit bbb709f1196efb987ae7bd0b3b264904a22f29c3
Author: Ole Jørgen Brønner <olejorgenb yahoo no>
Date:   Tue Aug 21 22:34:55 2018 +0200

    Move hypen_to_underscore to jsapi-util-string.cpp
    
    Will be used by object.cpp in next commit

 gi/gobject.cpp            | 14 ++------------
 gjs/jsapi-util-string.cpp | 10 ++++++++++
 gjs/jsapi-util.h          |  2 ++
 3 files changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/gi/gobject.cpp b/gi/gobject.cpp
index 65acdbdb..d4b74ae5 100644
--- a/gi/gobject.cpp
+++ b/gi/gobject.cpp
@@ -53,23 +53,13 @@ bool pop_class_init_properties(GType gtype, AutoParamArray* params_out) {
     return true;
 }
 
-static char* hyphen_to_underscore(const char* str) {
-    char *s = g_strdup(str);
-    char *retval = s;
-    while (*(s++) != '\0') {
-        if (*s == '-')
-            *s = '_';
-    }
-    return retval;
-}
-
 static void jsobj_set_gproperty(JSContext* cx, JS::HandleObject object,
                                 const GValue* value, GParamSpec* pspec) {
     JS::RootedValue jsvalue(cx);
     if (!gjs_value_from_g_value(cx, &jsvalue, value))
         return;
 
-    GjsAutoChar underscore_name = hyphen_to_underscore(pspec->name);
+    GjsAutoChar underscore_name = gjs_hyphen_to_underscore(pspec->name);
     if (!JS_SetProperty(cx, object, underscore_name, jsvalue))
         gjs_log_exception(cx);
 }
@@ -161,7 +151,7 @@ static void gjs_object_get_gproperty(GObject* object, unsigned property_id,
     JS::RootedObject js_obj(cx, priv->wrapper());
     JS::RootedValue jsvalue(cx);
 
-    GjsAutoChar underscore_name = hyphen_to_underscore(pspec->name);
+    GjsAutoChar underscore_name = gjs_hyphen_to_underscore(pspec->name);
     if (!JS_GetProperty(cx, js_obj, underscore_name, &jsvalue) ||
         !gjs_value_to_g_value(cx, jsvalue, value))
         gjs_log_exception(cx);
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index 03e8c4fd..f3e2c02a 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -32,6 +32,16 @@
 #include "jsapi-util.h"
 #include "jsapi-wrapper.h"
 
+char* gjs_hyphen_to_underscore(const char* str) {
+    char *s = g_strdup(str);
+    char *retval = s;
+    while (*(s++) != '\0') {
+        if (*s == '-')
+            *s = '_';
+    }
+    return retval;
+}
+
 /**
  * gjs_string_to_utf8:
  * @cx: JSContext
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 3597ff96..4bcaa577 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -424,4 +424,6 @@ std::string gjs_debug_object(JSObject *obj);
 std::string gjs_debug_value(JS::Value v);
 std::string gjs_debug_id(jsid id);
 
+char* gjs_hyphen_to_underscore(const char* str);
+
 #endif  /* __GJS_JSAPI_UTIL_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]