ruby-changes:46439
From: duerst <ko1@a...>
Date: Thu, 4 May 2017 10:36:59 +0900 (JST)
Subject: [ruby-changes:46439] duerst:r58553 (trunk): move definition of String#unicode_normalize! to C to make sure it is documented
duerst 2017-05-04 10:36:52 +0900 (Thu, 04 May 2017) New Revision: 58553 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58553 Log: move definition of String#unicode_normalize! to C to make sure it is documented * lib/unicode_normalize.rb: Remove definition of String#unicode_normalize! (including documentation) * string.c: Define String#unicode_normalize! in rb_str_unicode_normalize_bang in C, (including documentation) * lib/unicode_normalize/normalize.rb: Remove (re)definition of String#unicode_normalize! to avoid warnings (when $VERBOSE==true) and problems when String is frozen Modified files: trunk/lib/unicode_normalize/normalize.rb trunk/lib/unicode_normalize.rb trunk/string.c Index: string.c =================================================================== --- string.c (revision 58552) +++ string.c (revision 58553) @@ -9615,7 +9615,6 @@ rb_str_unicode_normalize(int argc, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L9615 rb_require("unicode_normalize/normalize.rb"); UnicodeNormalizeRequired = 1; } - /* return rb_funcall2(str, id_unicode_normalize, argc, argv); */ if (argc==0) return rb_funcall(mUnicodeNormalize, id_normalize, 1, str); else if (argc==1) @@ -9624,6 +9623,28 @@ rb_str_unicode_normalize(int argc, VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L9623 rb_raise(rb_eArgError, "too many arguments to unicode_normalize"); } +/* + * call-seq: + * str.unicode_normalize!(form=:nfc) + * + * Destructive version of String#unicode_normalize, doing Unicode + * normalization in place. + */ +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!"); +} + /********************************************************************** * Document-class: Symbol * @@ -10277,6 +10298,7 @@ Init_String(void) https://github.com/ruby/ruby/blob/trunk/string.c#L10298 id_normalize = rb_intern("normalize"); rb_define_method(rb_cString, "unicode_normalize", rb_str_unicode_normalize, -1); + rb_define_method(rb_cString, "unicode_normalize!", rb_str_unicode_normalize_bang, -1); rb_fs = Qnil; rb_define_hooked_variable("$;", &rb_fs, 0, rb_fs_setter); Index: lib/unicode_normalize/normalize.rb =================================================================== --- lib/unicode_normalize/normalize.rb (revision 58552) +++ lib/unicode_normalize/normalize.rb (revision 58553) @@ -160,10 +160,6 @@ module UnicodeNormalize # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L160 end # module class String # :nodoc: - def unicode_normalize!(form = :nfc) - replace(UnicodeNormalize.normalize(self, form)) - end - def unicode_normalized?(form = :nfc) UnicodeNormalize.normalized?(self, form) end Index: lib/unicode_normalize.rb =================================================================== --- lib/unicode_normalize.rb (revision 58552) +++ lib/unicode_normalize.rb (revision 58553) @@ -7,18 +7,6 @@ https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize.rb#L7 # additions to class String for Unicode normalization #++ class String - - # :call-seq: - # str.unicode_normalize!(form=:nfc) - # - # Destructive version of String#unicode_normalize, doing Unicode - # normalization in place. - # - def unicode_normalize!(form = :nfc) - require 'unicode_normalize/normalize.rb' - unicode_normalize! form - end - # :call-seq: # str.unicode_normalized?(form=:nfc) # -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/