@@ -45,7 +45,8 @@ module Text
45
45
46
46
DefaultPatternSets = [ Rex ::Text ::UpperAlpha , Rex ::Text ::LowerAlpha , Rex ::Text ::Numerals ]
47
47
48
- # In case Iconv isn't loaded
48
+ # The Iconv translation table. The Iconv gem is deprecated in favor of
49
+ # String#encode, yet there is no encoding for EBCDIC. See #4525
49
50
Iconv_EBCDIC = [
50
51
"\x00 " , "\x01 " , "\x02 " , "\x03 " , "7" , "-" , "." , "/" , "\x16 " , "\x05 " ,
51
52
"%" , "\v " , "\f " , "\r " , "\x0E " , "\x0F " , "\x10 " , "\x11 " , "\x12 " , "\x13 " ,
@@ -386,9 +387,9 @@ def self.to_utf8(str)
386
387
#
387
388
class IllegalSequence < ArgumentError ; end
388
389
389
- # A native implementation of the ASCII->EBCDIC table, used to fall back from using
390
- # Iconv
391
- def self . to_ebcdic_rex ( str )
390
+ # A native implementation of the EBCDIC->ASCII table, since it's not available
391
+ # in String#encode
392
+ def self . to_ebcdic ( str )
392
393
new_str = [ ]
393
394
str . each_byte do |x |
394
395
if Iconv_ASCII . index ( x . chr )
@@ -400,9 +401,9 @@ def self.to_ebcdic_rex(str)
400
401
new_str . join
401
402
end
402
403
403
- # A native implementation of the EBCDIC->ASCII table, used to fall back from using
404
- # Iconv
405
- def self . from_ebcdic_rex ( str )
404
+ # A native implementation of the EBCDIC->ASCII table, since it's not available
405
+ # in String#encode
406
+ def self . from_ebcdic ( str )
406
407
new_str = [ ]
407
408
str . each_byte do |x |
408
409
if Iconv_EBCDIC . index ( x . chr )
@@ -414,29 +415,6 @@ def self.from_ebcdic_rex(str)
414
415
new_str . join
415
416
end
416
417
417
- def self . to_ebcdic ( str )
418
- begin
419
- Iconv . iconv ( "EBCDIC-US" , "ASCII" , str ) . first
420
- rescue ::Iconv ::IllegalSequence => e
421
- raise e
422
- rescue
423
- self . to_ebcdic_rex ( str )
424
- end
425
- end
426
-
427
- #
428
- # Converts EBCIDC to ASCII
429
- #
430
- def self . from_ebcdic ( str )
431
- begin
432
- Iconv . iconv ( "ASCII" , "EBCDIC-US" , str ) . first
433
- rescue ::Iconv ::IllegalSequence => e
434
- raise e
435
- rescue
436
- self . from_ebcdic_rex ( str )
437
- end
438
- end
439
-
440
418
#
441
419
# Returns the words in +str+ as an Array.
442
420
#
0 commit comments