Class: Unisec::Decdump
- Inherits:
-
Object
- Object
- Unisec::Decdump
- Defined in:
- lib/unisec/decdump.rb
Overview
Decimal dump (decdump) of all Unicode encodings.
Instance Attribute Summary collapse
-
#utf16be ⇒ String
readonly
UTF-16BE decdump.
-
#utf16le ⇒ String
readonly
UTF-16LE decdump.
-
#utf32be ⇒ String
readonly
UTF-32BE decdump.
-
#utf32le ⇒ String
readonly
UTF-32LE decdump.
-
#utf8 ⇒ String
readonly
UTF-8 decdump.
Class Method Summary collapse
-
.utf16be(str) ⇒ String
Encode to UTF-16BE in decdump format (packed by code unit = every 2 bytes).
-
.utf16le(str) ⇒ String
Encode to UTF-16LE in decdump format (packed by code unit = every 2 bytes).
-
.utf32be(str) ⇒ String
Encode to UTF-32BE in decdump format (packed by code unit = every 4 bytes).
-
.utf32le(str) ⇒ String
Encode to UTF-32LE in decdump format (packed by code unit = every 4 bytes).
-
.utf8(str) ⇒ String
Encode to UTF-8 in decdump format (spaced at every code unit = every byte).
Instance Method Summary collapse
-
#display ⇒ String
Display a CLI-friendly output summurizing the decdump in all Unicode encodings.
-
#initialize(str) ⇒ Decdump
constructor
Init the decdump.
Constructor Details
#initialize(str) ⇒ Decdump
Init the decdump.
36 37 38 39 40 41 42 |
# File 'lib/unisec/decdump.rb', line 36 def initialize(str) @utf8 = Decdump.utf8(str) @utf16be = Decdump.utf16be(str) @utf16le = Decdump.utf16le(str) @utf32be = Decdump.utf32be(str) @utf32le = Decdump.utf32le(str) end |
Instance Attribute Details
#utf16be ⇒ String (readonly)
UTF-16BE decdump
15 16 17 |
# File 'lib/unisec/decdump.rb', line 15 def utf16be @utf16be end |
#utf16le ⇒ String (readonly)
UTF-16LE decdump
19 20 21 |
# File 'lib/unisec/decdump.rb', line 19 def utf16le @utf16le end |
#utf32be ⇒ String (readonly)
UTF-32BE decdump
23 24 25 |
# File 'lib/unisec/decdump.rb', line 23 def utf32be @utf32be end |
#utf32le ⇒ String (readonly)
UTF-32LE decdump
27 28 29 |
# File 'lib/unisec/decdump.rb', line 27 def utf32le @utf32le end |
#utf8 ⇒ String (readonly)
UTF-8 decdump
11 12 13 |
# File 'lib/unisec/decdump.rb', line 11 def utf8 @utf8 end |
Class Method Details
.utf16be(str) ⇒ String
Encode to UTF-16BE in decdump format (packed by code unit = every 2 bytes)
58 59 60 61 62 63 |
# File 'lib/unisec/decdump.rb', line 58 def self.utf16be(str) dec_chuncks = str.encode('UTF-16BE').to_hex.scan(/.{2}/).map do |x| x.hex2dec(padding: 3) end dec_chuncks.join(' ').scan(/\d+ \d+/).map { |x| "|#{x}|" }.join(' ') end |
.utf16le(str) ⇒ String
Encode to UTF-16LE in decdump format (packed by code unit = every 2 bytes)
70 71 72 73 74 75 |
# File 'lib/unisec/decdump.rb', line 70 def self.utf16le(str) dec_chuncks = str.encode('UTF-16LE').to_hex.scan(/.{2}/).map do |x| x.hex2dec(padding: 3) end dec_chuncks.join(' ').scan(/\d+ \d+/).map { |x| "|#{x}|" }.join(' ') end |
.utf32be(str) ⇒ String
Encode to UTF-32BE in decdump format (packed by code unit = every 4 bytes)
82 83 84 85 86 87 |
# File 'lib/unisec/decdump.rb', line 82 def self.utf32be(str) dec_chuncks = str.encode('UTF-32BE').to_hex.scan(/.{2}/).map do |x| x.hex2dec(padding: 3) end dec_chuncks.join(' ').scan(/\d+ \d+ \d+ \d+/).map { |x| "|#{x}|" }.join(' ') end |
.utf32le(str) ⇒ String
Encode to UTF-32LE in decdump format (packed by code unit = every 4 bytes)
94 95 96 97 98 99 |
# File 'lib/unisec/decdump.rb', line 94 def self.utf32le(str) dec_chuncks = str.encode('UTF-32LE').to_hex.scan(/.{2}/).map do |x| x.hex2dec(padding: 3) end dec_chuncks.join(' ').scan(/\d+ \d+ \d+ \d+/).map { |x| "|#{x}|" }.join(' ') end |
.utf8(str) ⇒ String
Encode to UTF-8 in decdump format (spaced at every code unit = every byte)
49 50 51 |
# File 'lib/unisec/decdump.rb', line 49 def self.utf8(str) str.encode('UTF-8').to_hex.scan(/.{2}/).map { |x| x.hex2dec(padding: 3) }.join(' ') end |
Instance Method Details
#display ⇒ String
Display a CLI-friendly output summurizing the decdump in all Unicode encodings
110 111 112 113 114 115 116 |
# File 'lib/unisec/decdump.rb', line 110 def display "UTF-8: #{@utf8}\n" \ "UTF-16BE: #{@utf16be}\n" \ "UTF-16LE: #{@utf16le}\n" \ "UTF-32BE: #{@utf32be}\n" \ "UTF-32LE: #{@utf32le}".gsub('|', Paint['|', :red]) end |