lib: update the documentation
authorJean Privat <jean@pryen.org>
Tue, 14 Feb 2012 19:49:19 +0000 (14:49 -0500)
committerJean Privat <jean@pryen.org>
Tue, 14 Feb 2012 19:49:19 +0000 (14:49 -0500)
Add some examples and fix some spelling issues

Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/collection/abstract_collection.nit
lib/standard/collection/array.nit
lib/standard/collection/hash_collection.nit
lib/standard/collection/range.nit
lib/standard/environ.nit
lib/standard/file.nit
lib/standard/kernel.nit
lib/standard/math.nit
lib/standard/string.nit
lib/standard/string_search.nit

index 3a2b25b..c3643b1 100644 (file)
@@ -10,7 +10,7 @@
 # You  are  allowed  to  redistribute it and sell it, alone or is a part of
 # another product.
 
-# This module define several abtract collection classes.
+# This module define several abstract collection classes.
 package abstract_collection
 
 import kernel
@@ -19,7 +19,7 @@ import kernel
 #
 # Instances of this class offers an iterator method.
 #
-# Colections instances can use the "for" structure:
+# Collections instances can use the "for" structure:
 #        var x: Collection[U]
 #         ...
 #         for u in x do
@@ -60,16 +60,16 @@ interface Collection[E]
        fun length: Int is abstract
 
        # Is `item' in the collection ?
-       # Comparaisons are done with ==
+       # Comparisons are done with ==
        fun has(item: E): Bool is abstract
 
        # Is the collection contain only `item' ?
-       # Comparaisons are done with ==
+       # Comparisons are done with ==
        # Return true if the collection is empty.
        fun has_only(item: E): Bool is abstract
 
-       # How many occurences of `item' are in the collection ?
-       # Comparaisons are done with ==
+       # How many occurrences of `item' are in the collection ?
+       # Comparisons are done with ==
        fun count(item: E): Int is abstract
 
        # Return one the item of the collection
@@ -202,10 +202,10 @@ end
 
 # Abstract sets.
 #
-# Set contains contains only one element with the same value (according to =).
-#    var s : Set[E]
+# Set contains contains only one element with the same value (according to ==).
+#    var s: Set[E]
 #    var a = "Hello"
-#    var b = "Hello"
+#    var b = "Hel" + "lo"
 #    ...
 #    s.add(a)
 #    s.has(b) # --> true
@@ -238,6 +238,7 @@ interface Set[E: Object]
        redef fun remove_all(item) do remove(item)
 end
 
+# MapRead are abstract associative collections: `key' -> `item'.
 interface MapRead[K: Object, E]
        # Get the item at `key'.
        fun [](key: K): E is abstract
@@ -259,13 +260,17 @@ interface MapRead[K: Object, E]
                end
        end
 
-       # Return the point of view of self on the values only
+       # Return the point of view of self on the values only.
+       # Note that `self' and `values' are views on the same data;
+       # therefore any modification of one is visible on the other.
        fun values: Collection[E] is abstract
 
-       # Return the point of view of self on the keys only
+       # Return the point of view of self on the keys only.
+       # Note that `self' and `keys' are views on the same data;
+       # therefore any modification of one is visible on the other.
        fun keys: Collection[E] is abstract
 
-       # Is there no item in the collection ?
+       # Is there no item in the collection?
        fun is_empty: Bool is abstract 
 
        # Number of items in the collection.
@@ -282,8 +287,18 @@ end
 #     map[u2] = v2      # Associate 'v2' to 'u2'
 #     map[u1]            # -> v1
 #     map[u2]            # -> v2
-#     map.has_key(u1)    # -> true
-#     map.has_key(u3)    # -> false
+#
+# Instances of maps can be used with the for structure
+#
+#     for key, value in map do ..
+#
+# The keys and values in the map can also be manipulated directly with the `keys' and `values' methods.
+#
+#     map.keys.has(u1)   # -> true
+#     map.keys.has(u3)   # -> false
+#     map.values.has(v1)   # -> true
+#     map.values.has(v3)   # -> false
+#
 interface Map[K: Object, E]
        super MapRead[K, E]
        # Set the`item' at `key'.
