def encode_utf16(str, encoding = 0)  # :nodoc:
    # Exit if the $string isn't defined, i.e., hasn't been set by user.
    return [nil, nil] if str.nil?

    string = str.dup
    # Return if encoding is set, i.e., string has been manually encoded.
    #return ( undef, undef ) if $string == 1;

    ruby_19 { string = convert_to_ascii_if_ascii(string) }

    # Handle utf8 strings.
    if is_utf8?(string)
      string = utf8_to_16be(string)
      encoding = 1
    end

    # Chart strings are limited to 255 characters.
    limit = encoding != 0 ? 255 * 2 : 255

    if string.bytesize >= limit
      # truncate the string and raise a warning.
      string = string[0, limit]
    end

    [string, encoding]
  end
def encode_utf16(str, encoding = 0)  # :nodoc:
    # Exit if the $string isn't defined, i.e., hasn't been set by user.
    return [nil, nil] if str.nil?

    string = str.dup
    # Return if encoding is set, i.e., string has been manually encoded.
    #return ( undef, undef ) if $string == 1;

    ruby_19 { string = convert_to_ascii_if_ascii(string) }

    # Handle utf8 strings.
    if is_utf8?(string)
      string = utf8_to_16be(string)
      encoding = 1
    end

    # Chart strings are limited to 255 characters.
    limit = encoding != 0 ? 255 * 2 : 255

    if string.bytesize >= limit
      # truncate the string and raise a warning.
      string = string[0, limit]
    end

    [string, encoding]
  end
Convert UTF8 strings used in the chart to UTF16.