Module: Origami::String

Includes:
Object
Included in:
HexaString, LiteralString
Defined in:
lib/origami/string.rb

Overview

Module common to String objects.

Defined Under Namespace

Modules: Encoding

Constant Summary

Constants included from Object

Object::TOKENS

Instance Attribute Summary collapse

Attributes included from Object

#file_offset, #generation, #no, #objstm_offset, #parent

Instance Method Summary collapse

Methods included from Object

#cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, #numbered?, parse, #post_build, #pre_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #version_required, #xrefs

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



110
111
112
# File 'lib/origami/string.rb', line 110

def encoding
  @encoding
end

Instance Method Details

#detect_encodingObject

:nodoc:



146
147
148
149
150
151
152
# File 'lib/origami/string.rb', line 146

def detect_encoding #:nodoc:
    if self.value[0,2] == Encoding::UTF16BE::BOM
        @encoding = Encoding::UTF16BE
    else
        @encoding = Encoding::PDFDocEncoding
    end
end

#initialize(str) ⇒ Object

:nodoc:



112
113
114
115
116
# File 'lib/origami/string.rb', line 112

def initialize(str) #:nodoc:
    super(str.force_encoding('binary'))

    detect_encoding
end

#to_pdfdocObject

Convert String object to a PDFDocEncoding encoded binary Ruby string.



141
142
143
144
# File 'lib/origami/string.rb', line 141

def to_pdfdoc
    detect_encoding
    self.encoding.to_pdfdoc(self.value)
end

#to_utf16beObject

Convert String object to an UTF16-BE encoded binary Ruby string.



133
134
135
136
# File 'lib/origami/string.rb', line 133

def to_utf16be
    detect_encoding
    self.encoding.to_utf16be(self.value)
end

#to_utf8Object

Convert String object to an UTF8 encoded Ruby string.



121
122
123
124
125
126
127
128
# File 'lib/origami/string.rb', line 121

def to_utf8
    detect_encoding

    utf16 = self.encoding.to_utf16be(self.value)
    utf16.slice!(0, Encoding::UTF16BE::BOM.size)

    utf16.encode("utf-8", "utf-16be")
end