@@ -351,7 +366,7 @@ class MapValuesIterator[K: Object, V]
        redef fun item do return self.iterator.item
 end
 
-# Indexed collection are ordoned collections.
+# Sequences are indexed collections.
 # The first item is 0. The last is `length'-1.
 interface SequenceRead[E]
        super Collection[E]
@@ -363,6 +378,9 @@ interface SequenceRead[E]
                return self[0]
        end
 
+       # Return the index=th element of the sequence.
+       # The first element is 0 and the last if `length-1'
+       # If index is invalid, the program aborts
        fun [](index: Int): E is abstract
 
        # Get the last item.
@@ -373,8 +391,9 @@ interface SequenceRead[E]
                return self[length-1]
        end
 
-       # Return the index of the first occurence of `item'.
+       # Return the index of the first occurrence of `item'.
        # Return -1 if `item' is not found
+       # Comparison is done with ==
        fun index_of(item: E): Int
        do
                var i = iterator
@@ -388,11 +407,12 @@ interface SequenceRead[E]
        redef fun iterator: IndexedIterator[E] is abstract
 end
 
-# Indexed collection are ordoned collections.
+# Sequence are indexed collection.
 # The first item is 0. The last is `length'-1.
 interface Sequence[E]
        super SequenceRead[E]
        super SimpleCollection[E]
+
        # Set the first item.
        # Is equivalent with `self'[0] = `item'.
        fun first=(item: E)
@@ -443,7 +463,7 @@ interface IndexedIterator[E]
        fun index: Int is abstract
 end
 
-# Associatives arrays that internally uses couples to represent each (key, value) pairs.
+# Associative arrays that internally uses couples to represent each (key, value) pairs.
 interface CoupleMap[K: Object, E]
        super Map[K, E]
        # Return the couple of the corresponding key
index e8f7448..c5e2c7f 100644 (file)
@@ -17,10 +17,10 @@ package array
 
 import abstract_collection
 
-# One dimention array of objects.
+# One dimension array of objects.
 class AbstractArrayRead[E]
        super SequenceRead[E]
-       # The current length
+
        redef readable var _length: Int = 0
 
        redef fun is_empty do return _length == 0
@@ -61,8 +61,12 @@ class AbstractArrayRead[E]
 
        redef fun index_of(item) do return index_of_from(item, 0)
 
+       # The index of the last occurrence of an element.
+       # Return -1 if not found.
        fun last_index_of(item: E): Int do return last_index_of_from(item, length-1)
 
+       # The index of the first occurrence of an element starting from pos.
+       # Return -1 if not found.
        fun index_of_from(item: E, pos: Int): Int
        do
                var i = pos
@@ -76,6 +80,8 @@ class AbstractArrayRead[E]
                return -1
        end
 
+       # The index of the last occurrence of an element starting from pos.
+       # Return -1 if not found.
        fun last_index_of_from(item: E, pos: Int): Int
        do
                var i = pos
@@ -89,6 +95,9 @@ class AbstractArrayRead[E]
                return -1
        end
 
+       # Return a new array that is the reverse of `self'
+       #
+       #     [1,2,3].reversed # -> [3, 2, 1]
        fun reversed: Array[E]
        do
                var cmp = _length
@@ -100,6 +109,12 @@ class AbstractArrayRead[E]
                return result
        end
 
+       # Copy a portion of `self' to an other array.
+       #
+       #     var a = [1, 2, 3, 4]
+       #     var b = [10, 20, 30, 40, 50]
+       #     a.copy_to(1, 2, b, 2)
+       #     b # -> [10, 20, 2, 3, 50]
        protected fun copy_to(start: Int, len: Int, dest: AbstractArray[E], new_start: Int)
        do
                # TODO native one
