Project

General

Profile

Feature #13588

Add Encoding#min_char_size, #max_char_size, #minmax_char_size

Added by haines (Andrew Haines) about 3 years ago. Updated about 3 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:81335]

Description

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.

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


Related issues

Related to Ruby master - Feature #11094: Remove traces of 6-byte UTF-8Closed04/24/2015Actions
Related to Ruby master - Bug #13590: Change max byte length of UTF-8 to 4 bytes to conform to definition of UTF-8Closedduerst (Martin Dürst)Actions

Also available in: Atom PDF