# This module is about character strings.
package string
-intrude import array
+intrude import collection # FIXME should be collection::array
+import hash
###############################################################################
# String #
###############################################################################
abstract class AbstractString
-special AbstractArrayRead[Char]
+ super AbstractArrayRead[Char]
readable private var _items: NativeString
redef fun [](index) do return _items[index]
var myitems = _items
var itsitems = str._items
if myindex > length or itsindex > myindex then return false
- while itsindex > 0 do
+ while itsindex >= 0 do
if myitems[myindex] != itsitems[itsindex] then return false
- myindex -= myindex
- itsindex -= itsindex
+ myindex -= 1
+ itsindex -= 1
end
return true
end
class String
-special Comparable
-special AbstractString
+ super Comparable
+ super AbstractString
redef type OTHER: String
# Create a new string from a given char *.
end
redef fun to_s do return self
+
+ redef fun hash
+ do
+ # djb2 hash algorythm
+ var h = 5381
+ var i = _length - 1
+ var it = _items
+ while i >= 0 do
+ h = (h * 32) + h + it[i].ascii
+ i -= 1
+ end
+ return h
+
+ end
end
# Strings are arrays of characters.
class Buffer
-special AbstractString
-special Comparable
-special StringCapable
-special AbstractArray[Char]
+ super AbstractString
+ super Comparable
+ super StringCapable
+ super AbstractArray[Char]
redef type OTHER: String
return "<{object_id.to_hex}"
end
- protected fun args: IndexedCollection[String]
+ protected fun args: Sequence[String]
do
return sys.args
end
end
redef class Sys
- var _args_cache: nullable IndexedCollection[String]
+ var _args_cache: nullable Sequence[String]
- redef fun args: IndexedCollection[String]
+ redef fun args: Sequence[String]
do
if _args_cache == null then init_args
return _args_cache.as(not null)