module Qpid::Proton::Types

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Constants

ARRAY
BINARY
BOOL
BYTE
CHAR
DECIMAL128
DECIMAL32
DECIMAL64
DESCRIBED
DOUBLE
Described
FLOAT
INT
LIST
LONG
MAP
NULL

@!group

SHORT
STRING
SYMBOL
TIMESTAMP
UBYTE
UINT
ULONG
USHORT
UUID

Public Class Methods

is_valid_utf?(value) click to toggle source

@private

# File lib/types/strings.rb, line 22
def self.is_valid_utf?(value)
  # In Ruby 1.9+ we have encoding methods that can check the content of
  # the string, so use them to see if what we have is unicode. If so,
  # good! If not, then just treat is as binary.
  #
  # No such thing in Ruby 1.8. So there we need to use Iconv to try and
  # convert it to unicode. If it works, good! But if it raises an
  # exception then we'll treat it as binary.
  if RUBY_VERSION < "1.9"
    return true if value.isutf8
    return false
  else
    return true if (value.encoding == "UTF-8" ||
                    value.encode("UTF-8").valid_encoding?)

    return false
  end
end