diff options
author | Toshiaki Asai <toshi.alternative@gmail.com> | 2014-04-24 00:36:14 +0900 |
---|---|---|
committer | Toshiaki Asai <toshi.alternative@gmail.com> | 2014-04-24 00:36:14 +0900 |
commit | 01d9132e83d085330437450fc8f96f1fd8fe3a0b (patch) | |
tree | 3eeaf171c1f8fa4c2b37c29bc305dfd1f1206ba8 | |
parent | a2b7f09c172f3b1b32395bb7b869879cd84bc989 (diff) | |
download | mikutter-01d9132e83d085330437450fc8f96f1fd8fe3a0b.tar.gz |
utils.rb で定義していた String#matches, String#each_matches を削除。全てString#scan で代用できるような使い方だったため
-rw-r--r-- | core/entity.rb | 3 | ||||
-rw-r--r-- | core/messageconverters.rb | 4 | ||||
-rw-r--r-- | core/mui/cairo_textselector.rb | 2 | ||||
-rw-r--r-- | core/mui/gtk_intelligent_textview.rb | 8 | ||||
-rw-r--r-- | core/plugin/openimg/openimg.rb | 4 | ||||
-rw-r--r-- | core/utils.rb | 2 |
6 files changed, 13 insertions, 10 deletions
diff --git a/core/entity.rb b/core/entity.rb index ac6025f4..8edb38ae 100644 --- a/core/entity.rb +++ b/core/entity.rb @@ -154,7 +154,8 @@ class Message::Entity result = Set.new(message_entities) @@linkrule.values.each{ |rule| if rule[:regexp] - message.to_show.each_matches(rule[:regexp]){ |match, byte, pos| + message.to_show.scan(rule[:regexp]){ |match| + pos = Regexp.last_match.begin(0) if not result.any?{ |this| this[:range].include?(pos) } result << @@filter[rule[:slug]].call(rule.merge({ :message => message, :range => Range.new(pos, pos + match.to_s.size, true), diff --git a/core/messageconverters.rb b/core/messageconverters.rb index 9ee90b84..7ead8521 100644 --- a/core/messageconverters.rb +++ b/core/messageconverters.rb @@ -62,14 +62,14 @@ class MessageConverters # textからURLを抜き出してすべて短縮したテキストを返す def shrink_url_all(text) - urls = text.matches(shrinkable_url_regexp) + urls = text.to_enum(:scan, shrinkable_url_regexp).map{ Regexp.last_match.to_s } return text if(urls.empty?) table = self.shrink_url(urls) text.gsub(shrinkable_url_regexp){ |k| table[k] } if table end # textからURLを抜き出してすべて展開したテキストを返す def expand_url_all(text) - urls = text.matches(shrinkable_url_regexp) + urls = text.to_enum(:scan, shrinkable_url_regexp).map{ Regexp.last_match.to_s } return text if(urls.empty?) table = self.expand_url(urls) text.gsub(shrinkable_url_regexp){ |k| table[k] } if table end diff --git a/core/mui/cairo_textselector.rb b/core/mui/cairo_textselector.rb index 0beae404..f7281489 100644 --- a/core/mui/cairo_textselector.rb +++ b/core/mui/cairo_textselector.rb @@ -84,7 +84,7 @@ module Gdk def markup(str, range, s, e) type_strict str => String - astr = str.matches(/<.*?>|&(?:gt|lt|amp);|./um) + astr = str.scan(/<.*?>|&(?:gt|lt|amp);|./um) arange_split(astr, range).reverse_each{ |arange| astr.insert(arange.last, e) astr.insert(arange.first, s) diff --git a/core/mui/gtk_intelligent_textview.rb b/core/mui/gtk_intelligent_textview.rb index 8fe181f7..be3fc200 100644 --- a/core/mui/gtk_intelligent_textview.rb +++ b/core/mui/gtk_intelligent_textview.rb @@ -145,9 +145,9 @@ class Gtk::IntelligentTextview < Gtk::TextView def apply_links @@linkrule.each{ |param| reg, left, right = param - buffer.text.each_matches(reg) { |match, index| + buffer.text.scan(reg) { |match| match = match.to_s - index = buffer.text[0, index].size + index = buffer.text[0, Regexp.last_match.begin(0)].size create_tag_ifnecessary(match, buffer, left, right) if not buffer.tag_table.lookup(match) range = buffer.get_range(index, match.size) buffer.apply_tag(match, *range) @@ -157,9 +157,9 @@ class Gtk::IntelligentTextview < Gtk::TextView offset = 0 @@widgetrule.each{ |param| reg, widget_generator = param - buffer.text.each_matches(reg) { |match, index| + buffer.text.scan(reg) { |match| match = match.to_s - index = [buffer.text.size, index].min + index = [buffer.text.size, Regexp.last_match.begin(0)].min range = buffer.get_range(index, match.size + offset) widget = widget_generator.call(match) if widget diff --git a/core/plugin/openimg/openimg.rb b/core/plugin/openimg/openimg.rb index e3a08f69..e5aab574 100644 --- a/core/plugin/openimg/openimg.rb +++ b/core/plugin/openimg/openimg.rb @@ -86,7 +86,7 @@ Plugin.create :openimg do def get_tag_by_attributes(tag) attribute = {} - tag.each_matches(/([^\s=]+)=(['"])(.*?)\2/){ |pair, pos| + tag.scan(/([^\s=]+)=(['"])(.*?)\2/){ |pair| key, val = pair[1], pair[3] attribute[key] = val } attribute.freeze end @@ -100,7 +100,7 @@ Plugin.create :openimg do if dom attribute = {} catch(:imgtag_match){ - dom.gsub("\n", ' ').each_matches(Regexp.new("<#{tag_name}.*?>")){ |str, pos| + dom.gsub("\n", ' ').scan(Regexp.new("<#{tag_name}.*?>")){ |str| attr = get_tag_by_attributes(str.to_s) if element_rule.all?{ |k, v| v === attr[k] } attribute = attr.freeze diff --git a/core/utils.rb b/core/utils.rb index 36b5f7cd..b5fa2782 100644 --- a/core/utils.rb +++ b/core/utils.rb @@ -391,6 +391,7 @@ class String match(str) end end def matches(regexp) + warn "String#matches is obsolete method. use String#scan" result = [] each_matches(regexp){ |m, pos| result << m.to_s } @@ -398,6 +399,7 @@ class String end def each_matches(regexp, &proc) # :yield: match, byte_index, char_intex + warn "String#each_matches is obsolete method. use String#scan" pos = 0 str = self while(match = regexp.match(str)) |