Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: abbrev.rb
#--
[0] Fix | Delete
# Copyright (c) 2001,2003 Akinori MUSHA <knu@iDaemons.org>
[1] Fix | Delete
#
[2] Fix | Delete
# All rights reserved. You can redistribute and/or modify it under
[3] Fix | Delete
# the same terms as Ruby.
[4] Fix | Delete
#
[5] Fix | Delete
# $Idaemons: /home/cvs/rb/abbrev.rb,v 1.2 2001/05/30 09:37:45 knu Exp $
[6] Fix | Delete
# $RoughId: abbrev.rb,v 1.4 2003/10/14 19:45:42 knu Exp $
[7] Fix | Delete
# $Id: abbrev.rb 46784 2014-07-11 08:16:05Z hsbt $
[8] Fix | Delete
#++
[9] Fix | Delete
[10] Fix | Delete
##
[11] Fix | Delete
# Calculates the set of unambiguous abbreviations for a given set of strings.
[12] Fix | Delete
#
[13] Fix | Delete
# require 'abbrev'
[14] Fix | Delete
# require 'pp'
[15] Fix | Delete
#
[16] Fix | Delete
# pp Abbrev.abbrev(['ruby'])
[17] Fix | Delete
# #=> {"ruby"=>"ruby", "rub"=>"ruby", "ru"=>"ruby", "r"=>"ruby"}
[18] Fix | Delete
#
[19] Fix | Delete
# pp Abbrev.abbrev(%w{ ruby rules })
[20] Fix | Delete
#
[21] Fix | Delete
# _Generates:_
[22] Fix | Delete
# { "ruby" => "ruby",
[23] Fix | Delete
# "rub" => "ruby",
[24] Fix | Delete
# "rules" => "rules",
[25] Fix | Delete
# "rule" => "rules",
[26] Fix | Delete
# "rul" => "rules" }
[27] Fix | Delete
#
[28] Fix | Delete
# It also provides an array core extension, Array#abbrev.
[29] Fix | Delete
#
[30] Fix | Delete
# pp %w{ summer winter }.abbrev
[31] Fix | Delete
#
[32] Fix | Delete
# _Generates:_
[33] Fix | Delete
# { "summer" => "summer",
[34] Fix | Delete
# "summe" => "summer",
[35] Fix | Delete
# "summ" => "summer",
[36] Fix | Delete
# "sum" => "summer",
[37] Fix | Delete
# "su" => "summer",
[38] Fix | Delete
# "s" => "summer",
[39] Fix | Delete
# "winter" => "winter",
[40] Fix | Delete
# "winte" => "winter",
[41] Fix | Delete
# "wint" => "winter",
[42] Fix | Delete
# "win" => "winter",
[43] Fix | Delete
# "wi" => "winter",
[44] Fix | Delete
# "w" => "winter" }
[45] Fix | Delete
[46] Fix | Delete
module Abbrev
[47] Fix | Delete
[48] Fix | Delete
# Given a set of strings, calculate the set of unambiguous abbreviations for
[49] Fix | Delete
# those strings, and return a hash where the keys are all the possible
[50] Fix | Delete
# abbreviations and the values are the full strings.
[51] Fix | Delete
#
[52] Fix | Delete
# Thus, given +words+ is "car" and "cone", the keys pointing to "car" would
[53] Fix | Delete
# be "ca" and "car", while those pointing to "cone" would be "co", "con", and
[54] Fix | Delete
# "cone".
[55] Fix | Delete
#
[56] Fix | Delete
# require 'abbrev'
[57] Fix | Delete
#
[58] Fix | Delete
# Abbrev.abbrev(%w{ car cone })
[59] Fix | Delete
# #=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"}
[60] Fix | Delete
#
[61] Fix | Delete
# The optional +pattern+ parameter is a pattern or a string. Only input
[62] Fix | Delete
# strings that match the pattern or start with the string are included in the
[63] Fix | Delete
# output hash.
[64] Fix | Delete
#
[65] Fix | Delete
# Abbrev.abbrev(%w{car box cone crab}, /b/)
[66] Fix | Delete
# #=> {"box"=>"box", "bo"=>"box", "b"=>"box", "crab" => "crab"}
[67] Fix | Delete
#
[68] Fix | Delete
# Abbrev.abbrev(%w{car box cone}, 'ca')
[69] Fix | Delete
# #=> {"car"=>"car", "ca"=>"car"}
[70] Fix | Delete
def abbrev(words, pattern = nil)
[71] Fix | Delete
table = {}
[72] Fix | Delete
seen = Hash.new(0)
[73] Fix | Delete
[74] Fix | Delete
if pattern.is_a?(String)
[75] Fix | Delete
pattern = /\A#{Regexp.quote(pattern)}/ # regard as a prefix
[76] Fix | Delete
end
[77] Fix | Delete
[78] Fix | Delete
words.each do |word|
[79] Fix | Delete
next if word.empty?
[80] Fix | Delete
word.size.downto(1) { |len|
[81] Fix | Delete
abbrev = word[0...len]
[82] Fix | Delete
[83] Fix | Delete
next if pattern && pattern !~ abbrev
[84] Fix | Delete
[85] Fix | Delete
case seen[abbrev] += 1
[86] Fix | Delete
when 1
[87] Fix | Delete
table[abbrev] = word
[88] Fix | Delete
when 2
[89] Fix | Delete
table.delete(abbrev)
[90] Fix | Delete
else
[91] Fix | Delete
break
[92] Fix | Delete
end
[93] Fix | Delete
}
[94] Fix | Delete
end
[95] Fix | Delete
[96] Fix | Delete
words.each do |word|
[97] Fix | Delete
next if pattern && pattern !~ word
[98] Fix | Delete
[99] Fix | Delete
table[word] = word
[100] Fix | Delete
end
[101] Fix | Delete
[102] Fix | Delete
table
[103] Fix | Delete
end
[104] Fix | Delete
[105] Fix | Delete
module_function :abbrev
[106] Fix | Delete
end
[107] Fix | Delete
[108] Fix | Delete
class Array
[109] Fix | Delete
# Calculates the set of unambiguous abbreviations for the strings in +self+.
[110] Fix | Delete
#
[111] Fix | Delete
# require 'abbrev'
[112] Fix | Delete
# %w{ car cone }.abbrev
[113] Fix | Delete
# #=> {"car"=>"car", "ca"=>"car", "cone"=>"cone", "con"=>"cone", "co"=>"cone"}
[114] Fix | Delete
#
[115] Fix | Delete
# The optional +pattern+ parameter is a pattern or a string. Only input
[116] Fix | Delete
# strings that match the pattern or start with the string are included in the
[117] Fix | Delete
# output hash.
[118] Fix | Delete
#
[119] Fix | Delete
# %w{ fast boat day }.abbrev(/^.a/)
[120] Fix | Delete
# #=> {"fast"=>"fast", "fas"=>"fast", "fa"=>"fast", "day"=>"day", "da"=>"day"}
[121] Fix | Delete
#
[122] Fix | Delete
# Abbrev.abbrev(%w{car box cone}, "ca")
[123] Fix | Delete
# #=> {"car"=>"car", "ca"=>"car"}
[124] Fix | Delete
#
[125] Fix | Delete
# See also Abbrev.abbrev
[126] Fix | Delete
def abbrev(pattern = nil)
[127] Fix | Delete
Abbrev::abbrev(self, pattern)
[128] Fix | Delete
end
[129] Fix | Delete
end
[130] Fix | Delete
[131] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function