lib/text/levenshtein.rb in text-0.1.13 vs lib/text/levenshtein.rb in text-0.1.14

- old
+ new

@@ -25,14 +25,17 @@ # When using Unicode text, be aware that this algorithm does not perform normalisation. # If there is a possibility of different normalised forms being used, normalisation # should be performed beforehand. # def distance(str1, str2) - if $KCODE =~ /^U/i + encoding = defined?(Encoding) ? str1.encoding.to_s : $KCODE + + if Text.encoding_of(str1) =~ /^U/i unpack_rule = 'U*' else unpack_rule = 'C*' end + s = str1.unpack(unpack_rule) t = str2.unpack(unpack_rule) n = s.length m = t.length return m if (0 == n) \ No newline at end of file