Sha256: 5f1b0cb2d2aef035e587e08f2106f6901888d5e2795b78b56ab3ad73393e9901

Contents?: true

Size: 820 Bytes

Versions: 3

Compression:

Stored size: 820 Bytes

Contents

module FlydataCore
module Redshift

class String
  # Redshift supports UTF-8 but it enforces stricter rule than other
  # implementations such as MySQL or Ruby.  This method returns a
  # Redshift-safe string from the given string.
  def self.encode(string, options = {})
    result = string.encoding == Encoding::UTF_8 ?
              string.encode(Encoding::UTF_16, options).encode(Encoding::UTF_8) :
              string.encode(Encoding::UTF_8, options)
    rep_str = options[:replace] || "\uFFFD"
    result.each_codepoint.with_index(0) do |cp, i|
      # Per Redshift document
      # http://docs.aws.amazon.com/redshift/latest/dg/multi-byte-character-load-errors.html
      if cp >= 0xFDD0 && cp <= 0xFDEF || cp == 0xFFFE || cp == 0xFFFF
        result[i] = rep_str
      end
    end
    result
  end
end

end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flydata-0.3.21 flydata-core/lib/flydata-core/redshift/string.rb
flydata-0.3.20 flydata-core/lib/flydata-core/redshift/string.rb
flydata-0.3.19 flydata-core/lib/flydata-core/redshift/string.rb