# 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
# 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]
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"
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
end
end
- # String to upper case
+ # A upper case version of `self'
fun to_upper: String
do
var s = new Buffer.with_capacity(length)
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)
end
end
-
+# Immutable strings of characters.
class String
super Comparable
super AbstractString
+
redef type OTHER: String
# Create a new string from a given char *.
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
###############################################################################
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}"
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 ""
end
###############################################################################
-# Native classe #
+# Native classes #
###############################################################################
# Native strings are simple C char *
end
# StringCapable objects can create native strings
-class StringCapable
+interface StringCapable
protected fun calloc_string(size: Int): NativeString is intern
end