Feature #1900
closedSuggestion: Encoding#ascii_compatible?
Description
=begin
An important property of an Encoding is whether it is ASCII-compatible. However as far as I can see, you can only test for this indirectly, e.g.
Encoding.compatible?("a".force_encoding("ISO-8859-1"), "a".force_encoding("US-ASCII"))
So I suggest exposing rb_enc_asciicompat as a property of the Encoding objects themselves.
=end
Updated by runpaint (Run Paint Run Run) over 14 years ago
=begin
There's Encoding::Converter.asciicompat_encoding('UTF-8'). It returns nil if it is; a corresponding ASCII-compatible encoding otherwise.
=end
Updated by phasis68 (Heesob Park) over 14 years ago
=begin
I think Encoding::Converter.asciicompat_encoding method is incomplete.
It cannot be distinguished whether the given encoding is invalid or ASCII-compatible.
Encoding::Converter.asciicompat_encoding("UTF-8") returns nil.
Encoding::Converter.asciicompat_encoding("UTF-0") also returns nil.
=end
Updated by naruse (Yui NARUSE) over 14 years ago
- Category set to M17N
=begin
This seems reasonable.
How do you think matz?
If ok, I'll add this.
=end
Updated by runpaint (Run Paint Run Run) over 14 years ago
=begin
It cannot be distinguished whether the given encoding is invalid or ASCII-compatible.
Encoding::Converter.asciicompat_encoding("UTF-8") returns nil.
Encoding::Converter.asciicompat_encoding("UTF-0") also returns nil.
Is this intentional or a bug?
=end
Updated by matz (Yukihiro Matsumoto) over 14 years ago
=begin
Hi,
In message "Re: [ruby-core:24800] [Feature #1900] Suggestion: Encoding#ascii_compatible?"
on Fri, 7 Aug 2009 01:40:21 +0900, Yui NARUSE redmine@ruby-lang.org writes:
|This seems reasonable.
|How do you think matz?
|If ok, I'll add this.
It's OK. But can you address the issue mentioned in [ruby-core:24796]
(cannot distinguish ASCII-compatible and invalid)?
matz.
=end
Updated by naruse (Yui NARUSE) over 14 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
Applied in changeset r24480.
=end
Updated by naruse (Yui NARUSE) over 14 years ago
=begin
It cannot be distinguished whether the given encoding is invalid or ASCII-compatible.
Encoding::Converter.asciicompat_encoding("UTF-8") returns nil.
Encoding::Converter.asciicompat_encoding("UTF-0") also returns nil.Is this intentional or a bug?
Different from methods of Encoding, methods of Encoding::Converter is categorized into transcode.
So their intention is also different.
Encoding::Converter.asciicompat_encoding is made to use when you handle a string encoded in ASCII-incompatible encoding.
You can use this and get an ASCII-compatible encoding which has the same character set, and convert to it, and you can handle that string with Ruby APIs.
=end