Permalink
Browse files

Added rb_str_encode. Closes #1620, #1472.

  • Loading branch information...
1 parent d09f636 commit e4d1cdd664b546f2108cdc9c1d7e518e0355054e @brixen brixen committed Oct 23, 2012
Showing with 14 additions and 0 deletions.
  1. +7 −0 kernel/common/capi.rb
  2. +2 −0 vm/capi/19/include/ruby/encoding.h
  3. +5 −0 vm/capi/string19.cpp
View
@@ -55,5 +55,12 @@ def self.rb_num_coerce_relop(x, y, op)
def self.sprintf(format, args)
::Rubinius::Sprinter.get(format).call(*args)
end
+
+ def self.rb_str_encode(str, enc, flags, opts)
+ ec = Encoding::Converter.new str.encoding, enc, flags
+ ec.replacement = opts[:replace] if opts
+
+ ec.convert str
+ end
end
end
@@ -106,6 +106,8 @@ VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *);
VALUE rb_str_export_to_enc(VALUE, rb_encoding *);
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to);
+VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts);
+
void rb_declare_transcoder(const char* from, const char* to, const char* lib);
void rb_register_transcoder(const rb_transcoder* trans);
View
@@ -64,6 +64,11 @@ extern "C" {
return rb_external_str_new_with_enc(string, strlen(string), rb_default_external_encoding());
}
+ VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts) {
+ return rb_funcall(rb_mCAPI, rb_intern("rb_str_encode"), 4,
+ str, to, INT2FIX(ecflags), ecopts);
+ }
+
int rb_enc_str_coderange(VALUE string) {
// TODO
return ENC_CODERANGE_7BIT;

0 comments on commit e4d1cdd

Please sign in to comment.