ruby-changes:46443
From: duerst <ko1@a...>
Date: Thu, 4 May 2017 11:16:32 +0900 (JST)
Subject: [ruby-changes:46443] duerst:r58558 (trunk): refactor common parts of unicode normalization functions into unicode_normalize_common
duerst 2017-05-04 11:16:27 +0900 (Thu, 04 May 2017) New Revision: 58558 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58558 Log: refactor common parts of unicode normalization functions into unicode_normalize_common In string.c, refactor the common parts (requiring of unicode_normalize/normalize.rb, check of number of arguments) of the unicode normalization functions (rb_str_unicode_normalize, rb_str_unicode_normalize_bang, rb_str_unicode_normalized_p) into the new function unicode_normalize_common. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 58557) +++ string.c (revision 58558) @@ -9585,7 +9585,23 @@ str_scrub_bang(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/string.c#L9585 static VALUE id_normalize; static VALUE id_normalized_p; static VALUE mUnicodeNormalize; -static int UnicodeNormalizeRequired = 0; + +static VALUE +unicode_normalize_common(int argc, VALUE *argv, VALUE str, VALUE id) +{ + static int UnicodeNormalizeRequired = 0; + + if (!UnicodeNormalizeRequired) { + rb_require("unicode_normalize/normalize.rb"); + UnicodeNormalizeRequired = 1; + } + if (argc==0) + return rb_funcall(mUnicodeNormalize, id, 1, str); + else if (argc==1) + return rb_funcall(mUnicodeNormalize, id, 2, str, argv[0]); + else + rb_raise(rb_eArgError, "too many arguments to unicode normalization function"); +} /* * call-seq: @@ -9612,16 +9628,7 @@ static int UnicodeNormalizeRequired = 0; https://github.com/ruby/ruby/blob/trunk/string.c#L9628 static VALUE rb_str_unicode_normalize(int argc, VALUE *argv, VALUE str) { - if (!UnicodeNormalizeRequired) { - rb_require("unicode_normalize/normalize.rb"); - UnicodeNormalizeRequired = 1; - } - if (argc==0) - return rb_funcall(mUnicodeNormalize, id_normalize, 1, str); - else if (argc==1) - return rb_funcall(mUnicodeNormalize, id_normalize, 2, str, argv[0]); - else - rb_raise(rb_eArgError, "too many arguments to unicode_normalize"); + return unicode_normalize_common(argc, argv, str, id_normalize); } /* @@ -9634,16 +9641,7 @@ rb_str_unicode_normalize(int argc, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L9641 static VALUE rb_str_unicode_normalize_bang(int argc, VALUE *argv, VALUE str) { - if (!UnicodeNormalizeRequired) { - rb_require("unicode_normalize/normalize.rb"); - UnicodeNormalizeRequired = 1; - } - if (argc==0) - return rb_str_replace(str, rb_funcall(mUnicodeNormalize, id_normalize, 1, str)); - else if (argc==1) - return rb_str_replace(str, rb_funcall(mUnicodeNormalize, id_normalize, 2, str, argv[0])); - else - rb_raise(rb_eArgError, "too many arguments to unicode_normalize!"); + return rb_str_replace(str, unicode_normalize_common(argc, argv, str, id_normalize)); } /* call-seq: @@ -9666,16 +9664,7 @@ rb_str_unicode_normalize_bang(int argc, https://github.com/ruby/ruby/blob/trunk/string.c#L9664 static VALUE rb_str_unicode_normalized_p(int argc, VALUE *argv, VALUE str) { - if (!UnicodeNormalizeRequired) { - rb_require("unicode_normalize/normalize.rb"); - UnicodeNormalizeRequired = 1; - } - if (argc==0) - return rb_funcall(mUnicodeNormalize, id_normalized_p, 1, str); - else if (argc==1) - return rb_funcall(mUnicodeNormalize, id_normalized_p, 2, str, argv[0]); - else - rb_raise(rb_eArgError, "too many arguments to unicode_normalized?"); + return unicode_normalize_common(argc, argv, str, id_normalized_p); } /********************************************************************** -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/