Merge branch 'alexandre/typo-in-nit-reference' into wip
[nit.git] / lib / standard / string.nit
index bcd0445..c6a3e50 100644 (file)
@@ -11,7 +11,7 @@
 # You  are  allowed  to  redistribute it and sell it, alone or is a part of
 # another product.
 
-# This module is about character strings.
+# Basic manipulations of strings of characters
 package string
 
 intrude import collection # FIXME should be collection::array
@@ -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]
@@ -51,7 +53,7 @@ abstract class AbstractString
                end
        end
 
-       # Create a substring with the string beginning at the 'from' position
+       # Create a substring from `self' beginning at the 'from' position
        #
        # "abcd".substring(1)   # --> "bcd"
        # "abcd".substring(-1)  # --> "abcd"
@@ -62,7 +64,7 @@ abstract class AbstractString
                return substring(from, length - from)
        end
 
-       # is this string a substring of the 'of' string from pos 'pos'
+       # Is `self' a substring of the `str' string from pos `pos'
        #
        # "bc".is_substring("abcd",1)   # --> true
        # "bc".is_substring("abcd",2)   # --> false
@@ -131,7 +133,7 @@ abstract class AbstractString
                end
        end
 
-       # String to upper case
+       # A upper case version of `self'
        fun to_upper: String
        do
                var s = new Buffer.with_capacity(length)
@@ -139,7 +141,7 @@ abstract class AbstractString
                return s.to_s
        end
 
-       # String to lower case
+       # A lower case version of `self'
        fun to_lower : String
        do
                var s = new Buffer.with_capacity(length)
@@ -158,10 +160,11 @@ abstract class AbstractString
        end
 end
 
-
+# Immutable strings of characters.
 class String
        super Comparable
        super AbstractString
+
        redef type OTHER: String
 
        # Create a new string from a given char *.
@@ -261,9 +264,11 @@ class String
                return h
 
        end
+
+       fun to_f : Float is extern import String::to_cstring
 end
 
-# Strings are arrays of characters.
+# Mutable strings of characters.
 class Buffer
        super AbstractString
        super Comparable
@@ -393,27 +398,27 @@ 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.
        private fun native_class_name: NativeString is intern
 
        # The class name of the object.
-       # FIXME: real type information is not available at runtime. Therefore, for instance, an instance of List[Bool] has just "List" for classname
+       # FIXME: real type information is not available at runtime.
+       # Therefore, for instance, an instance of List[Bool] has just
+       # "List" for class_name
        fun class_name: String do return new String.from_cstring(native_class_name)
 
-       # Developper readable representation of `self'.
-       # Usualy, it uses the form "<CLASSNAME:#OBJECTID bla bla bla>"
+       # Developer readable representation of `self'.
+       # Usually, it uses the form "<CLASSNAME:#OBJECTID bla bla bla>"
        fun inspect: String
        do
                return "<{inspect_head}>"
        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}"
@@ -555,8 +560,10 @@ redef class Array[E]
 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
+       # Concatenate couple of 'key value'.
+       # key and value are separated by 'couple_sep'.
+       # each couple is separated each couple with `sep'.
+       fun join(sep: String, couple_sep: String): String
        do
                if is_empty then return ""
                
@@ -582,7 +589,7 @@ redef class Map[K,V]
 end
 
 ###############################################################################
-# Native classe                                                               #
+# Native classes                                                              #
 ###############################################################################
 
 # Native strings are simple C char *
@@ -602,7 +609,7 @@ class NativeString
 end
 
 # StringCapable objects can create native strings
-class StringCapable
+interface StringCapable
        protected fun calloc_string(size: Int): NativeString is intern
 end