Skip to content

Commit

Permalink
QPID-3925 - Fix string encoding support for Ruby 1.9
Browse files Browse the repository at this point in the history
Applied patch from Will Benton/Darryl Pierce


git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1326663 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ted-ross committed Apr 16, 2012
1 parent 405a5b8 commit 2bab1a8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions qpid/cpp/bindings/qmf/ruby/qmf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ module Qmf
end
end

module StringHelpers
def ensure_encoding(str)
enc = (Encoding.default_external.name || "UTF-8" rescue "UTF-8")
str.respond_to?(:force_encoding) ? str.force_encoding(enc) : str
end
end

class Util
include StringHelpers

def qmf_to_native(val)
case val.getType
when TYPE_UINT8, TYPE_UINT16, TYPE_UINT32 then val.asUint
when TYPE_UINT64 then val.asUint64
when TYPE_SSTR, TYPE_LSTR then val.asString
when TYPE_SSTR, TYPE_LSTR then ensure_encoding(val.asString)
when TYPE_ABSTIME then val.asInt64
when TYPE_DELTATIME then val.asUint64
when TYPE_REF then ObjectId.new(val.asObjectId)
Expand Down Expand Up @@ -162,6 +171,7 @@ def list_to_value(val, list)
##==============================================================================

class ConnectionSettings
include StringHelpers
attr_reader :impl

def initialize(url = nil)
Expand Down Expand Up @@ -193,7 +203,7 @@ def set_attr(key, val)
def get_attr(key)
_v = @impl.getAttr(key)
if _v.isString()
return _v.asString()
return ensure_encoding(_v.asString())
elsif _v.isUint()
return _v.asUint()
elsif _v.isBool()
Expand Down Expand Up @@ -708,6 +718,8 @@ def set(key, value)
end

class MethodResponse
include StringHelpers

def initialize(impl)
@impl = Qmfengine::MethodResponse.new(impl)
end
Expand All @@ -721,7 +733,7 @@ def exception
end

def text
exception.asString
ensure_encoding(exception.asString)
end

def args
Expand Down Expand Up @@ -886,6 +898,7 @@ def to_s
end

class SchemaClassKey
include StringHelpers
attr_reader :impl
def initialize(i)
@impl = Qmfengine::SchemaClassKey.new(i)
Expand All @@ -900,7 +913,7 @@ def class_name
end

def to_s
@impl.asString
ensure_encoding(@impl.asString)
end
end

Expand Down

0 comments on commit 2bab1a8

Please sign in to comment.