Skip to content

Commit 12666f2

Browse files
Yu-zhpeter-jerry-ye
authored andcommitted
doc(string): add doc for String::char_at
1 parent 2569b36 commit 12666f2

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

string/string.mbt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,14 @@ pub fn String::offset_of_nth_char(
391391
}
392392

393393
///|
394-
/// Returns the Unicode character at the given index.
395-
pub fn String::char_at(self : String, index : Int) -> Char {
396-
guard index >= 0 && index < self.length() else {
397-
abort("index out of bounds")
394+
/// Returns the Unicode character at the given offset.
395+
///
396+
/// This has O(1) complexity.
397+
pub fn String::char_at(self : String, offset : Int) -> Char {
398+
guard offset >= 0 && offset < self.length() else {
399+
abort("offset out of bounds")
398400
}
399-
self.unsafe_char_at(index)
401+
self.unsafe_char_at(offset)
400402
}
401403

402404
///|

0 commit comments

Comments
 (0)