[#78633] ruby/spec needs help from CRuby committers — Benoit Daloze <eregontp@...>
Currently, ruby/spec is maintained mostly by individuals and enjoys the
13 messages
2016/12/13
[#78963] Re: ruby/spec needs help from CRuby committers
— Urabe Shyouhei <shyouhei@...>
2017/01/04
I did ask attendees of last developer meeting to join this
[#78642] Re: ruby/spec needs help from CRuby committers
— Eric Wong <normalperson@...>
2016/12/14
Benoit Daloze <eregontp@gmail.com> wrote:
[ruby-core:78541] [Ruby trunk Feature#13016] String#gsub(hash)
From:
akr@...
Date:
2016-12-08 08:29:09 UTC
List:
ruby-core #78541
Issue #13016 has been updated by Akira Tanaka.
Is str.gsub(map) a shortcut for str.gsub(Regexp.union(map.keys)) { map[$&] } ?
----------------------------------------
Feature #13016: String#gsub(hash)
https://bugs.ruby-lang.org/issues/13016#change-61925
* Author: Shyouhei Urabe
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Background: I wanted to drop NKF dependency of my script. By doing so I noticed that I can't purge `NKF.nkf '-Z4'`. It can neither be rewritten using String#tr, String#encode, nor String#unicode_normalize. It is doable using String#gsub theoretically, but that requires a hand-crafted nontrivial regular expression that exactly matches what Z4 expects to convert. This is almost impossible to do, and is definitely not something debuggable.
Proposal: extend String#gsub so that it also accepts hash as its only argument, specifying input-output mapping.
```ruby
# now
def convert str
require 'nkf'
NKF.nkf '-Z4xm0', str
end
# proposed
def convert str
map = { "\u3002" => "\uFF61", "\u300C" => "\uFF62", ... }
str.gsub map
end
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>