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

- old
+ new

@@ -9,22 +9,24 @@ # easier-to-pronounce-and-spell 'edit distance'. # # Author: Paul Battley (pbattley@gmail.com) # +require "text/util" + module Text # :nodoc: module Levenshtein # Calculate the Levenshtein distance between two strings +str1+ and +str2+. # +str1+ and +str2+ should be ASCII, UTF-8, or a one-byte-per character encoding such # as ISO-8859-*. # # The strings will be treated as UTF-8 if $KCODE is set appropriately (i.e. 'u'). - # Otherwise, the comparison will be performed byte-by-byte. There is no specific support + # Otherwise, the comparison will be performed byte-by-byte. There is no specific support # for Shift-JIS or EUC strings. # - # When using Unicode text, be aware that this algorithm does not perform normalisation. + # 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) encoding = defined?(Encoding) ? str1.encoding.to_s : $KCODE @@ -39,11 +41,11 @@ t = str2.unpack(unpack_rule) n = s.length m = t.length return m if (0 == n) return n if (0 == m) - + d = (0..m).to_a x = nil (0...n).each do |i| e = i+1 @@ -63,6 +65,6 @@ return x end extend self end -end \ No newline at end of file +end