@@ -138,10 +153,14 @@ class AbstractArrayRead[E]
        end
 end
 
-# Resizeable one dimention array of objects.
+# Resizable one dimension array of objects.
 class AbstractArray[E]
        super AbstractArrayRead[E]
        super Sequence[E]
+
+       # Force the capacity to be at least `cap'.
+       # The capacity of the array is an internal information.
+       # However, this method can be used to prepare a large amount of add
        fun enlarge(cap: Int) is abstract
 
        redef fun push(item) do add(item)
@@ -178,6 +197,11 @@ class AbstractArray[E]
                self[0] = item
        end
 
+       # Insert an element at a given position, following elements are shifted.
+       #
+       #     var a= [10, 20, 30, 40]
+       #     a.insert(100, 2)
+       #     a # -> [10, 20, 100, 30, 40]
        fun insert(item: E, pos: Int)
        do
                enlarge(length + 1)
@@ -213,7 +237,12 @@ class AbstractArray[E]
                end
        end
 
-       fun swap_at( a : Int, b : Int )
+       # Invert two elements in the array
+       #
+       #     var a = [10, 20, 30, 40]
+       #     a.swap_at(1, 3)
+       #     a # -> [10, 40, 30, 20]
+       fun swap_at(a: Int,b: Int)
        do
            var e = self[a]
            self[a] = b
@@ -221,7 +250,7 @@ class AbstractArray[E]
        end
 end
 
-# Resizeable one dimention array of objects.
+# Resizable one dimension array of objects.
 #
 # Arrays have a literal representation.
 #     a = [12, 32, 8]
@@ -233,6 +262,7 @@ end
 class Array[E]
        super AbstractArray[E]
        super ArrayCapable[E]
+
        redef fun iterate
                !each(e: E)
        do
@@ -397,6 +427,7 @@ end
 # An `Iterator' on `AbstractArray'
 class ArrayIterator[E]
        super IndexedIterator[E]
+
        redef fun item do return _array[_index]
 
        # redef fun item=(e) do _array[_index] = e
@@ -420,6 +451,7 @@ end
 # A set implemented with an Array.
 class ArraySet[E: Object]
        super Set[E]
+
        # The stored elements.
        var _array: Array[E]
 
@@ -449,7 +481,7 @@ class ArraySet[E: Object]
 
        redef fun iterator do return new ArraySetIterator[E](_array.iterator)
 
-       # Assume the capacitydd is at least `cap'.
+       # Assume the capacity is at least `cap'.
        fun enlarge(cap: Int) do _array.enlarge(cap)
 
        private fun remove_at(i: Int)
index 07bc985..989308c 100644 (file)
@@ -19,6 +19,7 @@ import hash
 # A HashCollection is an array of HashNode[K] indexed by the K hash value
 private class HashCollection[K: Object, N: HashNode[K]]
        super ArrayCapable[nullable N]
+
        var _array: nullable NativeArray[nullable N] = null # Used to store items
        var _capacity: Int = 0 # Size of _array
        var _length: Int = 0 # Number of items in the map
@@ -134,6 +135,7 @@ private class HashCollection[K: Object, N: HashNode[K]]
                _last_accessed_key = null
        end
 
+       # Clear the whole structure
        fun raz
        do
                var i = _capacity - 1
@@ -147,6 +149,7 @@ private class HashCollection[K: Object, N: HashNode[K]]
                _last_accessed_key = null
        end
 
+       # Force a capacity
        fun enlarge(cap: Int)
        do
                var old_cap = _capacity
@@ -196,6 +199,8 @@ private class HashNode[K: Object]
        end
 end
 
+# A map implemented with a hash table.
+# Keys of such a map cannot be null and require a working `hash' method
 class HashMap[K: Object, V]
        super Map[K, V]
        super HashCollection[K, HashMapNode[K, V]]
@@ -251,6 +256,7 @@ class HashMap[K: Object, V]
        redef var values: HashMapValues[K, V] = new HashMapValues[K, V](self)
 end
 
