summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/deps/mruby/mrblib
diff options
context:
space:
mode:
Diffstat (limited to 'web/server/h2o/libh2o/deps/mruby/mrblib')
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/00class.rb28
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/10error.rb56
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/array.rb243
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb84
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/enum.rb348
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/hash.rb358
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/init_mrblib.c11
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/kernel.rb50
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/mrblib.rake18
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/numeric.rb173
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/range.rb67
-rw-r--r--web/server/h2o/libh2o/deps/mruby/mrblib/string.rb275
12 files changed, 1711 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/00class.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/00class.rb
new file mode 100644
index 00000000..1a2d833c
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/00class.rb
@@ -0,0 +1,28 @@
+class Module
+ # 15.2.2.4.12
+ def attr_accessor(*names)
+ attr_reader(*names)
+ attr_writer(*names)
+ end
+ # 15.2.2.4.11
+ def attr(name)
+ attr_reader(name)
+ end
+
+ # 15.2.2.4.27
+ def include(*args)
+ args.reverse.each do |m|
+ m.append_features(self)
+ m.included(self)
+ end
+ self
+ end
+
+ def prepend(*args)
+ args.reverse.each do |m|
+ m.prepend_features(self)
+ m.prepended(self)
+ end
+ self
+ end
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/10error.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/10error.rb
new file mode 100644
index 00000000..22a8d1ad
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/10error.rb
@@ -0,0 +1,56 @@
+# ISO 15.2.24
+class ArgumentError < StandardError
+end
+
+# ISO 15.2.25 says "LocalJumpError < StandardError"
+class LocalJumpError < ScriptError
+end
+
+# ISO 15.2.26
+class RangeError < StandardError
+end
+
+class FloatDomainError < RangeError
+end
+
+# ISO 15.2.26
+class RegexpError < StandardError
+end
+
+# ISO 15.2.29
+class TypeError < StandardError
+end
+
+# ISO 15.2.31
+class NameError < StandardError
+ attr_accessor :name
+
+ def initialize(message=nil, name=nil)
+ @name = name
+ super(message)
+ end
+end
+
+# ISO 15.2.32
+class NoMethodError < NameError
+ attr_reader :args
+
+ def initialize(message=nil, name=nil, args=nil)
+ @args = args
+ super message, name
+ end
+end
+
+# ISO 15.2.33
+class IndexError < StandardError
+end
+
+class KeyError < IndexError
+end
+
+class NotImplementedError < ScriptError
+end
+
+class StopIteration < IndexError
+ attr_accessor :result
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/array.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/array.rb
new file mode 100644
index 00000000..a75ed622
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/array.rb
@@ -0,0 +1,243 @@
+# coding: utf-8
+##
+# Array
+#
+# ISO 15.2.12
+class Array
+
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the respective element.
+ #
+ # ISO 15.2.12.5.10
+ def each(&block)
+ return to_enum :each unless block
+
+ idx = 0
+ while idx < length
+ block.call(self[idx])
+ idx += 1
+ end
+ self
+ end
+
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the index of the respective element.
+ #
+ # ISO 15.2.12.5.11
+ def each_index(&block)
+ return to_enum :each_index unless block
+
+ idx = 0
+ while idx < length
+ block.call(idx)
+ idx += 1
+ end
+ self
+ end
+
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the respective element. Each element will
+ # be replaced by the resulting values.
+ #
+ # ISO 15.2.12.5.7
+ def collect!(&block)
+ return to_enum :collect! unless block
+
+ idx = 0
+ len = size
+ while idx < len
+ self[idx] = block.call self[idx]
+ idx += 1
+ end
+ self
+ end
+
+ ##
+ # Alias for collect!
+ #
+ # ISO 15.2.12.5.20
+ alias map! collect!
+
+ ##
+ # Private method for Array creation.
+ #
+ # ISO 15.2.12.5.15
+ def initialize(size=0, obj=nil, &block)
+ raise TypeError, "expected Integer for 1st argument" unless size.kind_of? Integer
+ raise ArgumentError, "negative array size" if size < 0
+
+ self.clear
+ if size > 0
+ self[size - 1] = nil # allocate
+
+ idx = 0
+ while idx < size
+ self[idx] = (block)? block.call(idx): obj
+ idx += 1
+ end
+ end
+
+ self
+ end
+
+ def _inspect
+ return "[]" if self.size == 0
+ "["+self.map{|x|x.inspect}.join(", ")+"]"
+ end
+ ##
+ # Return the contents of this array as a string.
+ #
+ # ISO 15.2.12.5.31 (x)
+ def inspect
+ begin
+ self._inspect
+ rescue SystemStackError
+ "[...]"
+ end
+ end
+ # ISO 15.2.12.5.32 (x)
+ alias to_s inspect
+
+ ##
+ # Equality---Two arrays are equal if they contain the same number
+ # of elements and if each element is equal to (according to
+ # Object.==) the corresponding element in the other array.
+ #
+ # ISO 15.2.12.5.33 (x)
+ def ==(other)
+ other = self.__ary_eq(other)
+ return false if other == false
+ return true if other == true
+ len = self.size
+ i = 0
+ while i < len
+ return false if self[i] != other[i]
+ i += 1
+ end
+ return true
+ end
+
+ ##
+ # Returns <code>true</code> if +self+ and _other_ are the same object,
+ # or are both arrays with the same content.
+ #
+ # ISO 15.2.12.5.34 (x)
+ def eql?(other)
+ other = self.__ary_eq(other)
+ return false if other == false
+ return true if other == true
+ len = self.size
+ i = 0
+ while i < len
+ return false unless self[i].eql?(other[i])
+ i += 1
+ end
+ return true
+ end
+
+ ##
+ # Comparison---Returns an integer (-1, 0, or +1)
+ # if this array is less than, equal to, or greater than <i>other_ary</i>.
+ # Each object in each array is compared (using <=>). If any value isn't
+ # equal, then that inequality is the return value. If all the
+ # values found are equal, then the return is based on a
+ # comparison of the array lengths. Thus, two arrays are
+ # "equal" according to <code>Array#<=></code> if and only if they have
+ # the same length and the value of each element is equal to the
+ # value of the corresponding element in the other array.
+ #
+ # ISO 15.2.12.5.36 (x)
+ def <=>(other)
+ other = self.__ary_cmp(other)
+ return 0 if 0 == other
+ return nil if nil == other
+
+ len = self.size
+ n = other.size
+ len = n if len > n
+ i = 0
+ while i < len
+ n = (self[i] <=> other[i])
+ return n if n.nil? || n != 0
+ i += 1
+ end
+ len = self.size - other.size
+ if len == 0
+ 0
+ elsif len > 0
+ 1
+ else
+ -1
+ end
+ end
+
+ ##
+ # Delete element with index +key+
+ def delete(key, &block)
+ while i = self.index(key)
+ self.delete_at(i)
+ ret = key
+ end
+ return block.call if ret.nil? && block
+ ret
+ end
+
+ # internal method to convert multi-value to single value
+ def __svalue
+ return self.first if self.size < 2
+ self
+ end
+end
+
+##
+# Array is enumerable
+class Array
+ # ISO 15.2.12.3
+ include Enumerable
+
+ ##
+ # Quick sort
+ # a : the array to sort
+ # left : the beginning of sort region
+ # right : the end of sort region
+ def __sort_sub__(a, left, right, &block)
+ if left < right
+ i = left
+ j = right
+ pivot = a[i + (j - i) / 2]
+ while true
+ while ((block)? block.call(a[i], pivot): (a[i] <=> pivot)) < 0
+ i += 1
+ end
+ while ((block)? block.call(pivot, a[j]): (pivot <=> a[j])) < 0
+ j -= 1
+ end
+ break if (i >= j)
+ tmp = a[i]; a[i] = a[j]; a[j] = tmp;
+ i += 1
+ j -= 1
+ end
+ __sort_sub__(a, left, i-1, &block)
+ __sort_sub__(a, j+1, right, &block)
+ end
+ end
+ # private :__sort_sub__
+
+ ##
+ # Sort all elements and replace +self+ with these
+ # elements.
+ def sort!(&block)
+ size = self.size
+ if size > 1
+ __sort_sub__(self, 0, size - 1, &block)
+ end
+ self
+ end
+
+ def sort(&block)
+ self.dup.sort!(&block)
+ end
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb
new file mode 100644
index 00000000..84b96259
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/compar.rb
@@ -0,0 +1,84 @@
+##
+# Comparable
+#
+# ISO 15.3.3
+module Comparable
+
+ ##
+ # Return true if +self+ is less
+ # than +other+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.3.2.1
+ def < other
+ cmp = self <=> other
+ if cmp.nil?
+ raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ end
+ cmp < 0
+ end
+
+ ##
+ # Return true if +self+ is less
+ # than or equal to +other+.
+ # Otherwise return false.
+ #
+ # ISO 15.3.3.2.2
+ def <= other
+ cmp = self <=> other
+ if cmp.nil?
+ raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ end
+ cmp <= 0
+ end
+
+ ##
+ # Return true if +self+ is equal
+ # to +other+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.3.2.3
+ def == other
+ cmp = self <=> other
+ cmp == 0
+ end
+
+ ##
+ # Return true if +self+ is greater
+ # than +other+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.3.2.4
+ def > other
+ cmp = self <=> other
+ if cmp.nil?
+ raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ end
+ cmp > 0
+ end
+
+ ##
+ # Return true if +self+ is greater
+ # than or equal to +other+.
+ # Otherwise return false.
+ #
+ # ISO 15.3.3.2.5
+ def >= other
+ cmp = self <=> other
+ if cmp.nil?
+ raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
+ end
+ cmp >= 0
+ end
+
+ ##
+ # Return true if +self+ is greater
+ # than or equal to +min+ and
+ # less than or equal to +max+.
+ # Otherwise return false.
+ #
+ # ISO 15.3.3.2.6
+ def between?(min, max)
+ self >= min and self <= max
+ end
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/enum.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/enum.rb
new file mode 100644
index 00000000..12bd1d37
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/enum.rb
@@ -0,0 +1,348 @@
+##
+# Enumerable
+#
+# The <code>Enumerable</code> mixin provides collection classes with
+# several traversal and searching methods, and with the ability to
+# sort. The class must provide a method `each`, which
+# yields successive members of the collection. If
+# {Enumerable#max}, {#min}, or
+# {#sort} is used, the objects in the collection must also
+# implement a meaningful `<=>` operator, as these methods
+# rely on an ordering between members of the collection.
+#
+# @ISO 15.3.2
+module Enumerable
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+. Return false
+ # if one block value is false. Otherwise
+ # return true. If no block is given and
+ # +self+ is false return false.
+ #
+ # ISO 15.3.2.2.1
+ def all?(&block)
+ if block
+ self.each{|*val| return false unless block.call(*val)}
+ else
+ self.each{|*val| return false unless val.__svalue}
+ end
+ true
+ end
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+. Return true
+ # if one block value is true. Otherwise
+ # return false. If no block is given and
+ # +self+ is true object return true.
+ #
+ # ISO 15.3.2.2.2
+ def any?(&block)
+ if block
+ self.each{|*val| return true if block.call(*val)}
+ else
+ self.each{|*val| return true if val.__svalue}
+ end
+ false
+ end
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+. Append all
+ # values of each block together and
+ # return this value.
+ #
+ # ISO 15.3.2.2.3
+ def collect(&block)
+ return to_enum :collect unless block
+
+ ary = []
+ self.each{|*val| ary.push(block.call(*val))}
+ ary
+ end
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+. Return
+ # +ifnone+ if no block value was true.
+ # Otherwise return the first block value
+ # which had was true.
+ #
+ # ISO 15.3.2.2.4
+ def detect(ifnone=nil, &block)
+ ret = ifnone
+ self.each{|*val|
+ if block.call(*val)
+ ret = val.__svalue
+ break
+ end
+ }
+ ret
+ end
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+. Pass an
+ # index to the block which starts at 0
+ # and increase by 1 for each element.
+ #
+ # ISO 15.3.2.2.5
+ def each_with_index(&block)
+ return to_enum :each_with_index unless block
+
+ i = 0
+ self.each{|*val|
+ block.call(val.__svalue, i)
+ i += 1
+ }
+ self
+ end
+
+ ##
+ # Return an array of all elements which
+ # are yield by +each+.
+ #
+ # ISO 15.3.2.2.6
+ def entries
+ ary = []
+ self.each{|*val|
+ # __svalue is an internal method
+ ary.push val.__svalue
+ }
+ ary
+ end
+
+ ##
+ # Alias for find
+ #
+ # ISO 15.3.2.2.7
+ alias find detect
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+. Return an array
+ # which contains all elements whose block
+ # value was true.
+ #
+ # ISO 15.3.2.2.8
+ def find_all(&block)
+ return to_enum :find_all unless block
+
+ ary = []
+ self.each{|*val|
+ ary.push(val.__svalue) if block.call(*val)
+ }
+ ary
+ end
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+ and which return
+ # value was true when invoking === with
+ # +pattern+. Return an array with all
+ # elements or the respective block values.
+ #
+ # ISO 15.3.2.2.9
+ def grep(pattern, &block)
+ ary = []
+ self.each{|*val|
+ sv = val.__svalue
+ if pattern === sv
+ ary.push((block)? block.call(*val): sv)
+ end
+ }
+ ary
+ end
+
+ ##
+ # Return true if at least one element which
+ # is yield by +each+ returns a true value
+ # by invoking == with +obj+. Otherwise return
+ # false.
+ #
+ # ISO 15.3.2.2.10
+ def include?(obj)
+ self.each{|*val|
+ return true if val.__svalue == obj
+ }
+ false
+ end
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+. Return value
+ # is the sum of all block values. Pass
+ # to each block the current sum and the
+ # current element.
+ #
+ # ISO 15.3.2.2.11
+ def inject(*args, &block)
+ raise ArgumentError, "too many arguments" if args.size > 2
+ if Symbol === args[-1]
+ sym = args[-1]
+ block = ->(x,y){x.__send__(sym,y)}
+ args.pop
+ end
+ if args.empty?
+ flag = true # no initial argument
+ result = nil
+ else
+ flag = false
+ result = args[0]
+ end
+ self.each{|*val|
+ val = val.__svalue
+ if flag
+ # push first element as initial
+ flag = false
+ result = val
+ else
+ result = block.call(result, val)
+ end
+ }
+ result
+ end
+ alias reduce inject
+
+ ##
+ # Alias for collect
+ #
+ # ISO 15.3.2.2.12
+ alias map collect
+
+ ##
+ # Return the maximum value of all elements
+ # yield by +each+. If no block is given <=>
+ # will be invoked to define this value. If
+ # a block is given it will be used instead.
+ #
+ # ISO 15.3.2.2.13
+ def max(&block)
+ flag = true # 1st element?
+ result = nil
+ self.each{|*val|
+ val = val.__svalue
+ if flag
+ # 1st element
+ result = val
+ flag = false
+ else
+ if block
+ result = val if block.call(val, result) > 0
+ else
+ result = val if (val <=> result) > 0
+ end
+ end
+ }
+ result
+ end
+
+ ##
+ # Return the minimum value of all elements
+ # yield by +each+. If no block is given <=>
+ # will be invoked to define this value. If
+ # a block is given it will be used instead.
+ #
+ # ISO 15.3.2.2.14
+ def min(&block)
+ flag = true # 1st element?
+ result = nil
+ self.each{|*val|
+ val = val.__svalue
+ if flag
+ # 1st element
+ result = val
+ flag = false
+ else
+ if block
+ result = val if block.call(val, result) < 0
+ else
+ result = val if (val <=> result) < 0
+ end
+ end
+ }
+ result
+ end
+
+ ##
+ # Alias for include?
+ #
+ # ISO 15.3.2.2.15
+ alias member? include?
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+. Return an
+ # array which contains two arrays. The
+ # first array contains all elements
+ # whose block value was true. The second
+ # array contains all elements whose
+ # block value was false.
+ #
+ # ISO 15.3.2.2.16
+ def partition(&block)
+ ary_T = []
+ ary_F = []
+ self.each{|*val|
+ if block.call(*val)
+ ary_T.push(val.__svalue)
+ else
+ ary_F.push(val.__svalue)
+ end
+ }
+ [ary_T, ary_F]
+ end
+
+ ##
+ # Call the given block for each element
+ # which is yield by +each+. Return an
+ # array which contains only the elements
+ # whose block value was false.
+ #
+ # ISO 15.3.2.2.17
+ def reject(&block)
+ ary = []
+ self.each{|*val|
+ ary.push(val.__svalue) unless block.call(*val)
+ }
+ ary
+ end
+
+ ##
+ # Alias for find_all.
+ #
+ # ISO 15.3.2.2.18
+ alias select find_all
+
+ ##
+ # Return a sorted array of all elements
+ # which are yield by +each+. If no block
+ # is given <=> will be invoked on each
+ # element to define the order. Otherwise
+ # the given block will be used for
+ # sorting.
+ #
+ # ISO 15.3.2.2.19
+ def sort(&block)
+ self.map{|*val| val.__svalue}.sort
+ end
+
+ ##
+ # Alias for entries.
+ #
+ # ISO 15.3.2.2.20
+ alias to_a entries
+
+ # redefine #hash 15.3.1.3.15
+ def hash
+ h = 12347
+ i = 0
+ self.each do |e|
+ n = (e.hash & (0x7fffffff >> (i % 16))) << (i % 16)
+ h ^= n
+ i += 1
+ end
+ h
+ end
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/hash.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/hash.rb
new file mode 100644
index 00000000..6b4803cc
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/hash.rb
@@ -0,0 +1,358 @@
+##
+# Hash
+#
+# ISO 15.2.13
+class Hash
+ ##
+ # Equality---Two hashes are equal if they each contain the same number
+ # of keys and if each key-value pair is equal to (according to
+ # <code>Object#==</code>) the corresponding elements in the other
+ # hash.
+ #
+ # ISO 15.2.13.4.1
+ def ==(hash)
+ return true if self.equal?(hash)
+ begin
+ hash = hash.to_hash
+ rescue NoMethodError
+ return false
+ end
+ return false if self.size != hash.size
+ self.each do |k,v|
+ return false unless hash.key?(k)
+ return false unless self[k] == hash[k]
+ end
+ return true
+ end
+
+ ##
+ # Returns <code>true</code> if <i>hash</i> and <i>other</i> are
+ # both hashes with the same content compared by eql?.
+ #
+ # ISO 15.2.13.4.32 (x)
+ def eql?(hash)
+ return true if self.equal?(hash)
+ begin
+ hash = hash.to_hash
+ rescue NoMethodError
+ return false
+ end
+ return false if self.size != hash.size
+ self.each do |k,v|
+ return false unless hash.key?(k)
+ return false unless self[k].eql?(hash[k])
+ end
+ return true
+ end
+
+ ##
+ # Delete the element with the key +key+.
+ # Return the value of the element if +key+
+ # was found. Return nil if nothing was
+ # found. If a block is given, call the
+ # block with the value of the element.
+ #
+ # ISO 15.2.13.4.8
+ def delete(key, &block)
+ if block && !self.has_key?(key)
+ block.call(key)
+ else
+ self.__delete(key)
+ end
+ end
+
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the key and value of each element.
+ #
+ # call-seq:
+ # hsh.each {| key, value | block } -> hsh
+ # hsh.each_pair {| key, value | block } -> hsh
+ # hsh.each -> an_enumerator
+ # hsh.each_pair -> an_enumerator
+ #
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200 }
+ # h.each {|key, value| puts "#{key} is #{value}" }
+ #
+ # <em>produces:</em>
+ #
+ # a is 100
+ # b is 200
+ #
+ # ISO 15.2.13.4.9
+ def each(&block)
+ return to_enum :each unless block
+
+ keys = self.keys
+ vals = self.values
+ len = self.size
+ i = 0
+ while i < len
+ block.call [keys[i], vals[i]]
+ i += 1
+ end
+ self
+ end
+
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the key of each element.
+ #
+ # call-seq:
+ # hsh.each_key {| key | block } -> hsh
+ # hsh.each_key -> an_enumerator
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200 }
+ # h.each_key {|key| puts key }
+ #
+ # <em>produces:</em>
+ #
+ # a
+ # b
+ #
+ # ISO 15.2.13.4.10
+ def each_key(&block)
+ return to_enum :each_key unless block
+
+ self.keys.each{|k| block.call(k)}
+ self
+ end
+
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the value of each element.
+ #
+ # call-seq:
+ # hsh.each_value {| value | block } -> hsh
+ # hsh.each_value -> an_enumerator
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200 }
+ # h.each_value {|value| puts value }
+ #
+ # <em>produces:</em>
+ #
+ # 100
+ # 200
+ #
+ # ISO 15.2.13.4.11
+ def each_value(&block)
+ return to_enum :each_value unless block
+
+ self.keys.each{|k| block.call(self[k])}
+ self
+ end
+
+ ##
+ # Replaces the contents of <i>hsh</i> with the contents of other hash
+ #
+ # ISO 15.2.13.4.23
+ def replace(hash)
+ raise TypeError, "can't convert argument into Hash" unless hash.respond_to?(:to_hash)
+ self.clear
+ hash = hash.to_hash
+ hash.each_key{|k|
+ self[k] = hash[k]
+ }
+ if hash.default_proc
+ self.default_proc = hash.default_proc
+ else
+ self.default = hash.default
+ end
+ self
+ end
+ # ISO 15.2.13.4.17
+ alias initialize_copy replace
+
+ ##
+ # Return a hash which contains the content of
+ # +self+ and +other+. If a block is given
+ # it will be called for each element with
+ # a duplicate key. The value of the block
+ # will be the final value of this element.
+ #
+ # ISO 15.2.13.4.22
+ def merge(other, &block)
+ h = {}
+ raise TypeError, "can't convert argument into Hash" unless other.respond_to?(:to_hash)
+ other = other.to_hash
+ self.each_key{|k| h[k] = self[k]}
+ if block
+ other.each_key{|k|
+ h[k] = (self.has_key?(k))? block.call(k, self[k], other[k]): other[k]
+ }
+ else
+ other.each_key{|k| h[k] = other[k]}
+ end
+ h
+ end
+
+ # internal method for Hash inspection
+ def _inspect
+ return "{}" if self.size == 0
+ "{"+self.map {|k,v|
+ k._inspect + "=>" + v._inspect
+ }.join(", ")+"}"
+ end
+ ##
+ # Return the contents of this hash as a string.
+ #
+ # ISO 15.2.13.4.30 (x)
+ def inspect
+ begin
+ self._inspect
+ rescue SystemStackError
+ "{...}"
+ end
+ end
+ # ISO 15.2.13.4.31 (x)
+ alias to_s inspect
+
+ ##
+ # call-seq:
+ # hsh.reject! {| key, value | block } -> hsh or nil
+ # hsh.reject! -> an_enumerator
+ #
+ # Equivalent to <code>Hash#delete_if</code>, but returns
+ # <code>nil</code> if no changes were made.
+ #
+ # 1.8/1.9 Hash#reject! returns Hash; ISO says nothing.
+ #
+ def reject!(&block)
+ return to_enum :reject! unless block
+
+ keys = []
+ self.each{|k,v|
+ if block.call([k, v])
+ keys.push(k)
+ end
+ }
+ return nil if keys.size == 0
+ keys.each{|k|
+ self.delete(k)
+ }
+ self
+ end
+
+ ##
+ # call-seq:
+ # hsh.reject {|key, value| block} -> a_hash
+ # hsh.reject -> an_enumerator
+ #
+ # Returns a new hash consisting of entries for which the block returns false.
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
+ # h.reject {|k,v| k < "b"} #=> {"b" => 200, "c" => 300}
+ # h.reject {|k,v| v > 100} #=> {"a" => 100}
+ #
+ # 1.8/1.9 Hash#reject returns Hash; ISO says nothing.
+ #
+ def reject(&block)
+ return to_enum :reject unless block
+
+ h = {}
+ self.each{|k,v|
+ unless block.call([k, v])
+ h[k] = v
+ end
+ }
+ h
+ end
+
+ ##
+ # call-seq:
+ # hsh.select! {| key, value | block } -> hsh or nil
+ # hsh.select! -> an_enumerator
+ #
+ # Equivalent to <code>Hash#keep_if</code>, but returns
+ # <code>nil</code> if no changes were made.
+ #
+ # 1.9 Hash#select! returns Hash; ISO says nothing.
+ #
+ def select!(&block)
+ return to_enum :select! unless block
+
+ keys = []
+ self.each{|k,v|
+ unless block.call([k, v])
+ keys.push(k)
+ end
+ }
+ return nil if keys.size == 0
+ keys.each{|k|
+ self.delete(k)
+ }
+ self
+ end
+
+ ##
+ # call-seq:
+ # hsh.select {|key, value| block} -> a_hash
+ # hsh.select -> an_enumerator
+ #
+ # Returns a new hash consisting of entries for which the block returns true.
+ #
+ # If no block is given, an enumerator is returned instead.
+ #
+ # h = { "a" => 100, "b" => 200, "c" => 300 }
+ # h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300}
+ # h.select {|k,v| v < 200} #=> {"a" => 100}
+ #
+ # 1.9 Hash#select returns Hash; ISO says nothing
+ #
+ def select(&block)
+ return to_enum :select unless block
+
+ h = {}
+ self.each{|k,v|
+ if block.call([k, v])
+ h[k] = v
+ end
+ }
+ h
+ end
+
+ ##
+ # call-seq:
+ # hsh.rehash -> hsh
+ #
+ # Rebuilds the hash based on the current hash values for each key. If
+ # values of key objects have changed since they were inserted, this
+ # method will reindex <i>hsh</i>.
+ #
+ # h = {"AAA" => "b"}
+ # h.keys[0].chop!
+ # h #=> {"AA"=>"b"}
+ # h["AA"] #=> nil
+ # h.rehash #=> {"AA"=>"b"}
+ # h["AA"] #=> "b"
+ #
+ def rehash
+ h = {}
+ self.each{|k,v|
+ h[k] = v
+ }
+ self.replace(h)
+ end
+
+ def __update(h)
+ h.each_key{|k| self[k] = h[k]}
+ self
+ end
+end
+
+##
+# Hash is enumerable
+#
+# ISO 15.2.13.3
+class Hash
+ include Enumerable
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/init_mrblib.c b/web/server/h2o/libh2o/deps/mruby/mrblib/init_mrblib.c
new file mode 100644
index 00000000..4d4bcd25
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/init_mrblib.c
@@ -0,0 +1,11 @@
+#include <mruby.h>
+#include <mruby/irep.h>
+
+extern const uint8_t mrblib_irep[];
+
+void
+mrb_init_mrblib(mrb_state *mrb)
+{
+ mrb_load_irep(mrb, mrblib_irep);
+}
+
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/kernel.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/kernel.rb
new file mode 100644
index 00000000..550ae817
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/kernel.rb
@@ -0,0 +1,50 @@
+##
+# Kernel
+#
+# ISO 15.3.1
+module Kernel
+
+ # 15.3.1.2.1 Kernel.`
+ # provided by Kernel#`
+ # 15.3.1.3.5
+ def `(s)
+ raise NotImplementedError.new("backquotes not implemented")
+ end
+
+ ##
+ # 15.3.1.2.3 Kernel.eval
+ # 15.3.1.3.12 Kernel#eval
+ # NotImplemented by mruby core; use mruby-eval gem
+
+ ##
+ # ISO 15.3.1.2.8 Kernel.loop
+ # provided by Kernel#loop
+
+ ##
+ # Calls the given block repetitively.
+ #
+ # ISO 15.3.1.3.29
+ def loop(&block)
+ return to_enum :loop unless block
+
+ while true
+ yield
+ end
+ rescue StopIteration => e
+ e.result
+ end
+
+ # 11.4.4 Step c)
+ def !~(y)
+ !(self =~ y)
+ end
+
+ # internal method for inspect
+ def _inspect
+ self.inspect
+ end
+
+ def to_enum(*a)
+ raise NotImplementedError.new("fiber required for enumerator")
+ end
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/mrblib.rake b/web/server/h2o/libh2o/deps/mruby/mrblib/mrblib.rake
new file mode 100644
index 00000000..19fd00d6
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/mrblib.rake
@@ -0,0 +1,18 @@
+MRuby.each_target do
+ current_dir = File.dirname(__FILE__)
+ relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
+ current_build_dir = "#{build_dir}/#{relative_from_root}"
+
+ self.libmruby << objfile("#{current_build_dir}/mrblib")
+
+ file objfile("#{current_build_dir}/mrblib") => "#{current_build_dir}/mrblib.c"
+ file "#{current_build_dir}/mrblib.c" => [mrbcfile, __FILE__] + Dir.glob("#{current_dir}/*.rb").sort do |t|
+ _, _, *rbfiles = t.prerequisites
+ FileUtils.mkdir_p File.dirname(t.name)
+ open(t.name, 'w') do |f|
+ _pp "GEN", "*.rb", "#{t.name.relative_path}"
+ f.puts File.read("#{current_dir}/init_mrblib.c")
+ mrbc.run f, rbfiles, 'mrblib_irep'
+ end
+ end
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/numeric.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/numeric.rb
new file mode 100644
index 00000000..89401a08
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/numeric.rb
@@ -0,0 +1,173 @@
+##
+# Numeric
+#
+# ISO 15.2.7
+class Numeric
+ include Comparable
+ ##
+ # Returns the receiver simply.
+ #
+ # ISO 15.2.7.4.1
+ def +@
+ self
+ end
+
+ ##
+ # Returns the receiver's value, negated.
+ #
+ # ISO 15.2.7.4.2
+ def -@
+ 0 - self
+ end
+
+ ##
+ # Returns the absolute value of the receiver.
+ #
+ # ISO 15.2.7.4.3
+ def abs
+ if self < 0
+ -self
+ else
+ self
+ end
+ end
+end
+
+##
+# Integral
+#
+# mruby special - module to share methods between Floats and Integers
+# to make them compatible
+module Integral
+ ##
+ # Calls the given block once for each Integer
+ # from +self+ downto +num+.
+ #
+ # ISO 15.2.8.3.15
+ def downto(num, &block)
+ return to_enum(:downto, num) unless block
+
+ i = self.to_i
+ while i >= num
+ block.call(i)
+ i -= 1
+ end
+ self
+ end
+
+ ##
+ # Returns self + 1
+ #
+ # ISO 15.2.8.3.19
+ def next
+ self + 1
+ end
+ # ISO 15.2.8.3.21
+ alias succ next
+
+ ##
+ # Calls the given block +self+ times.
+ #
+ # ISO 15.2.8.3.22
+ def times &block
+ return to_enum :times unless block
+
+ i = 0
+ while i < self
+ block.call i
+ i += 1
+ end
+ self
+ end
+
+ ##
+ # Calls the given block once for each Integer
+ # from +self+ upto +num+.
+ #
+ # ISO 15.2.8.3.27
+ def upto(num, &block)
+ return to_enum(:upto, num) unless block
+
+ i = self.to_i
+ while i <= num
+ block.call(i)
+ i += 1
+ end
+ self
+ end
+
+ ##
+ # Calls the given block from +self+ to +num+
+ # incremented by +step+ (default 1).
+ #
+ def step(num=nil, step=1, &block)
+ raise ArgumentError, "step can't be 0" if step == 0
+ return to_enum(:step, num, step) unless block
+
+ i = if num.kind_of? Float then self.to_f else self end
+ if num == nil
+ while true
+ block.call(i)
+ i+=step
+ end
+ return self
+ end
+ if step > 0
+ while i <= num
+ block.call(i)
+ i += step
+ end
+ else
+ while i >= num
+ block.call(i)
+ i += step
+ end
+ end
+ self
+ end
+end
+
+##
+# Integer
+#
+# ISO 15.2.8
+class Integer
+ include Integral
+ ##
+ # Returns the receiver simply.
+ #
+ # ISO 15.2.8.3.14
+ def ceil
+ self
+ end
+
+ ##
+ # Returns the receiver simply.
+ #
+ # ISO 15.2.8.3.17
+ def floor
+ self
+ end
+
+ ##
+ # Returns the receiver simply.
+ #
+ # ISO 15.2.8.3.24
+ alias round floor
+
+ ##
+ # Returns the receiver simply.
+ #
+ # ISO 15.2.8.3.26
+ alias truncate floor
+end
+
+##
+# Float
+#
+# ISO 15.2.9
+class Float
+ # mruby special - since mruby integers may be upgraded to floats,
+ # floats should be compatible to integers.
+ include Integral
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/range.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/range.rb
new file mode 100644
index 00000000..5bd2521e
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/range.rb
@@ -0,0 +1,67 @@
+##
+# Range
+#
+# ISO 15.2.14
+class Range
+
+ ##
+ # Calls the given block for each element of +self+
+ # and pass the respective element.
+ #
+ # ISO 15.2.14.4.4
+ def each(&block)
+ return to_enum :each unless block
+
+ val = self.first
+ last = self.last
+
+ if val.kind_of?(Fixnum) && last.kind_of?(Fixnum) # fixnums are special
+ lim = last
+ lim += 1 unless exclude_end?
+ i = val
+ while i < lim
+ block.call(i)
+ i += 1
+ end
+ return self
+ end
+
+ if val.kind_of?(String) && last.kind_of?(String) # fixnums are special
+ if val.respond_to? :upto
+ return val.upto(last, exclude_end?, &block)
+ else
+ str_each = true
+ end
+ end
+
+ raise TypeError, "can't iterate" unless val.respond_to? :succ
+
+ return self if (val <=> last) > 0
+
+ while (val <=> last) < 0
+ block.call(val)
+ val = val.succ
+ if str_each
+ break if val.size > last.size
+ end
+ end
+
+ block.call(val) if !exclude_end? && (val <=> last) == 0
+ self
+ end
+
+ # redefine #hash 15.3.1.3.15
+ def hash
+ h = first.hash ^ last.hash
+ h += 1 if self.exclude_end?
+ h
+ end
+end
+
+##
+# Range is enumerable
+#
+# ISO 15.2.14.3
+class Range
+ include Enumerable
+end
diff --git a/web/server/h2o/libh2o/deps/mruby/mrblib/string.rb b/web/server/h2o/libh2o/deps/mruby/mrblib/string.rb
new file mode 100644
index 00000000..4c6114ec
--- /dev/null
+++ b/web/server/h2o/libh2o/deps/mruby/mrblib/string.rb
@@ -0,0 +1,275 @@
+##
+# String
+#
+# ISO 15.2.10
+class String
+ include Comparable
+ ##
+ # Calls the given block for each line
+ # and pass the respective line.
+ #
+ # ISO 15.2.10.5.15
+ def each_line(rs = "\n", &block)
+ return to_enum(:each_line, rs, &block) unless block
+ return block.call(self) if rs.nil?
+ rs = rs.to_str
+ offset = 0
+ rs_len = rs.length
+ this = dup
+ while pos = this.index(rs, offset)
+ block.call(this[offset, pos + rs_len - offset])
+ offset = pos + rs_len
+ end
+ block.call(this[offset, this.size - offset]) if this.size > offset
+ self
+ end
+
+ # private method for gsub/sub
+ def __sub_replace(pre, m, post)
+ s = ""
+ i = 0
+ while j = index("\\", i)
+ break if j == length-1
+ t = case self[j+1]
+ when "\\"
+ "\\"
+ when "`"
+ pre
+ when "&", "0"
+ m
+ when "'"
+ post
+ when "1", "2", "3", "4", "5", "6", "7", "8", "9"
+ ""
+ else
+ self[j, 2]
+ end
+ s += self[i, j-i] + t
+ i = j + 2
+ end
+ s + self[i, length-i]
+ end
+
+ ##
+ # Replace all matches of +pattern+ with +replacement+.
+ # Call block (if given) for each match and replace
+ # +pattern+ with the value of the block. Return the
+ # final value.
+ #
+ # ISO 15.2.10.5.18
+ def gsub(*args, &block)
+ return to_enum(:gsub, *args) if args.length == 1 && !block
+ raise ArgumentError, "wrong number of arguments" unless (1..2).include?(args.length)
+
+ pattern, replace = *args
+ plen = pattern.length
+ if args.length == 2 && block
+ block = nil
+ end
+ if !replace.nil? || !block
+ replace = replace.to_str
+ end
+ offset = 0
+ result = []
+ while found = index(pattern, offset)
+ result << self[offset, found - offset]
+ offset = found + plen
+ result << if block
+ block.call(pattern).to_s
+ else
+ replace.__sub_replace(self[0, found], pattern, self[offset..-1] || "")
+ end
+ if plen == 0
+ result << self[offset, 1]
+ offset += 1
+ end
+ end
+ result << self[offset..-1] if offset < length
+ result.join
+ end
+
+ ##
+ # Replace all matches of +pattern+ with +replacement+.
+ # Call block (if given) for each match and replace
+ # +pattern+ with the value of the block. Modify
+ # +self+ with the final value.
+ #
+ # ISO 15.2.10.5.19
+ def gsub!(*args, &block)
+ raise RuntimeError, "can't modify frozen String" if frozen?
+ return to_enum(:gsub!, *args) if args.length == 1 && !block
+ str = self.gsub(*args, &block)
+ return nil if str == self
+ self.replace(str)
+ end
+
+ ##
+ # Calls the given block for each match of +pattern+
+ # If no block is given return an array with all
+ # matches of +pattern+.
+ #
+ # ISO 15.2.10.5.32
+ def scan(reg, &block)
+ ### *** TODO *** ###
+ unless Object.const_defined?(:Regexp)
+ raise NotImplementedError, "scan not available (yet)"
+ end
+ end
+
+ ##
+ # Replace only the first match of +pattern+ with
+ # +replacement+. Call block (if given) for each
+ # match and replace +pattern+ with the value of the
+ # block. Return the final value.
+ #
+ # ISO 15.2.10.5.36
+ def sub(*args, &block)
+ unless (1..2).include?(args.length)
+ raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 2)"
+ end
+
+ pattern, replace = *args
+ pattern = pattern.to_str
+ if args.length == 2 && block
+ block = nil
+ end
+ unless block
+ replace = replace.to_str
+ end
+ result = []
+ this = dup
+ found = index(pattern)
+ return this unless found
+ result << this[0, found]
+ offset = found + pattern.length
+ result << if block
+ block.call(pattern).to_s
+ else
+ replace.__sub_replace(this[0, found], pattern, this[offset..-1] || "")
+ end
+ result << this[offset..-1] if offset < length
+ result.join
+ end
+
+ ##
+ # Replace only the first match of +pattern+ with
+ # +replacement+. Call block (if given) for each
+ # match and replace +pattern+ with the value of the
+ # block. Modify +self+ with the final value.
+ #
+ # ISO 15.2.10.5.37
+ def sub!(*args, &block)
+ raise RuntimeError, "can't modify frozen String" if frozen?
+ str = self.sub(*args, &block)
+ return nil if str == self
+ self.replace(str)
+ end
+
+ ##
+ # Call the given block for each character of
+ # +self+.
+ def each_char(&block)
+ pos = 0
+ while pos < self.size
+ block.call(self[pos])
+ pos += 1
+ end
+ self
+ end
+
+ ##
+ # Call the given block for each byte of +self+.
+ def each_byte(&block)
+ bytes = self.bytes
+ pos = 0
+ while pos < bytes.size
+ block.call(bytes[pos])
+ pos += 1
+ end
+ self
+ end
+
+ ##
+ # Modify +self+ by replacing the content of +self+.
+ # The portion of the string affected is determined using the same criteria as +String#[]+.
+ def []=(*args)
+ anum = args.size
+ if anum == 2
+ pos, value = args
+ case pos
+ when String
+ posnum = self.index(pos)
+ if posnum
+ b = self[0, posnum.to_i]
+ a = self[(posnum + pos.length)..-1]
+ self.replace([b, value, a].join(''))
+ else
+ raise IndexError, "string not matched"
+ end
+ when Range
+ head = pos.begin
+ tail = pos.end
+ tail += self.length if tail < 0
+ unless pos.exclude_end?
+ tail += 1
+ end
+ return self[head, tail-head]=value
+ else
+ pos += self.length if pos < 0
+ if pos < 0 || pos > self.length
+ raise IndexError, "index #{args[0]} out of string"
+ end
+ b = self[0, pos.to_i]
+ a = self[pos + 1..-1]
+ self.replace([b, value, a].join(''))
+ end
+ return value
+ elsif anum == 3
+ pos, len, value = args
+ pos += self.length if pos < 0
+ if pos < 0 || pos > self.length
+ raise IndexError, "index #{args[0]} out of string"
+ end
+ if len < 0
+ raise IndexError, "negative length #{len}"
+ end
+ b = self[0, pos.to_i]
+ a = self[pos + len..-1]
+ self.replace([b, value, a].join(''))
+ return value
+ else
+ raise ArgumentError, "wrong number of arguments (#{anum} for 2..3)"
+ end
+ end
+
+ ##
+ # ISO 15.2.10.5.3
+ def =~(re)
+ raise TypeError, "type mismatch: String given" if re.respond_to? :to_str
+ re =~ self
+ end
+
+ ##
+ # ISO 15.2.10.5.27
+ def match(re, &block)
+ if re.respond_to? :to_str
+ if Object.const_defined?(:Regexp)
+ r = Regexp.new(re)
+ r.match(self, &block)
+ else
+ raise NotImplementedError, "String#match needs Regexp class"
+ end
+ else
+ re.match(self, &block)
+ end
+ end
+end
+
+##
+# String is comparable
+#
+# ISO 15.2.10.3
+module Comparable; end
+class String
+ include Comparable
+end