Skip to content

Commit

Permalink
addring.byte_at and string.rune_at
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Nov 23, 2023
1 parent ff070fb commit 72abe6e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/core/src/string.c.ri
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ public struct string < Stringable, Hashable, Throwable {
return unsafe { self.ptr[idx] };
}
public func byte_at(self, idx: uint) -> ?uint8 {
if idx >= self.len {
return none;
}
return unsafe { self.ptr[idx] };
}
public func rune_at(self, idx: uint) -> ?rune {
runes := self.as_runes();
if idx >= runes.len {
return none;
}
return runes[idx];
}
#[inline]
public func repeat(self, count: uint) -> Self {
return if count == 0 {
Expand Down Expand Up @@ -505,7 +520,7 @@ public struct string < Stringable, Hashable, Throwable {
};
}

/// Returns an array of all the UTF8 runes in the string `self` which is useful
/// Returns an array of all the UTF-8 runes in the string `self` which is useful
/// if you want random access to them.
public func as_runes(self) -> []rune {
mut runes := @vec(rune, self.runes_count());
Expand Down

0 comments on commit 72abe6e

Please sign in to comment.