JRuby

String#encode (and decode?) missing from Ruby 1.9 String

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.3.1
  • Fix Version/s: JRuby 1.6RC3
  • Component/s: HelpWanted, Ruby 1.9.2
  • Labels:
    None
  • Number of attachments :
    0

Description

At least String#encode is missing, and Marcin mentioned a String#decode or String::decode I can't find. That may be via Encoding::Converter?

Here at least is the rdoc for String#encode:

---------------------------------------------------------- String#encode
     str.encode(encoding [, options] )   => str
     str.encode(dst_encoding, src_encoding [, options] )   => str
     str.encode([options])   => str

     From Ruby 1.9.1
------------------------------------------------------------------------
     The first form returns a copy of _str_ transcoded to encoding
     +encoding+. The second form returns a copy of _str_ transcoded from
     src_encoding to dst_encoding. The last form returns a copy of _str_
     transcoded to +Encoding.default_internal+. By default, the first
     and second form raise Encoding::UndefinedConversionError for
     characters that are undefined in the destination encoding, and
     Encoding::InvalidByteSequenceError for invalid byte sequences in
     the source encoding. The last form by default does not raise
     exceptions but uses replacement strings. The +options+ Hash gives
     details for conversion.

     options

     The hash +options+ can have the following keys:

     :invalid :           If the value is +:replace+, +#encode+ replaces
                          invalid byte sequences in +str+ with the
                          replacement character. The default is to raise
                          the exception

     :undef :             If the value is +:replace+, +#encode+ replaces
                          characters which are undefined in the
                          destination encoding with the replacement
                          character.

     :replace :           Sets the replacement string to the value. The
                          default replacement string is "\uFFFD" for
                          Unicode encoding forms, and "?" otherwise.

     :xml :               The value must be +:text+ or +:attr+. If the
                          value is +:text+ +#encode+ replaces undefined
                          characters with their (upper-case hexadecimal)
                          numeric character references. '&', '<', and
                          '>' are converted to "&amp;", "&lt;", and
                          "&gt;", respectively. If the value is +:attr+,
                          +#encode+ also quotes the replacement result
                          (using '"'), and replaces '"' with "&quot;".

     :cr_newline :        Replaces LF ("\n") with CR ("\r") if value is
                          true.

     :crlf_newline :      Replaces LF ("\n") with CRLF ("\r\n") if value
                          is true.

     :universal_newline : Replaces CRLF ("\r\n") and CR ("\r") with LF
                          ("\n") if value is true.

Activity

Hide
Thomas E Enebo added a comment -

Charlie landed a charset version of encode and encode! some time ago. It works for basic encoding support. Specific problems with encode methods should be opened as a new issue.

Show
Thomas E Enebo added a comment - Charlie landed a charset version of encode and encode! some time ago. It works for basic encoding support. Specific problems with encode methods should be opened as a new issue.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: