mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* encoding.c (rb_enc_compatible): check if two objects have compatible
encodings. * encoding.c (enc_compatible_p): added Encoding.compatible?. * include/ruby/encoding.h (rb_enc_compatible): prototype. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b2c81746ac
commit
00befb4b3f
4 changed files with 34 additions and 4 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Mon Oct 22 10:57:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* encoding.c (rb_enc_compatible): check if two objects have compatible
|
||||||
|
encodings.
|
||||||
|
|
||||||
|
* encoding.c (enc_compatible_p): added Encoding.compatible?.
|
||||||
|
|
||||||
|
* include/ruby/encoding.h (rb_enc_compatible): prototype.
|
||||||
|
|
||||||
Sun Oct 21 18:29:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sun Oct 21 18:29:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* encoding.c (rb_enc_default, rb_enc_primary): return pointers to
|
* encoding.c (rb_enc_default, rb_enc_primary): return pointers to
|
||||||
|
|
22
encoding.c
22
encoding.c
|
@ -338,6 +338,15 @@ rb_enc_get(VALUE obj)
|
||||||
|
|
||||||
rb_encoding*
|
rb_encoding*
|
||||||
rb_enc_check(VALUE str1, VALUE str2)
|
rb_enc_check(VALUE str1, VALUE str2)
|
||||||
|
{
|
||||||
|
rb_encoding *enc = rb_enc_compatible(str1, str2);
|
||||||
|
if (!enc)
|
||||||
|
rb_raise(rb_eArgError, "character encodings differ");
|
||||||
|
return enc;
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_encoding*
|
||||||
|
rb_enc_compatible(VALUE str1, VALUE str2)
|
||||||
{
|
{
|
||||||
int idx1, idx2;
|
int idx1, idx2;
|
||||||
rb_encoding *enc;
|
rb_encoding *enc;
|
||||||
|
@ -371,7 +380,7 @@ rb_enc_check(VALUE str1, VALUE str2)
|
||||||
rb_enc_asciicompat(enc = rb_enc_from_index(idx2)))
|
rb_enc_asciicompat(enc = rb_enc_from_index(idx2)))
|
||||||
return enc;
|
return enc;
|
||||||
}
|
}
|
||||||
rb_raise(rb_eArgError, "character encodings differ");
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -510,6 +519,16 @@ enc_find(VALUE klass, VALUE enc)
|
||||||
return rb_enc_from_encoding(rb_enc_from_index(idx));
|
return rb_enc_from_encoding(rb_enc_from_index(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
enc_compatible_p(VALUE klass, VALUE str1, VALUE str2)
|
||||||
|
{
|
||||||
|
rb_encoding *enc = rb_enc_compatible(str1, str2);
|
||||||
|
VALUE encoding = Qnil;
|
||||||
|
if (!enc || !(encoding = rb_enc_from_encoding(enc)))
|
||||||
|
encoding = Qnil;
|
||||||
|
return encoding;
|
||||||
|
}
|
||||||
|
|
||||||
/* :nodoc: */
|
/* :nodoc: */
|
||||||
static VALUE
|
static VALUE
|
||||||
enc_dump(int argc, VALUE *argv, VALUE self)
|
enc_dump(int argc, VALUE *argv, VALUE self)
|
||||||
|
@ -621,6 +640,7 @@ Init_Encoding(void)
|
||||||
rb_define_method(rb_cEncoding, "name", enc_name, 0);
|
rb_define_method(rb_cEncoding, "name", enc_name, 0);
|
||||||
rb_define_singleton_method(rb_cEncoding, "list", enc_list, 0);
|
rb_define_singleton_method(rb_cEncoding, "list", enc_list, 0);
|
||||||
rb_define_singleton_method(rb_cEncoding, "find", enc_find, 1);
|
rb_define_singleton_method(rb_cEncoding, "find", enc_find, 1);
|
||||||
|
rb_define_singleton_method(rb_cEncoding, "compatible?", enc_compatible_p, 2);
|
||||||
|
|
||||||
rb_define_method(rb_cEncoding, "_dump", enc_dump, -1);
|
rb_define_method(rb_cEncoding, "_dump", enc_dump, -1);
|
||||||
rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1);
|
rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1);
|
||||||
|
|
|
@ -44,6 +44,7 @@ int rb_enc_find_index(const char *name);
|
||||||
int rb_to_encoding_index(VALUE);
|
int rb_to_encoding_index(VALUE);
|
||||||
rb_encoding* rb_to_encoding(VALUE);
|
rb_encoding* rb_to_encoding(VALUE);
|
||||||
rb_encoding* rb_enc_get(VALUE);
|
rb_encoding* rb_enc_get(VALUE);
|
||||||
|
rb_encoding* rb_enc_compatible(VALUE,VALUE);
|
||||||
rb_encoding* rb_enc_check(VALUE,VALUE);
|
rb_encoding* rb_enc_check(VALUE,VALUE);
|
||||||
void rb_enc_associate_index(VALUE, int);
|
void rb_enc_associate_index(VALUE, int);
|
||||||
void rb_enc_associate(VALUE, rb_encoding*);
|
void rb_enc_associate(VALUE, rb_encoding*);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define RUBY_VERSION "1.9.0"
|
#define RUBY_VERSION "1.9.0"
|
||||||
#define RUBY_RELEASE_DATE "2007-10-21"
|
#define RUBY_RELEASE_DATE "2007-10-22"
|
||||||
#define RUBY_VERSION_CODE 190
|
#define RUBY_VERSION_CODE 190
|
||||||
#define RUBY_RELEASE_CODE 20071021
|
#define RUBY_RELEASE_CODE 20071022
|
||||||
#define RUBY_PATCHLEVEL 0
|
#define RUBY_PATCHLEVEL 0
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
#define RUBY_VERSION_TEENY 0
|
#define RUBY_VERSION_TEENY 0
|
||||||
#define RUBY_RELEASE_YEAR 2007
|
#define RUBY_RELEASE_YEAR 2007
|
||||||
#define RUBY_RELEASE_MONTH 10
|
#define RUBY_RELEASE_MONTH 10
|
||||||
#define RUBY_RELEASE_DAY 21
|
#define RUBY_RELEASE_DAY 22
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
|
Loading…
Add table
Reference in a new issue