+# View of the keys of a HashMap
 class HashMapKeys[K: Object, V]
        super RemovableCollection[K]
        # The original map
@@ -271,6 +277,7 @@ class HashMapKeys[K: Object, V]
        redef fun remove_all(key) do self.map.remove_node(key)
 end
 
+# View of the values of a Map
 class HashMapValues[K: Object, V]
        super RemovableCollection[V]
        # The original map
@@ -341,7 +348,7 @@ class HashMapValues[K: Object, V]
        end
 end
 
-class HashMapNode[K: Object, V]
+private class HashMapNode[K: Object, V]
        super HashNode[K]
        redef type N: HashMapNode[K, V]
        var _value: V
@@ -394,6 +401,8 @@ class HashMapIterator[K: Object, V]
        end
 end
 
+# A `Set' implemented with a hash table.
+# Keys of such a map cannot be null and require a working `hash' method
 class HashSet[E: Object]
        super Set[E]
        super HashCollection[E, HashSetNode[E]]
@@ -438,7 +447,7 @@ class HashSet[E: Object]
        end
 end
 
-class HashSetNode[E: Object]
+private class HashSetNode[E: Object]
        super HashNode[E]
        redef type N: HashSetNode[E]
 
index 9dbbc80..b8545b3 100644 (file)
@@ -15,7 +15,7 @@ package range
 
 import abstract_collection
 
-# Range of discrete objects. 
+# Range of discrete objects.
 class Range[E: Discrete]
        super Collection[E]
 
@@ -87,7 +87,7 @@ end
 class IteratorRange[E: Discrete]
        # Iterator on ranges.
        super Iterator[E]
-       var _range: Range[E]    
+       var _range: Range[E]
        redef readable var _item: E
 
        redef fun is_ok do return _item < _range.after
index 9c584de..05b731a 100644 (file)
@@ -17,7 +17,8 @@ import symbol
 # TODO prevoir une structure pour recup tout un environ, le modifier et le passer a process
 
 redef class Symbol
-       # Return environement valued for this symbol
+       # Return environement value for this symbol
+       # If there is no such environement value, then return ""
        fun environ: String
        do
                var res = to_s.to_cstring.get_environ
@@ -32,6 +33,5 @@ redef class Symbol
 end
 
 redef class NativeString
-# Refinned to add environement bindings
        private fun get_environ: NativeString is extern "string_NativeString_NativeString_get_environ_0"
 end
index 6592b85..10e10e4 100644 (file)
@@ -68,6 +68,8 @@ class IFStream
        super BufferedIStream
        # Misc
 
+       # Open the same file again.
+       # The original path is reused, therefore the reopened file can be a different file.
        fun reopen
        do
                if not eof then close
@@ -83,7 +85,6 @@ class IFStream
                _end_reached = true
        end
 
-       # Fill the internal read buffer. Needed by read operations.
        redef fun fill_buffer
        do
                var nb = _file.io_read(_buffer._items, _buffer._capacity)
@@ -116,7 +117,6 @@ class OFStream
        super FStream
        super OStream
        
-       # Write a string.
        redef fun write(s)
        do
                assert _writable
@@ -195,8 +195,10 @@ redef class String
 
        fun file_stat: FileStat do return to_cstring.file_stat
 
+       # Remove a file, return true if success
        fun file_delete: Bool do return to_cstring.file_delete
 
+       # remove the trailing extension "ext"
        fun strip_extension(ext: String): String
        do
                if has_suffix(ext) then
@@ -205,6 +207,7 @@ redef class String
                return self
        end
 
+       # Extract the basename of a path and remove the extension
        fun basename(ext: String): String
        do
                var pos = last_index_of_from('/', _length - 1)
@@ -215,6 +218,7 @@ redef class String
                return n.strip_extension(ext)
        end
 
+       # Extract the dirname of a path
        fun dirname: String
        do
                var pos = last_index_of_from('/', _length - 1)
