Skip to content

Commit bc2508d

Browse files
authored
refactor(string): change type of String::op_get to Int (#1861)
1 parent c36e392 commit bc2508d

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

builtin/builtin.mbti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl String {
540540
get(String, Int) -> Char
541541
length(String) -> Int
542542
make(Int, Char) -> String
543-
op_get(String, Int) -> Char
543+
op_get(String, Int) -> Int
544544
substring(String, start~ : Int = .., end? : Int) -> String
545545
to_string(String) -> String
546546
unsafe_char_at(String, Int) -> Char

builtin/intrinsics.mbt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,15 +1723,12 @@ pub fn String::length(self : String) -> Int = "%string_length"
17231723
pub fn String::charcode_length(self : String) -> Int = "%string_length"
17241724

17251725
///|
1726-
/// Retrieves the character at the specified index in a string. Each character in
1727-
/// the string is represented as a UTF-16 code unit.
1726+
/// Retrieves the charcode (UTF-16 code unit) at the specified index in a string.
17281727
///
17291728
/// Parameters:
17301729
///
1731-
/// * `string` : The string from which to retrieve the character.
1732-
/// * `index` : The position in the string from which to retrieve the character.
1733-
///
1734-
/// Returns the character at the specified index.
1730+
/// * `string` : The string from which to retrieve the charcode.
1731+
/// * `index` : The position in the string from which to retrieve the charcode.
17351732
///
17361733
/// Throws a runtime error if `index` is negative or greater than or equal to the
17371734
/// length of the string.
@@ -1741,8 +1738,8 @@ pub fn String::charcode_length(self : String) -> Int = "%string_length"
17411738
/// ```moonbit
17421739
/// test "String::op_get" {
17431740
/// let s = "Hello, 世界!"
1744-
/// inspect!(s[0], content="H")
1745-
/// inspect!(s[7], content="")
1741+
/// inspect!(s[0].to_char(), content="Some('H')")
1742+
/// inspect!(s[7], content="19990")
17461743
/// }
17471744
///
17481745
/// test "panic String::op_get/out_of_bounds" {
@@ -1751,7 +1748,7 @@ pub fn String::charcode_length(self : String) -> Int = "%string_length"
17511748
/// }
17521749
/// ```
17531750
///
1754-
pub fn String::op_get(self : String, idx : Int) -> Char = "%string_get"
1751+
pub fn String::op_get(self : String, idx : Int) -> Int = "%string_get"
17551752

17561753
///|
17571754
/// Retrieves the character at the specified index in a string.

0 commit comments

Comments
 (0)