@string
Strings are sequences of characters. They keep track of their length.
Strings are sequences of characters. They keep track of their length.
//use built in LIL strings
var myStr: "Hello world";
myStr.append(", have a great day!");
//or do it manually
var otherStr: @string { };
otherStr.initialize(`this is a c style string`, 24);
Type: var.i64
The amount of bytes that are used in the buffer for storing the string.
print myStr.length;
Type: var.[56 x i8]
The internal storage space for characters, using the short string optimization. When the string is long, it contains a pointer to the buffer on the heap.
return pointerTo(@self.buffer) => cstr;
Type: fn
The constructor for this class. This method will be called automatically.
Type: fn
The destructor for this class. This method will be called automatically.
Type: fn => ptr(i8)
Returns a pointer to the characters as a C string, aka ptr(i8).
var str: "This is a LIL string";
doStuffWithCStr(str.cstr());
Type: fn(ptr(@string))
Add the content of the given string to the end of this one.
The other string, which will be added to this one.
var str: "Hello there ";
str.add("my friend");
print str; //prints Hello there my friend to stdout
Type: fn(ptr(i8),i64)
Sets up the string and adds the given string as content. This method is the one that is called by the compiler when creating built-in strings.
A null terminated C-style string.
The amount of bytes that are needed to store the full sequence of characters, but WITHOUT the null terminator. The method automatically adds 1 to the length when necessary.
To gain a better understanding of this class, it is recommended to look at the source code of the following file: