Module: Origami::String

Includes:
Object
Included in:
ByteString, HexaString
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

#<=>, #copy, #indirect_parent, #is_indirect?, parse, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #xrefs

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



115
116
117
# File 'lib/origami/string.rb', line 115

def encoding
  @encoding
end

Instance Method Details

#infer_encodingObject

:nodoc:



154
155
156
157
158
159
160
161
# File 'lib/origami/string.rb', line 154

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

#initialize(str) ⇒ Object

:nodoc:



119
120
121
122
# File 'lib/origami/string.rb', line 119

def initialize(str) #:nodoc:
  infer_encoding  
  super(str)
end

#real_typeObject



117
# File 'lib/origami/string.rb', line 117

def real_type ; Origami::String end

#to_pdfdocObject

Convert String object to a PDFDocEncoding encoded Ruby string.



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

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

#to_utf16beObject

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



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

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

#to_utf8Object

Convert String object to an UTF8 encoded Ruby string.



127
128
129
130
131
132
133
134
135
136
# File 'lib/origami/string.rb', line 127

def to_utf8
  require 'iconv'

  infer_encoding
  i = Iconv.new("UTF-8", "UTF-16")
    utf8str = i.iconv(self.encoding.to_utf16be(self.value))
  i.close

  utf8str
end