[前][次][番号順一覧][スレッド一覧]

ruby-changes:67209

From: S-H-GAMELINKS <ko1@a...>
Date: Sun, 22 Aug 2021 10:39:26 +0900 (JST)
Subject: [ruby-changes:67209] 18031f4102 (master): Add rb_encoding_check function

https://git.ruby-lang.org/ruby.git/commit/?id=18031f4102

From 18031f4102d7c8efc3a40b3fa65b36f94fc8a418 Mon Sep 17 00:00:00 2001
From: S-H-GAMELINKS <gamelinks007@g...>
Date: Sat, 21 Aug 2021 15:28:59 +0900
Subject: Add rb_encoding_check function

---
 encoding.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/encoding.c b/encoding.c
index 0f3f7f2..bc3d2f7 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1072,12 +1072,9 @@ rb_enc_get(VALUE obj) https://github.com/ruby/ruby/blob/trunk/encoding.c#L1072
     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) https://github.com/ruby/ruby/blob/trunk/encoding.c#L1082
     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*
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]