@@ -225,16 +229,6 @@ redef class String
                end
        end
 
-       fun file_path: String
-       do
-               var l = _length
-               var pos = last_index_of_from('/', l - 1)
-               if pos >= 0 then
-                       return substring(0, pos)
-               end
-               return "."
-       end
-
        # Create a directory (and all intermediate directories if needed)
        fun mkdir
        do
@@ -253,6 +247,7 @@ redef class String
                end
        end
 
+       # Return right-most extension (without the dot)
        fun file_extension : nullable String
        do
                var last_slash = last_index_of('.')
index f34766e..1fab3be 100644 (file)
@@ -21,25 +21,32 @@ import end # Mark this module is a top level one. (must be only one)
 ###############################################################################
 
 # The root of the class hierarchy.
-# Each class implicitely specialize Object.
+# Each class implicitly specialize Object.
+#
+# Currently, Object is also used to collect all top-level methods.
 interface Object
-       # The unique object identifier in the class
+       # The unique object identifier in the class.
+       # Unless specific code, you should not use this method.
+       # The identifier is used internally to provide a hash value.
        fun object_id: Int is intern
 
-       # Return true is `self' and `other' have the same dynamic type
+       # Return true is `self' and `other' have the same dynamic type.
+       # Unless specific code, you should not use this method.
        fun is_same_type(other: Object): Bool is intern
 
        # Have `self' and `other' the same value?
        ##
-       # Implicitely, the default implementation, is ==
+       # The exact meaning of "same value" is let to the subclasses.
+       # Implicitly, the default implementation, is ==
        fun ==(other: nullable Object): Bool do return self is other
 
        # Have `self' and `other' different values?
        ##
-       # != is equivament with "not =".
+       # != is equivalent with "not =".
        fun !=(other: nullable Object): Bool do return not (self == other)
 
        # Display self on stdout (debug only).
+       # This method MUST not be used by programs, it is here for debugging only and can be removed without any notice
        fun output
        do
                '<'.output
@@ -48,15 +55,21 @@ interface Object
        end
 
        # Display class name on stdout (debug only).
+       # This method MUST not be used by programs, it is here for debugging only and can be removed without any notice
        fun output_class_name is intern 
 
-       protected fun exit(exit_value: Int) is intern # Quit the program.
-       protected fun sys: Sys is intern # The global sys object
+       # Quit the program with a specific return code
+       protected fun exit(exit_value: Int) is intern
+
+       # Return the global sys object, the only instance of the `Sys' class.
+       protected fun sys: Sys is intern
 end
 
 # The main class of the program.
+# `Sys' is a singleton class, its only instance is `sys' defined in `Object'.
+# `sys' is used to invoke methods on the program on the system.
 class Sys
-       # Instructions outside classes implicetely redefine this method.
+       # Instructions outside classes implicitly redefine this method.
        fun main do end
 end
 
@@ -67,21 +80,25 @@ end
 # The ancestor of class where objects are in a total order.
 # In order to work, the method '<' has to be redefined.
 interface Comparable
+       # What `self' can be compared to?
        type OTHER: Comparable
 
-       # Is `self' lesser than `other'
+       # Is `self' lesser than `other'?
        fun <(other: OTHER): Bool is abstract 
 
        # not `other' < `self'
+       # Note, the implementation must ensure that: (x<=y) == (x<y or x==y)
        fun <=(other: OTHER): Bool do return not other < self
 
        # not `self' < `other' 
+       # Note, the implementation must ensure that: (x>=y) == (x>y or x==y)
        fun >=(other: OTHER): Bool do return not self < other
 
        # `other' < `self'
        fun >(other: OTHER): Bool do return other < self
 
        # -1 if <, +1 if > and 0 otherwise
+       # Note, the implementation must ensure that: (x<=>y == 0) == (x==y)
        fun <=>(other: OTHER): Int
        do
                if self < other then
