Ignore:
Timestamp:
Jan 21, 2018, 12:10:09 AM (6 years ago)
Author:
coas-nagasima
Message:

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

Location:
EcnlProtoTool/trunk/mruby-1.3.0
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-1.3.0/mrblib/string.rb

    r321 r331  
    1010  #
    1111  # ISO 15.2.10.5.15
    12   def each_line(&block)
     12  def each_line(rs = "\n", &block)
     13    return to_enum(:each_line, rs, &block) unless block
     14    return block.call(self) if rs.nil?
     15    rs = rs.to_str
    1316    offset = 0
    14     while pos = self.index("\n", offset)
    15       block.call(self[offset, pos + 1 - offset])
    16       offset = pos + 1
    17     end
    18     block.call(self[offset, self.size - offset]) if self.size > offset
     17    rs_len = rs.length
     18    this = dup
     19    while pos = this.index(rs, offset)
     20      block.call(this[offset, pos + rs_len - offset])
     21      offset = pos + rs_len
     22    end
     23    block.call(this[offset, this.size - offset]) if this.size > offset
    1924    self
    2025  end
     
    3540          when "'"
    3641            post
     42          when "1", "2", "3", "4", "5", "6", "7", "8", "9"
     43            ""
    3744          else
    3845            self[j, 2]
     
    5259  # ISO 15.2.10.5.18
    5360  def gsub(*args, &block)
    54     if args.size == 2
    55       s = ""
    56       i = 0
    57       while j = index(args[0], i)
    58         seplen = args[0].length
    59         k = j + seplen
    60         pre = self[0, j]
    61         post = self[k, length-k]
    62         s += self[i, j-i] + args[1].__sub_replace(pre, args[0], post)
    63         i = k
    64       end
    65       s + self[i, length-i]
    66     elsif args.size == 1 && block
    67       split(args[0], -1).join(block.call(args[0]))
    68     else
    69       raise ArgumentError, "wrong number of arguments"
    70     end
     61    return to_enum(:gsub, *args) if args.length == 1 && !block
     62    raise ArgumentError, "wrong number of arguments" unless (1..2).include?(args.length)
     63
     64    pattern, replace = *args
     65    plen = pattern.length
     66    if args.length == 2 && block
     67      block = nil
     68    end
     69    if !replace.nil? || !block
     70      replace = replace.to_str
     71    end
     72    offset = 0
     73    result = []
     74    while found = index(pattern, offset)
     75      result << self[offset, found - offset]
     76      offset = found + plen
     77      result << if block
     78        block.call(pattern).to_s
     79      else
     80        replace.__sub_replace(self[0, found], pattern, self[offset..-1] || "")
     81      end
     82      if plen == 0
     83        result << self[offset, 1]
     84        offset += 1
     85      end
     86    end
     87    result << self[offset..-1] if offset < length
     88    result.join
    7189  end
    7290
     
    7997  # ISO 15.2.10.5.19
    8098  def gsub!(*args, &block)
     99    raise RuntimeError, "can't modify frozen String" if frozen?
     100    return to_enum(:gsub!, *args) if args.length == 1 && !block
    81101    str = self.gsub(*args, &block)
    82102    return nil if str == self
     
    105125  # ISO 15.2.10.5.36
    106126  def sub(*args, &block)
    107     if args.size == 2
    108       pre, post = split(args[0], 2)
    109       return self unless post # The sub target wasn't found in the string
    110       pre + args[1].__sub_replace(pre, args[0], post) + post
    111     elsif args.size == 1 && block
    112       split(args[0], 2).join(block.call(args[0]))
     127    unless (1..2).include?(args.length)
     128      raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 2)"
     129    end
     130
     131    pattern, replace = *args
     132    pattern = pattern.to_str
     133    if args.length == 2 && block
     134      block = nil
     135    end
     136    if !block
     137      replace = replace.to_str
     138    end
     139    result = []
     140    this = dup
     141    found = index(pattern)
     142    return this unless found
     143    result << this[0, found]
     144    offset = found + pattern.length
     145    result << if block
     146      block.call(pattern).to_s
    113147    else
    114       raise ArgumentError, "wrong number of arguments"
    115     end
     148      replace.__sub_replace(this[0, found], pattern, this[offset..-1] || "")
     149    end
     150    result << this[offset..-1] if offset < length
     151    result.join
    116152  end
    117153
     
    124160  # ISO 15.2.10.5.37
    125161  def sub!(*args, &block)
     162    raise RuntimeError, "can't modify frozen String" if frozen?
    126163    str = self.sub(*args, &block)
    127164    return nil if str == self
     
    160197    if anum == 2
    161198      pos, value = args
    162       if pos.kind_of? String
     199      case pos
     200      when String
    163201        posnum = self.index(pos)
    164202        if posnum
     
    166204          a = self[(posnum + pos.length)..-1]
    167205          self.replace([b, value, a].join(''))
    168           return value
    169206        else
    170207          raise IndexError, "string not matched"
    171208        end
     209      when Range
     210        head = pos.begin
     211        tail = pos.end
     212        tail += self.length if tail < 0
     213        unless pos.exclude_end?
     214          tail += 1
     215        end
     216        return self[head, tail-head]=value
    172217      else
    173218        pos += self.length if pos < 0
     
    178223        a = self[pos + 1..-1]
    179224        self.replace([b, value, a].join(''))
    180         return value
    181       end
     225      end
     226      return value
    182227    elsif anum == 3
    183228      pos, len, value = args
Note: See TracChangeset for help on using the changeset viewer.