Project

General

Profile

Actions

Bug #1681

closed

Integer#chr Should Infer Encoding of Given Codepoint

Bug #1681: Integer#chr Should Infer Encoding of Given Codepoint

Added by runpaint (Run Paint Run Run) over 16 years ago. Updated over 14 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux]
Backport:
[ruby-core:23997]

Description

=begin
String#ord and Integer#chr are symmetrical operations on ASCII Strings:

 'a'.ord.chr   #=> "a"

But Integer#chr fails to round-trip when the given codepoint is outside the range of ASCII:

 "\u{2563}".ord.chr #=> RangeError: 9571 out of char range

To fix this, the codepoint's encoding needs to be specified:

 "\u{2563}".ord.chr('utf-8')  #=> "╣"

This seems needlessly verbose given that Ruby already knows that my source encoding is UTF-8. I suggest, then, that, when invoked with no argument, Integer#chr displays the given codepoint w.r.t to the current encoding, raising a RangeError only if the codepoint is out-of-bounds for this inferred encoding.
=end

Actions

Also available in: PDF Atom