Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adjusting code to meet typical Ruby style.

This is typical Ruby style:
  def a_method(parameter)
    # ...
  end

This is not:
  def a_method( parameter )
    # ...
  end

Also cleaned up whitespace at ends of lines.

Signed-off-by: Pritesh <pritesh@phatforge.com>
  • Loading branch information...
commit af19a6339cd6ca119a353dd7172cfa756c3f218f 1 parent 693664d
David James djsun authored jasherai committed
Showing with 126 additions and 126 deletions.
  1. +126 −126 lib/oniguruma.rb
252 lib/oniguruma.rb
View
@@ -77,48 +77,48 @@ module Oniguruma
ENCODING_GB18030 = 31
ENCODING_UNDEF = 32
-
+
class ORegexp
-
+
class << self
# :stopdoc:
alias compile new
# :startdoc:
-
+
# call-seq:
# ORegexp.escape(str) => a_str
# ORegexp.quote(str) => a_str
- #
+ #
# Escapes any characters that would have special meaning in a regular
# expression. Returns a new escaped string, or self if no characters are
# escaped. For any string,
# <code>Regexp.escape(<i>str</i>)=~<i>str</i></code> will be true.
- #
+ #
# ORegexp.escape('\\*?{}.') #=> \\\\\*\?\{\}\.
- #
-
- def escape( *args )
- Regexp.escape( *args )
+ #
+
+ def escape(*args)
+ Regexp.escape(*args)
end
# :stopdoc:
alias quote escape
# :startdoc:
-
+
# call-seq:
# ORegexp.last_match => matchdata
# ORegexp.last_match(fixnum) => str
- #
+ #
# The first form returns the <code>MatchData</code> object generated by the
# last successful pattern match. The second form returns the nth field in this
# <code>MatchData</code> object.
- #
- # ORegexp.new( 'c(.)t' ) =~ 'cat' #=> 0
- # ORegexp.last_match #=> #<MatchData:0x401b3d30>
- # ORegexp.last_match(0) #=> "cat"
- # ORegexp.last_match(1) #=> "a"
- # ORegexp.last_match(2) #=> nil
-
- def last_match( index = nil)
+ #
+ # ORegexp.new('c(.)t') =~ 'cat' #=> 0
+ # ORegexp.last_match #=> #<MatchData:0x401b3d30>
+ # ORegexp.last_match(0) #=> "cat"
+ # ORegexp.last_match(1) #=> "a"
+ # ORegexp.last_match(2) #=> nil
+
+ def last_match(index = nil)
if index
@@last_match[index]
else
@@ -126,37 +126,37 @@ def last_match( index = nil)
end
end
end
-
+
# :stopdoc:
- alias old_initialize initialize
+ alias old_initialize initialize
# :startdoc:
-
+
# call-seq:
- # ORegexp.new( pattern, options_hash )
- # ORegexp.new( pattern, option_str, encoding_str=nil, syntax_str=nil)
+ # ORegexp.new(pattern, options_hash)
+ # ORegexp.new(pattern, option_str, encoding_str=nil, syntax_str=nil)
#
- # Constructs a new regular expression from <i>pattern</i>, which is a
- # <code>String</code>. The second parameter <i></i> may be a <code>Hash</code>
+ # Constructs a new regular expression from <i>pattern</i>, which is a
+ # <code>String</code>. The second parameter <i></i> may be a <code>Hash</code>
# of the form:
#
# <code>{ :options => option_value, :encoding => encoding_value, :syntax => syntax_value }</code>
#
- # Where <code>option_value</code> is a bitwise <code>OR</code> of
+ # Where <code>option_value</code> is a bitwise <code>OR</code> of
# <code>Oniguruma::OPTION_XXX</code> constants; <code>encoding_value</code>
- # is one of <code>Oniguruma::ENCODING_XXX</code> constants; and
+ # is one of <code>Oniguruma::ENCODING_XXX</code> constants; and
# <code>syntax_value</code> is one of <code>Oniguruma::SYNTAX_XXX</code>
# constants.
- #
- # r1 = ORegexp.new('^a-z+:\\s+\w+') #=> /^a-z+:\s+\w+/
- # r2 = ORegexp.new('cat', :options => OPTION_IGNORECASE ) #=> /cat/i
- # r3 = ORegexp.new('dog', :options => OPTION_EXTEND ) #=> /dog/x
+ #
+ # r1 = ORegexp.new('^a-z+:\\s+\w+') #=> /^a-z+:\s+\w+/
+ # r2 = ORegexp.new('cat', :options => OPTION_IGNORECASE) #=> /cat/i
+ # r3 = ORegexp.new('dog', :options => OPTION_EXTEND) #=> /dog/x
#
# #Accept java syntax on SJIS encoding:
- # r4 = ORegexp.new('ape', :syntax => SYNTAX_JAVA, :encoding => ENCODING_SJIS) #=> /ape/
- #
+ # r4 = ORegexp.new('ape', :syntax => SYNTAX_JAVA, :encoding => ENCODING_SJIS) #=> /ape/
+ #
# Second form uses string shortcuts to set options and encoding:
# r = ORegexp.new('cat', 'i', 'utf8', 'java')
-
+
def initialize(pattern, *args)
defaults = {
:options => OPTION_DEFAULT,
@@ -180,29 +180,29 @@ def initialize(pattern, *args)
end
old_initialize(pattern, defaults.merge(options).freeze)
end
-
+
# call-seq:
# rxp == other_rxp => true or false
# rxp.eql?(other_rxp) => true or false
- #
+ #
# Equality---Two regexps are equal if their patterns are identical, they have
# the same character set code, and their <code>#casefold?</code> values are the
# same.
-
+
def == regexp
@pattern == regexp.source && kcode == regexp.kcode && casefold? == regexp.casefold?
end
alias eql? ==
-
+
# call-seq:
# rxp.casefold? => true of false
#
# Returns the value of the case-insensitive flag.
-
+
def casefold?
(@options[:options] & OPTION_IGNORECASE) > 0
end
-
+
# call-seq:
# rxp.kode => int
#
@@ -210,29 +210,29 @@ def casefold?
def kcode
@options[:encoding]
end
-
+
# call-seq:
# rxp.options => fixnum
- #
+ #
# Returns the set of bits corresponding to the options used when creating this
# ORegexp (see <code>ORegexp::new</code> for details. Note that additional bits
# may be set in the returned options: these are used internally by the regular
# expression code. These extra bits are ignored if the options are passed to
# <code>ORegexp::new</code>.
- #
- # Oniguruma::OPTION_IGNORECASE #=> 1
- # Oniguruma::OPTION_EXTEND #=> 2
- # Oniguruma::OPTION_MULTILINE #=> 4
- #
- # Regexp.new(r.source, :options => Oniguruma::OPTION_EXTEND ) #=> 2
-
+ #
+ # Oniguruma::OPTION_IGNORECASE #=> 1
+ # Oniguruma::OPTION_EXTEND #=> 2
+ # Oniguruma::OPTION_MULTILINE #=> 4
+ #
+ # Regexp.new(r.source, :options => Oniguruma::OPTION_EXTEND) #=> 2
+
def options
@options[:options]
end
-
+
# call-seq:
# rxp.to_s => str
- #
+ #
# Returns a string containing the regular expression and its options (using the
# <code>(?xxx:yyy)</code> notation. This string can be fed back in to
# <code>Regexp::new</code> to a regular expression with the same semantics as
@@ -240,14 +240,14 @@ def options
# comparing the two, as the source of the regular expression itself may
# differ, as the example shows). <code>Regexp#inspect</code> produces a
# generally more readable version of <i>rxp</i>.
- #
- # r1 = ORegexp.new( 'ab+c', :options OPTION_IGNORECASE | OPTION_EXTEND ) #=> /ab+c/ix
- # s1 = r1.to_s #=> "(?ix-m:ab+c)"
- # r2 = ORegexp.new(s1) #=> /(?ix-m:ab+c)/
- # r1 == r2 #=> false
- # r1.source #=> "ab+c"
- # r2.source #=> "(?ix-m:ab+c)"
-
+ #
+ # r1 = ORegexp.new('ab+c', :options OPTION_IGNORECASE | OPTION_EXTEND) #=> /ab+c/ix
+ # s1 = r1.to_s #=> "(?ix-m:ab+c)"
+ # r2 = ORegexp.new(s1) #=> /(?ix-m:ab+c)/
+ # r1 == r2 #=> false
+ # r1.source #=> "ab+c"
+ # r2.source #=> "(?ix-m:ab+c)"
+
def to_s
opt_str = "(?"
opt_str += "i" if (@options[:options] & OPTION_IGNORECASE) > 0
@@ -262,16 +262,16 @@ def to_s
opt_str += ")"
opt_str + @pattern
end
-
-
+
+
# call-seq:
# rxp.inspect => string
#
# Returns a readable version of <i>rxp</i>
#
- # ORegexp.new( 'cat', :options => OPTION_MULTILINE | OPTION_IGNORECASE ).inspect => /cat/im
- # ORegexp.new( 'cat', :options => OPTION_MULTILINE | OPTION_IGNORECASE ).to_s => (?im-x)cat
-
+ # ORegexp.new('cat', :options => OPTION_MULTILINE | OPTION_IGNORECASE).inspect => /cat/im
+ # ORegexp.new('cat', :options => OPTION_MULTILINE | OPTION_IGNORECASE).to_s => (?im-x)cat
+
def inspect
opt_str = ""
opt_str += "i" if (@options[:options] & OPTION_IGNORECASE) > 0
@@ -279,21 +279,21 @@ def inspect
opt_str += "x" if (@options[:options] & OPTION_EXTEND) > 0
"/" + @pattern + "/" + opt_str
end
-
+
# call-seq:
# rxp.source => str
- #
+ #
# Returns the original string of the pattern.
- #
- # ORegexp.new( 'ab+c', 'ix' ).source #=> "ab+c"
+ #
+ # ORegexp.new('ab+c', 'ix').source #=> "ab+c"
def source
@pattern.freeze
end
-
+
alias match_all scan
-
+
end
-
+
end
class ::String
@@ -301,31 +301,31 @@ class ::String
def ogsub(*args)
Oniguruma::ORegexp.new(args.shift).gsub(self, *args)
end
-
+
# Calls <code>Oniguruma::ORegexp#gsub!</code> on this string.
def ogsub!(*args)
Oniguruma::ORegexp.new(args.shift).gsub!(self, *args)
end
-
+
# Calls <code>Oniguruma::ORegexp#sub</code> on this string.
def osub(re, *args)
- Oniguruma::ORegexp.new( re ).sub(self, *args)
+ Oniguruma::ORegexp.new(re).sub(self, *args)
end
-
+
# Calls <code>Oniguruma::ORegexp#sub!</code> on this string.
def osub!(re, *args)
- Oniguruma::ORegexp.new( re ).sub(self, *args)
+ Oniguruma::ORegexp.new(re).sub(self, *args)
end
end
class ::MatchData
# call-seq:
# to_index[symbol] => int or nil
- #
- # Returns the group index for the corresponding named group, or
+ #
+ # Returns the group index for the corresponding named group, or
# <code>nil</code> if the group does not exist.
- #
- # m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
+ #
+ # m = ORegexp.new('(?<begin>^.*?)(?<middle>\d)(?<end>.*)').match("THX1138")
# m.to_index[:begin] #=> 1
# m.to_index[:unknown] #=> nil
def to_index symbol
@@ -333,20 +333,20 @@ def to_index symbol
end
alias old_aref :[]
-
+
# call-seq:
# mtch[i] => obj
# mtch[start, length] => array
# mtch[range] => array
# mtch[symbol] => obj
- #
+ #
# <code>MatchData</code> acts as an array, and may be
# accessed using the normal array indexing techniques. <i>mtch</i>[0] is
# equivalent to the special variable <code>$&</code>, and returns the entire
# matched string. <i>mtch</i>[1], <i>mtch</i>[2], and so on return the values
# of the matched backreferences (portions of the pattern between parentheses).
- #
- # m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
+ #
+ # m = ORegexp.new('(.)(.)(\d+)(\d)').match("THX1138.")
# m[0] #=> "HX1138"
# m[1, 2] #=> ["H", "X"]
# m[1..3] #=> ["H", "X", "113"]
@@ -355,127 +355,127 @@ def to_index symbol
# If a symbol is used as index, the corresponding named group is returned,
# or <code>nil</code> if such a group does not exist.
#
- # m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
+ # m = ORegexp.new('(?<begin>^.*?)(?<middle>\d)(?<end>.*)').match("THX1138")
# m[:begin] #=> "THX"
# m[:moddle] #=> "1"
# m[:end] #=> "138"
-
+
def [](*idx)
- if idx[0].is_a?(Symbol)
- k = to_index( idx[0] )
+ if idx[0].is_a?(Symbol)
+ k = to_index(idx[0])
k && old_aref(k)
else
old_aref(*idx)
end
end
-
+
alias old_begin :begin
-
+
# call-seq:
# mtch.begin(n) => integer
# mtch.begin => integer
# mtch.begin(symbol) => integer
- #
+ #
# Returns the offset of the start of the <em>n</em>th element of the match
# array in the string.
- #
- # m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
+ #
+ # m = ORegexp.new('(.)(.)(\d+)(\d)').match("THX1138.")
# m.begin(0) #=> 1
# m.begin(2) #=> 2
#
# If no arguments are given, the index of the
# first matching character is returned.
#
- # m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
+ # m = ORegexp.new('(.)(.)(\d+)(\d)').match("THX1138.")
# m.begin #=> 1
#
- # If the argument is a symbol, then the beginning of the
+ # If the argument is a symbol, then the beginning of the
# corresponding named group is returned, or <code>nil</code>
# if the group does not exist.
#
- # m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
+ # m = ORegexp.new('(?<begin>^.*?)(?<middle>\d)(?<end>.*)').match("THX1138")
# m.begin(:middle) #=> 3
-
+
def begin(*idx)
- if idx[0].is_a?(Symbol)
- k = to_index( idx[0] )
+ if idx[0].is_a?(Symbol)
+ k = to_index(idx[0])
k && old_begin(k)
elsif idx.empty?
- old_begin( 0 )
+ old_begin(0)
else
old_begin(*idx)
end
end
-
+
alias old_end :end
-
+
# call-seq:
# mtch.end(n) => integer
- #
+ #
# Returns the offset of the character immediately following the end of the
# <em>n</em>th element of the match array in the string.
- #
- # m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
+ #
+ # m = ORegexp.new('(.)(.)(\d+)(\d)').match("THX1138.")
# m.end(0) #=> 7
# m.end(2) #=> 3
#
# If no arguments are given, the index of the
# last matching character is returned.
#
- # m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
+ # m = ORegexp.new('(.)(.)(\d+)(\d)').match("THX1138.")
# m.last #=> 7
#
- # If the argument is a symbol, then the beginning of the
+ # If the argument is a symbol, then the beginning of the
# corresponding named group is returned, or <code>nil</code>
# if the group does not exist.
#
- # m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
+ # m = ORegexp.new('(?<begin>^.*?)(?<middle>\d)(?<end>.*)').match("THX1138")
# m.end(:middle) #=> 4
-
+
def end(*idx)
- if idx[0].is_a?(Symbol)
- k = to_index( idx[0] )
+ if idx[0].is_a?(Symbol)
+ k = to_index(idx[0])
k && old_end(k)
elsif idx.empty?
- old_end( 0 )
+ old_end(0)
else
old_end(*idx)
end
end
-
+
alias old_offset :offset
-
+
# call-seq:
# mtch.offset(n) => array
# mtch.offset => array
# mtch.offset(symbol) => array
- #
+ #
# Returns a two-element array containing the beginning and ending offsets of
# the <em>n</em>th match.
- #
- # m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
+ #
+ # m = ORegexp.new('(.)(.)(\d+)(\d)').match("THX1138.")
# m.offset(0) #=> [1, 7]
- # m.offset(4) #=> [6, 7]
+ # m.offset(4) #=> [6, 7]
#
# If no arguments are given, the offsets of the entire
# sequence are returned.
#
- # m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
+ # m = ORegexp.new('(.)(.)(\d+)(\d)').match("THX1138.")
# m.offset #=> [1, 7]
#
- # If the argument is a symbol, then the offsets of the
+ # If the argument is a symbol, then the offsets of the
# corresponding named group are returned, or <code>nil</code>
# if the group does not exist.
#
- # m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
+ # m = ORegexp.new('(?<begin>^.*?)(?<middle>\d)(?<end>.*)').match("THX1138")
# m.end(:middle) #=> [3, 4]
-
+
def offset(*idx)
- if idx[0].is_a?(Symbol)
- k = to_index( idx[0] )
+ if idx[0].is_a?(Symbol)
+ k = to_index(idx[0])
k && old_offset(k)
elsif idx.empty?
- old_offset( 0 )
+ old_offset(0)
else
old_offset(*idx)
end
Please sign in to comment.
Something went wrong with that request. Please try again.