Commit bbb709f1 authored by Ole Jørgen Brønner's avatar Ole Jørgen Brønner

Move hypen_to_underscore to jsapi-util-string.cpp

Will be used by object.cpp in next commit
parent 1043d492
......@@ -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);
......
......@@ -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
......
......@@ -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__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment