File: decode-pdf-string

package info (click to toggle)
ruby-asciidoctor-pdf 2.3.19-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,972 kB
  • sloc: ruby: 44,316; sh: 133; java: 45; makefile: 4
file content (29 lines) | stat: -rwxr-xr-x 653 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env ruby

str = ARGV[0]

def string_object_to_utf16 str
  [str.force_encoding(::Encoding::US_ASCII)].pack('H*').force_encoding ::Encoding::UTF_16BE
end

def string_object_to_utf8 str
  [str.force_encoding(::Encoding::US_ASCII)].pack('H*').force_encoding ::Encoding::UTF_8
end

def utf16_to_utf8 str
  str.encode ::Encoding::UTF_8
end

def decode_hexified_utf16_string_object str
  utf16_to_utf8 string_object_to_utf16 str
end

def decode_hexified_utf8_string_object str
  string_object_to_utf8 str
end

if ARGV[1] == 'utf8'
  puts decode_hexified_utf8_string_object ARGV[0].dup
else
  puts decode_hexified_utf16_string_object ARGV[0].dup
end