Sha256: 4afd820e076359d9179b700cd17fc37b4bb29143771f55f4fc0237dfbde01eb7
Contents?: true
Size: 870 Bytes
Versions: 20
Compression:
Stored size: 870 Bytes
Contents
module OverSIP module Utils # It ensures that two identical byte secuences are matched regardless # they have different encoding. # For example in Ruby the following returns false: # "iñaki".force_encoding(::Encoding::BINARY) == "iñaki" def self.string_compare string1, string2 string1.force_encoding(::Encoding::BINARY) == string2.force_encoding(::Encoding::BINARY) end # This avoid "invalid byte sequence in UTF-8" when the directly doing: # string =~ /EXPRESSION/ # and string has invalid UTF-8 bytes secuence. # NOTE: expression argument must be a Regexp expression (with / symbols at the # begining and at the end). def self.regexp_compare string, expression return false unless string && string.valid_encoding? string.force_encoding(::Encoding::BINARY) =~ expression end end end
Version data entries
20 entries across 20 versions & 1 rubygems