Module: AEMEncodingSupport::DisableStringEncodings

Defined in:
lib/_aem/encodingsupport.rb

Class Method Summary collapse

Class Method Details

.pack_string(s, as_type) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/_aem/encodingsupport.rb', line 50

def DisableStringEncodings.pack_string(s, as_type)
  begin
    # Note: while the BOM is optional in typeUnicodeText, it's not included by AS
    # and some apps, e.g. iTunes 7, will handle it incorrectly, so it's omitted here.)
    return AE::AEDesc.new(KAE::TypeUTF8Text, s).coerce(as_type)
  rescue AE::MacOSError => e
    if e.to_i == -1700 # couldn't coerce to TypeUnicodeText
      raise TypeError, "Not valid UTF8 data or couldn't coerce to type %{as_type}: #{s.inspect}"
    else
      raise
    end
  end
end

.to_utf8_string(s) ⇒ Object

Support for Ruby 1.8 Strings, which do not contain encoding information. User is responsible for ensuring String instances passed to AE APIs contain UTF-8 encoded data; String instances returned by unpack_string will always contain contain UTF-8 encoded data.



46
47
48
# File 'lib/_aem/encodingsupport.rb', line 46

def DisableStringEncodings.to_utf8_string(s)
  return s
end

.unpack_string(desc) ⇒ Object



64
65
66
# File 'lib/_aem/encodingsupport.rb', line 64

def DisableStringEncodings.unpack_string(desc)
  return desc.coerce(KAE::TypeUTF8Text).data
end