Skip to content

Commit

Permalink
Solve it via fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed May 13, 2024
1 parent ed00d8d commit 64ba8ed
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/utilities/core/jsoncpp.i
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@

#if defined SWIGRUBY

%fragment("JsonToDict","header", fragment="SWIG_FromCharPtrAndSize") {

extern "C" {
struct OnigEncodingTypeST;
typedef struct OnigEncodingTypeST OnigEncodingType;
typedef const OnigEncodingType rb_encoding;
%fragment("<ruby_encoding>", "header") %{
#include <ruby/encoding.h>
%}

rb_encoding *rb_utf8_encoding(void);
ID rb_intern3(const char *name, long len, rb_encoding *enc);
%fragment("string_to_ruby_utf8_symbol", "header", fragment="<ruby_encoding>") {
SWIGINTERN VALUE SWIG_String_to_ruby_utf8_symbol(const std::string& str) {
return ID2SYM(rb_intern3(str.data(), str.size(), rb_utf8_encoding()));
}
}

%fragment("JsonToDict", "header", fragment="SWIG_FromCharPtrAndSize", fragment="string_to_ruby_utf8_symbol") {

SWIGINTERN VALUE SWIG_From_JsonValue(const Json::Value& value) {

Expand Down Expand Up @@ -120,7 +121,7 @@
VALUE result = rb_hash_new();
for( const auto& id : value.getMemberNames()) {
rb_hash_aset(result,
ID2SYM(rb_intern3(id.data(), id.size(), rb_utf8_encoding())),
SWIG_String_to_ruby_utf8_symbol(id),
SWIG_From_JsonValue(value[id])
);
}
Expand Down

0 comments on commit 64ba8ed

Please sign in to comment.