From: cedlemo <nu...@co...> - 2017-08-06 07:08:23
|
cedlemo 2017-08-03 02:07:48 +0900 (Thu, 03 Aug 2017) New Revision: 94891b801b5ecb9d7421cbf8eed52d6da659628a https://github.com/ruby-gnome2/ruby-gnome2/commit/94891b801b5ecb9d7421cbf8eed52d6da659628a Merged 33cf5d9: Merge pull request #1087 from cedlemo/vte3_regex Message: Add support for Vte::Regex Added files: vte3/lib/vte3/regex.rb Modified files: vte3/lib/vte3/loader.rb Modified: vte3/lib/vte3/loader.rb (+1 -0) =================================================================== --- vte3/lib/vte3/loader.rb 2017-08-03 00:10:10 +0900 (0d445a5d4) +++ vte3/lib/vte3/loader.rb 2017-08-03 02:07:48 +0900 (ee5dd52c4) @@ -44,6 +44,7 @@ module Vte require "vte3/pty" require "vte3/terminal" require "vte3/version" + require "vte3/regex" # need to be after version because I use Version.or_later? in it require "vte3/deprecated" end Added: vte3/lib/vte3/regex.rb (+52 -0) 100644 =================================================================== --- /dev/null +++ vte3/lib/vte3/regex.rb 2017-08-03 02:07:48 +0900 (3d99735d2) @@ -0,0 +1,52 @@ +# Copyright (C) 2015 Ruby-GNOME2 Project Team +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +module Vte + if Version.or_later?(0, 46) + class Regex + alias_method :initialize_raw, :initialize + def initialize(pattern, compile_flags, options) + flags = parse_compile_flags(compile_flags) + if options[:for_match] + initialize_new_for_match(pattern, pattern.length, flags) + elsif options[:for_search] + initialize_new_for_search(pattern, pattern.length, flags) + else + raise(ArgumentError, + "must specify usage :for_match or :for_search : #{options.inspect}") + end + end + + private + + def parse_compile_flags(compile_flags) + return compile_flags if compile_flags.class == Integer + + flags = 0 + return flags unless compile_flags.class == Array + + compile_flags.each do |flag| + begin + flags = flags | GLib::RegexCompileFlags.const_get(flag.to_s.upcase).to_i + rescue + end + end + + flags + end + end + end +end |