end
+# A `String` holds and manipulates an arbitrary sequence of characters.
+#
+# String objects may be created using literals.
+#
+# assert "Hello World!" isa String
abstract class String
super Text
# assert "abc" * 0 == ""
fun *(i: Int): SELFTYPE is abstract
+ # Insert `s` at `pos`.
+ #
+ # assert "helloworld".insert_at(" ", 5) == "hello world"
fun insert_at(s: String, pos: Int): SELFTYPE is abstract
redef fun substrings: Iterator[String] is abstract
end
+# A mutable sequence of characters.
abstract class Buffer
super Text
# Create a new empty string.
init do end
+ # Create a new string copied from `s`.
init from(s: Text)
do
capacity = s.length + 1
super StringCapable
# Creates a new NativeString with a capacity of `length`
new(length: Int) is intern
+
+ # Get char at `index`.
fun [](index: Int): Char is intern
+
+ # Set char `item` at index.
fun []=(index: Int, item: Char) is intern
+
+ # Copy `self` to `dest`.
fun copy_to(dest: NativeString, length: Int, from: Int, to: Int) is intern
# Position of the first nul character.
while self[l] != '\0' do l += 1
return l
end
+
+ # Parse `self` as an Int.
fun atoi: Int is intern
+
+ # Parse `self` as a Float.
fun atof: Float is extern "atof"
redef fun to_s
return to_s_with_length(cstring_length)
end
+ # Returns `self` as a String of `length`.
fun to_s_with_length(length: Int): FlatString
do
assert length >= 0
return str
end
+ # Returns `self` as a new String.
fun to_s_with_copy: FlatString
do
var length = cstring_length
# StringCapable objects can create native strings
interface StringCapable
+
+ # Allocate a string of `size`.
protected fun calloc_string(size: Int): NativeString is intern
end