Module: HexaPDF::DictionaryFields::StringConverter
- Defined in:
- lib/hexapdf/dictionary_fields.rb
Overview
Converter module for string fields to automatically convert a string into UTF-8 encoding.
Class Method Summary collapse
-
.additional_types ⇒ Object
:nodoc:.
-
.convert(str, _type, _document) ⇒ Object
Converts the string into UTF-8 encoding, assuming it is currently a binary string.
-
.convert?(data, _type) ⇒ Boolean
Returns
true
if the given data should be converted to a UTF-8 encoded string. -
.usable_for?(type) ⇒ Boolean
This converter is usable if the
type
is the String class.
Class Method Details
.additional_types ⇒ Object
:nodoc:
241 242 |
# File 'lib/hexapdf/dictionary_fields.rb', line 241 def self.additional_types end |
.convert(str, _type, _document) ⇒ Object
Converts the string into UTF-8 encoding, assuming it is currently a binary string.
250 251 252 253 254 255 256 |
# File 'lib/hexapdf/dictionary_fields.rb', line 250 def self.convert(str, _type, _document) if str.getbyte(0) == 254 && str.getbyte(1) == 255 str[2..-1].force_encoding(Encoding::UTF_16BE).encode(Encoding::UTF_8) else Utils::PDFDocEncoding.convert_to_utf8(str) end end |
.convert?(data, _type) ⇒ Boolean
Returns true
if the given data should be converted to a UTF-8 encoded string.
245 246 247 |
# File 'lib/hexapdf/dictionary_fields.rb', line 245 def self.convert?(data, _type) data.kind_of?(String) && data.encoding == Encoding::BINARY end |
.usable_for?(type) ⇒ Boolean
This converter is usable if the type
is the String class.
236 237 238 |
# File 'lib/hexapdf/dictionary_fields.rb', line 236 def self.usable_for?(type) type == String end |