module Spotify::UTF8String

A UTF-8 FFI type, making sure all strings are UTF8 in and out.

Given an ingoing (ruby to C) string, it will make sure the string is in UTF-8 encoding. An outgoing (C to Ruby) will be assumed to actually be in UTF-8, and force-encoded as such.

Public Class Methods

from_native(value, ctx) click to toggle source

Given an original string, assume it is in UTF-8.

@note NO error checking is made, the string is just forced to UTF-8 @param [String] value can be in any encoding @param ctx @return [String] value, but with UTF-8 encoding

# File lib/spotify/data_converters/utf8_string.rb, line 30
def from_native(value, ctx)
  value && value.force_encoding(Encoding::UTF_8)
end
to_native(value, ctx) click to toggle source

Given a value, encodes it to UTF-8 no matter what.

@note if the value is already in UTF-8, ruby does nothing @note if the given value is falsy, default behaviour is used

@param [String, nil] value @param ctx @return [String] value, but in UTF-8 if it wasn’t already

# File lib/spotify/data_converters/utf8_string.rb, line 20
def to_native(value, ctx)
  value && value.encode(Encoding::UTF_8)
end