diff options
author | S-H-GAMELINKS <gamelinks007@gmail.com> | 2021-08-21 15:28:59 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-08-22 10:39:14 +0900 |
commit | 18031f4102d7c8efc3a40b3fa65b36f94fc8a418 (patch) | |
tree | d39c2acedb3fa66599ddabdda29d25947ac41929 /encoding.c | |
parent | 6594623f623a0982da62cc105094da0701d499da (diff) |
Add rb_encoding_check function
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4759
Diffstat (limited to 'encoding.c')
-rw-r--r-- | encoding.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/encoding.c b/encoding.c index 0f3f7f2c53..bc3d2f78f2 100644 --- a/encoding.c +++ b/encoding.c @@ -1072,12 +1072,9 @@ rb_enc_get(VALUE obj) return rb_enc_from_index(rb_enc_get_index(obj)); } -static rb_encoding* enc_compatible_str(VALUE str1, VALUE str2); - -rb_encoding* -rb_enc_check_str(VALUE str1, VALUE str2) +static rb_encoding* +rb_encoding_check(rb_encoding* enc, VALUE str1, VALUE str2) { - rb_encoding *enc = enc_compatible_str(MUST_STRING(str1), MUST_STRING(str2)); if (!enc) rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s", rb_enc_name(rb_enc_get(str1)), @@ -1085,15 +1082,20 @@ rb_enc_check_str(VALUE str1, VALUE str2) return enc; } +static rb_encoding* enc_compatible_str(VALUE str1, VALUE str2); + +rb_encoding* +rb_enc_check_str(VALUE str1, VALUE str2) +{ + rb_encoding *enc = enc_compatible_str(MUST_STRING(str1), MUST_STRING(str2)); + return rb_encoding_check(enc, str1, str2); +} + rb_encoding* rb_enc_check(VALUE str1, VALUE str2) { rb_encoding *enc = rb_enc_compatible(str1, str2); - if (!enc) - rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s", - rb_enc_name(rb_enc_get(str1)), - rb_enc_name(rb_enc_get(str2))); - return enc; + return rb_encoding_check(enc, str1, str2); } static rb_encoding* |