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/mrbgems/mruby-string-ext/mrblib/string.rb

    r321 r331  
    11class String
     2
     3  ##
     4  #  call-seq:
     5  #     String.try_convert(obj) -> string or nil
     6  #
     7  # Try to convert <i>obj</i> into a String, using to_str method.
     8  # Returns converted string or nil if <i>obj</i> cannot be converted
     9  # for any reason.
     10  #
     11  #     String.try_convert("str")     #=> "str"
     12  #     String.try_convert(/re/)      #=> nil
     13  #
     14  def self.try_convert(obj)
     15    if obj.respond_to?(:to_str)
     16      obj.to_str
     17    else
     18      nil
     19    end
     20  end
    221
    322  ##
     
    2746    a = 0
    2847    z = self.size - 1
    29     a += 1 while " \f\n\r\t\v".include?(self[a]) and a <= z
     48    a += 1 while a <= z and " \f\n\r\t\v".include?(self[a])
    3049    (z >= 0) ? self[a..z] : ""
    3150  end
     
    4463    a = 0
    4564    z = self.size - 1
    46     z -= 1 while " \f\n\r\t\v\0".include?(self[z]) and a <= z
     65    z -= 1 while a <= z and " \f\n\r\t\v\0".include?(self[z])
    4766    (z >= 0) ? self[a..z] : ""
    4867  end
     
    6079    a = 0
    6180    z = self.size - 1
    62     a += 1 while " \f\n\r\t\v".include?(self[a]) and a <= z
    63     z -= 1 while " \f\n\r\t\v\0".include?(self[z]) and a <= z
     81    a += 1 while a <= z and " \f\n\r\t\v".include?(self[a])
     82    z -= 1 while a <= z and " \f\n\r\t\v\0".include?(self[z])
    6483    (z >= 0) ? self[a..z] : ""
    6584  end
     
    7796  #
    7897  def lstrip!
     98    raise RuntimeError, "can't modify frozen String" if frozen?
    7999    s = self.lstrip
    80100    (s == self) ? nil : self.replace(s)
     
    93113  #
    94114  def rstrip!
     115    raise RuntimeError, "can't modify frozen String" if frozen?
    95116    s = self.rstrip
    96117    (s == self) ? nil : self.replace(s)
     
    105126  #
    106127  def strip!
     128    raise RuntimeError, "can't modify frozen String" if frozen?
    107129    s = self.strip
    108130    (s == self) ? nil : self.replace(s)
     
    165187  #
    166188  def slice!(arg1, arg2=nil)
     189    raise RuntimeError, "can't modify frozen String" if frozen?
    167190    raise "wrong number of arguments (for 1..2)" if arg1.nil? && arg2.nil?
    168191
     
    189212        idx = arg1
    190213        idx += self.size if arg1 < 0
    191         validated = true if idx >=0 && arg1 < self.size   
     214        validated = true if idx >=0 && arg1 < self.size
    192215      end
    193216      if validated
     
    236259  #
    237260  def insert(idx, str)
    238     pos = idx.to_i
    239     pos += self.size + 1 if pos < 0
    240 
    241     raise IndexError, "index #{idx.to_i} out of string" if pos < 0 || pos > self.size
    242 
    243     return self + str if pos == -1
    244     return str + self if pos == 0
    245     return self[0..pos - 1] + str + self[pos..-1]
     261    if idx == -1
     262      return self << str
     263    elsif idx < 0
     264      idx += 1
     265    end
     266    self[idx, 0] = str
     267    self
    246268  end
    247269
     
    258280  #     "hello".ljust(20, '1234')   #=> "hello123412341234123"
    259281  def ljust(idx, padstr = ' ')
    260     if idx <= self.size
    261       return self
    262     end
    263     newstr = self.dup
    264     newstr << padstr
    265     while newstr.size <= idx
    266       newstr << padstr
    267     end
    268     return newstr.slice(0,idx)
    269   end
    270 
    271   #     str.upto(other_str, exclusive=false) {|s| block }   -> str
    272   #     str.upto(other_str, exclusive=false)                -> an_enumerator
    273   #
    274   #  Iterates through successive values, starting at <i>str</i> and
    275   #  ending at <i>other_str</i> inclusive, passing each value in turn to
    276   #  the block. The <code>String#succ</code> method is used to generate
    277   #  each value.  If optional second argument exclusive is omitted or is false,
    278   #  the last value will be included; otherwise it will be excluded.
    279   #
    280   #  If no block is given, an enumerator is returned instead.
    281   #
    282   #     "a8".upto("b6") {|s| print s, ' ' }
    283   #     for s in "a8".."b6"
    284   #       print s, ' '
    285   #     end
    286   #
    287   #  <em>produces:</em>
    288   #
    289   #     a8 a9 b0 b1 b2 b3 b4 b5 b6
    290   #     a8 a9 b0 b1 b2 b3 b4 b5 b6
    291   #
    292   #  If <i>str</i> and <i>other_str</i> contains only ascii numeric characters,
    293   #  both are recognized as decimal numbers. In addition, the width of
    294   #  string (e.g. leading zeros) is handled appropriately.
    295   #
    296   #     "9".upto("11").to_a   #=> ["9", "10", "11"]
    297   #     "25".upto("5").to_a   #=> []
    298   #     "07".upto("11").to_a  #=> ["07", "08", "09", "10", "11"]
    299   #
    300   def upto(other_str, excl=false, &block)
    301     return to_enum :upto, other_str, excl unless block
    302 
    303     str = self
    304     n = self.<=>other_str
    305     return self if n > 0 || (self == other_str && excl)
    306     while true
    307       block.call(str)
    308       return self if !excl && str == other_str
    309       str = str.succ
    310       return self if excl && str == other_str
    311     end
     282    raise ArgumentError, 'zero width padding' if padstr == ''
     283    return self if idx <= self.size
     284    pad_repetitions = (idx / padstr.length).ceil
     285    padding = (padstr * pad_repetitions)[0...(idx - self.length)]
     286    self + padding
     287  end
     288
     289  ##
     290  #  call-seq:
     291  #     str.rjust(integer, padstr=' ')   -> new_str
     292  #
     293  #  If <i>integer</i> is greater than the length of <i>str</i>, returns a new
     294  #  <code>String</code> of length <i>integer</i> with <i>str</i> right justified
     295  #  and padded with <i>padstr</i>; otherwise, returns <i>str</i>.
     296  #
     297  #     "hello".rjust(4)            #=> "hello"
     298  #     "hello".rjust(20)           #=> "               hello"
     299  #     "hello".rjust(20, '1234')   #=> "123412341234123hello"
     300  def rjust(idx, padstr = ' ')
     301    raise ArgumentError, 'zero width padding' if padstr == ''
     302    return self if idx <= self.size
     303    pad_repetitions = (idx / padstr.length).ceil
     304    padding = (padstr * pad_repetitions)[0...(idx - self.length)]
     305    padding + self
    312306  end
    313307
    314308  def chars(&block)
    315309    if block_given?
    316       self.split('').map do |i|
     310      self.split('').each do |i|
    317311        block.call(i)
    318312      end
     
    322316    end
    323317  end
    324   alias each_char chars
     318
     319  def each_char(&block)
     320    return to_enum :each_char unless block
     321
     322    split('').each do |i|
     323      block.call(i)
     324    end
     325    self
     326  end
    325327
    326328  def codepoints(&block)
     
    328330
    329331    if block_given?
    330       self.split('').map do|x|
     332      self.split('').each do|x|
    331333        block.call(x.ord)
    332334      end
     
    337339  end
    338340  alias each_codepoint codepoints
     341
     342  ##
     343  # call-seq:
     344  #    str.prepend(other_str)  -> str
     345  #
     346  # Prepend---Prepend the given string to <i>str</i>.
     347  #
     348  #    a = "world"
     349  #    a.prepend("hello ") #=> "hello world"
     350  #    a                   #=> "hello world"
     351  def prepend(arg)
     352    self[0, 0] = arg
     353    self
     354  end
    339355end
Note: See TracChangeset for help on using the changeset viewer.