Method: HexaPDF::Serializer#serialize_string
- Defined in:
- lib/hexapdf/serializer.rb
#serialize_string(obj) ⇒ Object
Serializes a String object.
See: PDF2.0 s7.3.4
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/hexapdf/serializer.rb', line 278 def serialize_string(obj) if obj.encoding != Encoding::BINARY && obj.match?(/[^ -~\t\r\n]/) utf16_encoded = true obj = "\xFE\xFF".b << obj.encode(Encoding::UTF_16BE).force_encoding(Encoding::BINARY) end obj = if @encrypter && @object.kind_of?(HexaPDF::Object) && @object.indirect? encrypter.encrypt_string(obj, @object) elsif utf16_encoded obj else obj.b end obj.gsub!(/[()\\\r]/n, STRING_ESCAPE_MAP) "(#{obj})" end |