From: duerst@... Date: 2017-05-23T09:17:31+00:00 Subject: [ruby-core:81343] [Ruby trunk Feature#13588][Feedback] Add Encoding#min_char_size, #max_char_size, #minmax_char_size Issue #13588 has been updated by duerst (Martin D��rst). Status changed from Open to Feedback haines (Andrew Haines) wrote: > When implementing an IO-like object, I'd like to handle encoding correctly. This should be possible without knowing the minimum and maximum length of characters in the encoding. > To do so, I need to know the minimum and maximum character sizes for the encoding of the stream I'm reading. However, I can't find a way to access this information from Ruby (I ended up writing a gem with a native extension [1] to do so). > > I'd like to propose adding instance methods `min_char_size`, `max_char_size`, and `minmax_char_size` to the `Encoding` class to expose the information stored in the `OnigEncodingType` struct's `min_enc_len` and `max_enc_len` fields. It may be that there is indeed something that you need for implementing your IO-like object. But my guess is that its most probably something on a higher abstraction level than `min_enc_len` and `max_enc_len`. It would be good to have more specific information about what you actually want to do or are doing. I'm changing the status to feedback. > Encoding::UTF_8.max_char_size # => 6 The max length for UTF-8 should actually be 4. I have submitted a separate bug (#13590) to fix this. ---------------------------------------- Feature #13588: Add Encoding#min_char_size, #max_char_size, #minmax_char_size https://bugs.ruby-lang.org/issues/13588#change-65041 * Author: haines (Andrew Haines) * Status: Feedback * Priority: Normal * Assignee: * Target version: ---------------------------------------- When implementing an IO-like object, I'd like to handle encoding correctly. To do so, I need to know the minimum and maximum character sizes for the encoding of the stream I'm reading. However, I can't find a way to access this information from Ruby (I ended up writing a gem with a native extension [1] to do so). I'd like to propose adding instance methods `min_char_size`, `max_char_size`, and `minmax_char_size` to the `Encoding` class to expose the information stored in the `OnigEncodingType` struct's `min_enc_len` and `max_enc_len` fields. ~~~ ruby Encoding::UTF_8.min_char_size # => 1 Encoding::UTF_8.max_char_size # => 6 Encoding::UTF_8.minmax_char_size # => [1, 6] ~~~ [1] https://github.com/haines/char_size -- https://bugs.ruby-lang.org/ Unsubscribe: