From: knu@... Date: 2015-12-14T08:00:44+00:00 Subject: [ruby-core:72106] [Ruby trunk - Feature #11814] String#valid_encoding? without force_encoding Issue #11814 has been updated by Akinori MUSHA. For guessing the possible encodings for a byte stream, there are gems specialized for that purpose like charlock_homes, ucharset and rcharset. They are mostly either a wrapper of LibICU4C or a port of Mozilla's encoding detector. ---------------------------------------- Feature #11814: String#valid_encoding? without force_encoding https://bugs.ruby-lang.org/issues/11814#change-55522 * Author: Usaku NAKAMURA * Status: Rejected * 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/