Issue #11814 has been reported by Usaku NAKAMURA.

----------------------------------------
Feature #11814: String#valid_encoding? without force_encoding
https://bugs.ruby-lang.org/issues/11814

* Author: Usaku NAKAMURA
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Now we have to set a encoding to a string to validate it, just like:

```ruby
str.force_encoding('euc-jp').valid_encoding?  # => true or false
```

But to modify the string is not so smart.
knu-san requires the way to validate a string without modifiing it [*1].

Then, I propose to add an optional encoding parameter to `String#valid_encoding?`.

```ruby
str.valid_encoding?('euc-jp')  # => true or false
```

A patch is attached.

[*1] https://twitter.com/knu/status/676009662655934465 (in Japanese)

---Files--------------------------------
valid_encoding.patch (4.4 KB)


-- 
https://bugs.ruby-lang.org/