@@ -168,9 +185,9 @@ end
 # Native classes                                                              #
 ###############################################################################
 
-# Native booleans.
+# Native Booleans.
 # `true' and `false' are the only instances.
-# Boolean are manipulated trought three special operators:
+# Boolean are manipulated trough three special operators:
 #       `and', `or', `not'.
 # Booleans are mainly used by conditional statement and loops.
 universal Bool
@@ -280,7 +297,7 @@ universal Int
        # The character whose ASCII value is `self'.
        fun ascii: Char is intern
 
-       # Number of digits of an integer in base `b' plus one if negative)
+       # Number of digits of an integer in base `b' (plus one if negative)
        fun digit_count(b: Int): Int
        do
                var d: Int # number of digits
@@ -298,7 +315,7 @@ universal Int
                # count digits
                while n > 0 do
                        d += 1
-                       n = n / b       # euclidian division /          
+                       n = n / b       # euclidian division /
                end
                return d
        end
@@ -316,7 +333,7 @@ universal Int
                end
        end
 
-       # Executre 'each' for each integer in [self..last]
+       # Execute 'each' for each integer in [self..last]
        fun enumerate_to(last: Int)
                !each(i: Int)
        do
@@ -327,7 +344,7 @@ universal Int
                end
        end
 
-       # Executre 'each' for each integer in [self..after[
+       # Execute 'each' for each integer in [self..after[
        fun enumerate_before(after: Int)
                !each(i: Int)
        do
@@ -338,7 +355,8 @@ universal Int
                end
        end
 
-       fun abs : Int
+       # The absolute value of self
+       fun abs: Int
        do
            if self >= 0
            then
@@ -379,7 +397,7 @@ universal Char
                end
        end
 
-       # If `self' is a digit then return this digit.
+       # If `self' is a digit then return this digit else return -1.
        fun to_i: Int
        do
 
@@ -398,8 +416,9 @@ universal Char
        redef fun +(i) is intern
        redef fun -(i) is intern
 
-       # Char to lower case
-       fun to_lower : Char
+       # Return the lower case version of self.
+       # If self is not a letter, then return self
+       fun to_lower: Char
        do
                if is_upper then
                        return (ascii + ('a'.distance('A'))).ascii
@@ -408,8 +427,9 @@ universal Char
                end
        end
 
-       # Char to upper case
-       fun to_upper : Char
+       # Return the upper case version of self.
+       # If self is not a letter, then return self
+       fun to_upper: Char
        do
                if is_lower then
                        return (ascii - ('a'.distance('A'))).ascii
@@ -418,21 +438,25 @@ universal Char
                end
        end
        
+       # Is self a digit? (from '0' to '9')
        fun is_digit : Bool
        do
                return self >= '0' and self <= '9'
        end
        
+       # Is self a lower case letter? (from 'a' to 'z')
        fun is_lower : Bool
        do
                return self >= 'a' and self <= 'z'
        end
        
+       # Is self a upper case letter? (from 'A' to 'Z')
        fun is_upper : Bool
        do
                return self >= 'A' and self <= 'Z'
        end
        
+       # Is self a letter? (from 'A' to 'Z' and 'a' to 'z')
        fun is_letter : Bool
        do
                return is_lower or is_upper
index 0e3d57e..f27501e 100644 (file)
@@ -38,6 +38,7 @@ redef class Float
 end
 
 redef class Collection[ E ]
+       # Return a random element in the collection
        fun rand : nullable E
        do
                if is_empty then return null
index bcd0445..6089102 100644 (file)
@@ -21,8 +21,10 @@ import hash
 # String                                                                      #
 ###############################################################################
 
+# Common subclass for String and Buffer
 abstract class AbstractString
        super AbstractArrayRead[Char]
+
        readable private var _items: NativeString
 
        redef fun [](index) do return _items[index]
@@ -162,6 +164,7 @@ end
 class String
        super Comparable
        super AbstractString
+
        redef type OTHER: String
 
        # Create a new string from a given char *.
