diff options
Diffstat (limited to 'std/prelude/strings.pk')
-rw-r--r-- | std/prelude/strings.pk | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/std/prelude/strings.pk b/std/prelude/strings.pk index a8c72fb..5c71047 100644 --- a/std/prelude/strings.pk +++ b/std/prelude/strings.pk @@ -22,7 +22,7 @@ pub func len(self: lent str): uint = res ## Pushes a character to the end of a mutable string. -pub func push(self: mut str, val: chr) = +pub func push(self: mut str, val: char) = self.data.push(val.byte) # todo: obsolete by from/to conversion?? ## Pushes an owned string to the end of a mutable string. @@ -34,29 +34,29 @@ pub func push(self: mut str, val: str) = ## SAFETY: We return early upon an empty string. ## And decrement by one char for a non-empty string. @[safe] -pub func pop(self: mut str): chr? = +pub func pop(self: mut str): char? = let char = self.chars.rev.next? self.data.set_len(self.len - char.len) # this is normally unsafe. Some(char) ## Returns the character at the provided index, if it exists. -pub func get(self: str, i: uint): chr? = +pub func get(self: str, i: uint): char? = ... ## Sets the character at the provided index, if it exists. ## As strings are packed, this may call str.grow and reallocate. ## oh fuck we have to insert + remove anyway -pub func set(self: mut str, i: uint, val: chr) = +pub func set(self: mut str, i: uint, val: char) = ... ## Inserts a character at an arbitrary position within a string. ## Panics on failure. (todo: can we do better?) -pub func insert(self: mut str, i: uint, val: chr) = +pub func insert(self: mut str, i: uint, val: char) = ... ## Removes and returns a character at an arbitrary position within a string. ## Panics on failure. (todo: can we do better?) -pub func remove(self: mut str, i: uint): chr = +pub func remove(self: mut str, i: uint): char? = ... ## Syntactic sugar for string appending. @@ -70,9 +70,9 @@ pub func &(a: str, b: str): str = ## Conversion from a string to a list of bytes. Zero-cost. pub func to(self: str): list[byte] = self.data -## Conversion from a str to a list[chr]. Reallocates. -pub func to(self: str): list[chr] = - var res: list[chr] +## Conversion from a str to a list[char]. Reallocates. +pub func to(self: str): list[char] = + var res: list[char] for char in self do res.push(char) res ## Conversion from a char to an array of bytes. Zero-cost. |