Issue #12306 has been updated by sam.saffron (Sam Saffron).


@matz ... is there any way we can revise this and act on it? I really want to kill off my "fast_blank" gem. The 2 decisions that need to be made are:

1. Will MRI accept String#blank? which returns exactly the same as String#strip.empty? 
2. Will MRI accept changing #strip to be unicode space aware so it is consistent with Regexp? 

#match? helps but it is not as fast as a native implementation. 

```
sam@ubuntu rails % irb
irb(main):001:0> str = "\u202f"
=> ""
irb(main):002:0> str = "\u202f".strip.length
=> 1
irb(main):005:0> str = "\u202f".match?(/\A[[:space:]]*\z/)
=> true
```

The real world use case of this is slowly moving us to Ruby 3x3, by adding #blank? we can have an optimised implementation of #strip#empty? this is used widely in MRI codebase and other projects (non Rails including) 

An alternative may be erasing #strip#empty? in insns or something but I wonder if this is both risky and simply adding #blank? is easier.  


----------------------------------------
Feature #12306: Implement String #blank? #present? and improve #strip and family to handle unicode
https://bugs.ruby-lang.org/issues/12306#change-72360

* Author: sam.saffron (Sam Saffron)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Time and again there have been rejected feature requests to Ruby core to implement `blank` and `present` protocols across all objects as ActiveSupport does. I am fine with this call and think it is fair. 

However, for the narrow case of String having `#blank?` and `#present?` makes sense. 

- Provides a natural extension over `#strip`, `#lstrip` and `#rstrip`. `("   ".strip.length == 0) == "    ".blank?`

- Plays nicely with ActiveSupport, providing an efficient implementation in Ruby core: see: https://github.com/SamSaffron/fast_blank, implementing blank efficiently requires a c extension. 

However, if this work is to be done, `#strip` and should probably start dealing with unicode blanks, eg: 

```
irb(main):008:0> [0x3000].pack("U")
=> "กก"
irb(main):009:0> [0x3000].pack("U").strip.length
=> 1
```

So there are 2 questions / feature requests here

1. Can we add blank? and present? to String? 
2. Can we amend strip and family to account for unicode per: https://github.com/SamSaffron/fast_blank/blob/master/ext/fast_blank/fast_blank.c#L43-L74



-- 
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>