@@ -395,7 +398,7 @@ end
 redef class Object
        #   fun class_name: String is extern intern # The name of the class
 
-       # User redeable representation of `self'.
+       # User readable representation of `self'.
        fun to_s: String do return inspect
 
        # The class name of the object in NativeString format.
@@ -405,7 +408,7 @@ redef class Object
        # FIXME: real type information is not available at runtime. Therefore, for instance, an instance of List[Bool] has just "List" for classname
        fun class_name: String do return new String.from_cstring(native_class_name)
 
-       # Developper readable representation of `self'.
+       # Developer readable representation of `self'.
        # Usualy, it uses the form "<CLASSNAME:#OBJECTID bla bla bla>"
        fun inspect: String
        do
@@ -413,7 +416,7 @@ redef class Object
        end
 
        # Return "CLASSNAME:#OBJECTID".
-       # This fuction is mainly used with the redefinition of the inspect method
+       # This function is mainly used with the redefinition of the inspect method
        protected fun inspect_head: String
        do
                return "{class_name}:#{object_id.to_hex}"
@@ -556,7 +559,7 @@ end
 
 redef class Map[K,V]
        # Concatenate couple of 'key value' separate by 'couple_sep' and separate each couple with `sep'. 
-       fun map_join(sep: String, couple_sep: String): String
+       fun join(sep: String, couple_sep: String): String
        do
                if is_empty then return ""
                
@@ -582,7 +585,7 @@ redef class Map[K,V]
 end
 
 ###############################################################################
-# Native classe                                                               #
+# Native classes                                                              #
 ###############################################################################
 
 # Native strings are simple C char *
index 162beec..59f7a81 100644 (file)
@@ -27,7 +27,7 @@ interface Pattern
        # Return null if not found.
        fun search_in(s: String, from: Int): nullable Match is abstract
 
-       # Search all `self' occucences into `s'.
+       # Search all `self' occurrences into `s'.
        fun search_all_in(s: String): Array[Match]
        do
                var res = new Array[Match] # Result
@@ -64,9 +64,10 @@ end
 # see also http://www.cs.utexas.edu/users/moore/best-ideas/string-searching/index.html
 class BM_Pattern
        super Pattern
+
        redef fun to_s do return _motif
 
-       # boyer-moore search gives the position of the first occurence of a pattern starting at position `from'
+       # boyer-moore search gives the position of the first occurrence of a pattern starting at position `from'
        redef fun search_index_in(s, from)
        do
                assert from >= 0
@@ -207,14 +208,14 @@ class Match
        # The starting position in the string
        readable var _from: Int
 
-       # The length of the mathching part
+       # The length of the matching part
        readable var _length: Int
 
        # The position of the first character just after the matching part.
        # May be out of the base string
        fun after: Int do return _from + _length
 
-       # The contents of the mathing part
+       # The contents of the matching part
        redef fun to_s do return _string.substring(_from, _length)
 
        # Matches `len' characters of `s' from `f'.
@@ -231,6 +232,7 @@ end
 
 redef class Char
        super Pattern
+
        redef fun search_index_in(s, from)
        do
                var stop = s.length
@@ -254,6 +256,7 @@ end
 
 redef class String
        super Pattern
+
        redef fun search_index_in(s, from)
        do
                assert from >= 0
@@ -279,7 +282,7 @@ redef class String
                end
        end
 
-       # Like `search_from' but from the first chararter.
+       # Like `search_from' but from the first character.
        fun search(p: Pattern): nullable Match do return p.search_in(self, 0)
 
        # Search the given pattern into self from a.
@@ -287,7 +290,7 @@ redef class String
        # Return null if not found.
        fun search_from(p: Pattern, from: Int): nullable Match do return p.search_in(self, from)
 
-       # Search all occurences of p into self.
+       # Search all occurrences of p into self.
        #
        #   var a = new Array[Int]
        #   for i in "hello world".searches('o') do