Sha256: d11a80d63f42aad1c7119d2f8c367d0a3c5be4c0d7caf3812c70c0e5f38afae6
Contents?: true
Size: 1.1 KB
Versions: 76
Compression:
Stored size: 1.1 KB
Contents
module FlydataCore module Redshift class String NULL_CHAR_CODE_POINTS = "\\0".codepoints # 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 = {}) encoded_str = string.encoding == Encoding::UTF_8 ? string.encode(Encoding::UTF_16, options).encode(Encoding::UTF_8) : string.encode(Encoding::UTF_8, options) ret_cpts = [] rep_str_cpts = (options[:replace] || "\uFFFD").codepoints replaced = false encoded_str.each_codepoint do |cp| # 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 ret_cpts.concat(rep_str_cpts) replaced = true elsif cp == 0x0000 ret_cpts.concat(NULL_CHAR_CODE_POINTS) replaced = true else ret_cpts << cp end end replaced ? ret_cpts.pack("U*") : encoded_str end end end end
Version data entries
76 entries across 76 versions & 1 rubygems