Project

General

Profile

Feature #1900

Suggestion: Encoding#ascii_compatible?

Added by candlerb (Brian Candler) over 10 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:24793]

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

History

#1

Updated by runpaint (Run Paint Run Run) over 10 years ago

=begin
There's Encoding::Converter.asciicompat_encoding('UTF-8'). It returns nil if it is; a corresponding ASCII-compatible encoding otherwise.
=end

#2

Updated by phasis68 (Heesob Park) over 10 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

#3

Updated by naruse (Yui NARUSE) over 10 years ago

  • Category set to M17N

=begin
This seems reasonable.
How do you think matz?
If ok, I'll add this.
=end

#4

Updated by runpaint (Run Paint Run Run) over 10 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

#5

Updated by matz (Yukihiro Matsumoto) over 10 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?

                        matz.

=end

#6

Updated by naruse (Yui NARUSE) over 10 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r24480.
=end

#7

Updated by naruse (Yui NARUSE) over 10 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

Also available in: Atom PDF