Sha256: cb751bc6eee23fe4fdaffe0dfe650bd1df31d36354d4d08f4c411f82e16e40b6
Contents?: true
Size: 825 Bytes
Versions: 26
Compression:
Stored size: 825 Bytes
Contents
# frozen_string_literal: true require 'rchardet' module Git # Method that can be used to detect and normalize string encoding module EncodingUtils def self.default_encoding __ENCODING__.name end def self.best_guess_encoding # Encoding::ASCII_8BIT.name Encoding::UTF_8.name end def self.detected_encoding(str) CharDet.detect(str)['encoding'] || best_guess_encoding end def self.encoding_options { invalid: :replace, undef: :replace } end def self.normalize_encoding(str) return str if str.valid_encoding? && str.encoding.name == default_encoding return str.encode(default_encoding, str.encoding, **encoding_options) if str.valid_encoding? str.encode(default_encoding, detected_encoding(str), **encoding_options) end end end
Version data entries
26 entries across 26 versions & 1 rubygems