class String

String

Public Instance Methods

each_matches(regexp) { |match, byte_index, char_index| ... } click to toggle source
# File core/utils.rb, line 392
def each_matches(regexp, &proc) # :yield: match, byte_index, char_index
  warn "String#each_matches is obsolete method. use String#scan"
  pos = 0
  str = self
  while(match = regexp.match(str))
    if(proc.arity == 1)
      proc.call(match)
    elsif(proc.arity == 2)
      proc.call(match, pos + match.begin(0))
    else
      proc.call(match, pos + match.begin(0), pos + match.begin(0)) end
    str = match.post_match
    pos += match.end(0) end end
get_index_from_byte(byte) click to toggle source

byte バイト目が何文字目にあたるかを返す

# File core/utils.rb, line 407
def get_index_from_byte(byte)
  result = 0
  split(//u).each{ |c|
    byte -= c.to_enum(:each_byte).to_a.size
    return result if(byte < 0)
    result += 1 }
  result end
inspect() click to toggle source
# File core/utils.rb, line 415
def inspect
  '"'+to_s+'"'
end
match_regexp(str) click to toggle source
# File core/utils.rb, line 378
def match_regexp(str)
  if(str.is_a? String)
    match(Regexp.new(str))
  else
    match(str) end end
matches(regexp) click to toggle source
# File core/utils.rb, line 384
def matches(regexp)
  warn "String#matches is obsolete method. use String#scan"
  result = []
  each_matches(regexp){ |m, pos|
    result << m.to_s }
  result
end