summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/ext/encoding_spec.c
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/optional/capi/ext/encoding_spec.c')
-rw-r--r--spec/ruby/optional/capi/ext/encoding_spec.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/spec/ruby/optional/capi/ext/encoding_spec.c b/spec/ruby/optional/capi/ext/encoding_spec.c
index 4d2ff52ef3..2038a5d4a8 100644
--- a/spec/ruby/optional/capi/ext/encoding_spec.c
+++ b/spec/ruby/optional/capi/ext/encoding_spec.c
@@ -91,6 +91,11 @@ static VALUE encoding_spec_rb_enc_compatible(VALUE self, VALUE a, VALUE b) {
return rb_enc_from_encoding(enc);
}
+static VALUE encoding_spec_rb_enc_check(VALUE self, VALUE a, VALUE b) {
+ rb_encoding* enc = rb_enc_check(a, b);
+ return rb_enc_from_encoding(enc);
+}
+
static VALUE encoding_spec_rb_enc_copy(VALUE self, VALUE dest, VALUE src) {
rb_enc_copy(dest, src);
return dest;
@@ -271,15 +276,12 @@ static VALUE encoding_spec_rb_enc_str_asciionly_p(VALUE self, VALUE str) {
}
}
-RBIMPL_WARNING_PUSH()
-RBIMPL_WARNING_IGNORED(-Wformat-security)
static VALUE encoding_spec_rb_enc_raise(VALUE self, VALUE encoding, VALUE exception_class, VALUE format) {
rb_encoding *e = rb_to_encoding(encoding);
const char *f = RSTRING_PTR(format);
rb_enc_raise(e, exception_class, "%s", f);
}
-RBIMPL_WARNING_POP()
static VALUE encoding_spec_rb_uv_to_utf8(VALUE self, VALUE buf, VALUE num) {
int len = rb_uv_to_utf8(RSTRING_PTR(buf), NUM2INT(num));
@@ -323,6 +325,14 @@ static VALUE encoding_spec_rb_enc_left_char_head(VALUE self, VALUE str, VALUE of
return LONG2NUM(result - ptr);
}
+static VALUE encoding_spec_rb_define_dummy_encoding(VALUE self, VALUE name) {
+ return INT2NUM(rb_define_dummy_encoding(RSTRING_PTR(name)));
+}
+
+static VALUE encoding_spec_ONIGENC_IS_UNICODE(VALUE self, VALUE encoding) {
+ return ONIGENC_IS_UNICODE(rb_to_encoding(encoding)) ? Qtrue : Qfalse;
+}
+
void Init_encoding_spec(void) {
VALUE cls;
native_rb_encoding_pointer = (rb_encoding**) malloc(sizeof(rb_encoding*));
@@ -348,6 +358,7 @@ void Init_encoding_spec(void) {
rb_define_method(cls, "rb_enc_associate", encoding_spec_rb_enc_associate, 2);
rb_define_method(cls, "rb_enc_associate_index", encoding_spec_rb_enc_associate_index, 2);
rb_define_method(cls, "rb_enc_compatible", encoding_spec_rb_enc_compatible, 2);
+ rb_define_method(cls, "rb_enc_check", encoding_spec_rb_enc_check, 2);
rb_define_method(cls, "rb_enc_copy", encoding_spec_rb_enc_copy, 2);
rb_define_method(cls, "rb_enc_codelen", encoding_spec_rb_enc_codelen, 2);
rb_define_method(cls, "rb_enc_strlen", encoding_spec_rb_enc_strlen, 3);
@@ -382,6 +393,8 @@ void Init_encoding_spec(void) {
rb_define_method(cls, "rb_uv_to_utf8", encoding_spec_rb_uv_to_utf8, 2);
rb_define_method(cls, "ONIGENC_MBC_CASE_FOLD", encoding_spec_ONIGENC_MBC_CASE_FOLD, 1);
rb_define_method(cls, "rb_enc_left_char_head", encoding_spec_rb_enc_left_char_head, 2);
+ rb_define_method(cls, "rb_define_dummy_encoding", encoding_spec_rb_define_dummy_encoding, 1);
+ rb_define_method(cls, "ONIGENC_IS_UNICODE", encoding_spec_ONIGENC_IS_UNICODE, 1);
}
#ifdef __cplusplus