Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: abbrev.rb
#!/usr/bin/env ruby
[0] Fix | Delete
=begin
[1] Fix | Delete
#
[2] Fix | Delete
# Copyright (c) 2001,2003 Akinori MUSHA <knu@iDaemons.org>
[3] Fix | Delete
#
[4] Fix | Delete
# All rights reserved. You can redistribute and/or modify it under
[5] Fix | Delete
# the same terms as Ruby.
[6] Fix | Delete
#
[7] Fix | Delete
# $Idaemons: /home/cvs/rb/abbrev.rb,v 1.2 2001/05/30 09:37:45 knu Exp $
[8] Fix | Delete
# $RoughId: abbrev.rb,v 1.4 2003/10/14 19:45:42 knu Exp $
[9] Fix | Delete
# $Id: abbrev.rb 11708 2007-02-12 23:01:19Z shyouhei $
[10] Fix | Delete
=end
[11] Fix | Delete
[12] Fix | Delete
# Calculate the set of unique abbreviations for a given set of strings.
[13] Fix | Delete
#
[14] Fix | Delete
# require 'abbrev'
[15] Fix | Delete
# require 'pp'
[16] Fix | Delete
#
[17] Fix | Delete
# pp Abbrev::abbrev(['ruby', 'rules']).sort
[18] Fix | Delete
#
[19] Fix | Delete
# <i>Generates:</i>
[20] Fix | Delete
#
[21] Fix | Delete
# [["rub", "ruby"],
[22] Fix | Delete
# ["ruby", "ruby"],
[23] Fix | Delete
# ["rul", "rules"],
[24] Fix | Delete
# ["rule", "rules"],
[25] Fix | Delete
# ["rules", "rules"]]
[26] Fix | Delete
#
[27] Fix | Delete
# Also adds an +abbrev+ method to class +Array+.
[28] Fix | Delete
[29] Fix | Delete
module Abbrev
[30] Fix | Delete
[31] Fix | Delete
# Given a set of strings, calculate the set of unambiguous
[32] Fix | Delete
# abbreviations for those strings, and return a hash where the keys
[33] Fix | Delete
# are all the possible abbreviations and the values are the full
[34] Fix | Delete
# strings. Thus, given input of "car" and "cone", the keys pointing
[35] Fix | Delete
# to "car" would be "ca" and "car", while those pointing to "cone"
[36] Fix | Delete
# would be "co", "con", and "cone".
[37] Fix | Delete
#
[38] Fix | Delete
# The optional +pattern+ parameter is a pattern or a string. Only
[39] Fix | Delete
# those input strings matching the pattern, or begging the string,
[40] Fix | Delete
# are considered for inclusion in the output hash
[41] Fix | Delete
[42] Fix | Delete
def abbrev(words, pattern = nil)
[43] Fix | Delete
table = {}
[44] Fix | Delete
seen = Hash.new(0)
[45] Fix | Delete
[46] Fix | Delete
if pattern.is_a?(String)
[47] Fix | Delete
pattern = /^#{Regexp.quote(pattern)}/ # regard as a prefix
[48] Fix | Delete
end
[49] Fix | Delete
[50] Fix | Delete
words.each do |word|
[51] Fix | Delete
next if (abbrev = word).empty?
[52] Fix | Delete
while (len = abbrev.rindex(/[\w\W]\z/)) > 0
[53] Fix | Delete
abbrev = word[0,len]
[54] Fix | Delete
[55] Fix | Delete
next if pattern && pattern !~ abbrev
[56] Fix | Delete
[57] Fix | Delete
case seen[abbrev] += 1
[58] Fix | Delete
when 1
[59] Fix | Delete
table[abbrev] = word
[60] Fix | Delete
when 2
[61] Fix | Delete
table.delete(abbrev)
[62] Fix | Delete
else
[63] Fix | Delete
break
[64] Fix | Delete
end
[65] Fix | Delete
end
[66] Fix | Delete
end
[67] Fix | Delete
[68] Fix | Delete
words.each do |word|
[69] Fix | Delete
next if pattern && pattern !~ word
[70] Fix | Delete
[71] Fix | Delete
table[word] = word
[72] Fix | Delete
end
[73] Fix | Delete
[74] Fix | Delete
table
[75] Fix | Delete
end
[76] Fix | Delete
[77] Fix | Delete
module_function :abbrev
[78] Fix | Delete
end
[79] Fix | Delete
[80] Fix | Delete
class Array
[81] Fix | Delete
# Calculates the set of unambiguous abbreviations for the strings in
[82] Fix | Delete
# +self+. If passed a pattern or a string, only the strings matching
[83] Fix | Delete
# the pattern or starting with the string are considered.
[84] Fix | Delete
#
[85] Fix | Delete
# %w{ car cone }.abbrev #=> { "ca" => "car", "car" => "car",
[86] Fix | Delete
# "co" => "cone", "con" => cone",
[87] Fix | Delete
# "cone" => "cone" }
[88] Fix | Delete
def abbrev(pattern = nil)
[89] Fix | Delete
Abbrev::abbrev(self, pattern)
[90] Fix | Delete
end
[91] Fix | Delete
end
[92] Fix | Delete
[93] Fix | Delete
if $0 == __FILE__
[94] Fix | Delete
while line = gets
[95] Fix | Delete
hash = line.split.abbrev
[96] Fix | Delete
[97] Fix | Delete
hash.sort.each do |k, v|
[98] Fix | Delete
puts "#{k} => #{v}"
[99] Fix | Delete
end
[100] Fix | Delete
end
[101] Fix | Delete
end
[102] Fix | Delete
[103] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function