diff options
author | yoshi~ <jreusch4@gmail.com> | 2024-12-03 16:34:57 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-12-03 15:57:24 +0000 |
commit | 78b8dc807767b89fcc7234f270610fd2a6c1a2d9 (patch) | |
tree | 33c9d3f3279caba2ed08bb5eb24299685c984e57 | |
parent | 2f3b2bbaf925c432f0fc128336c4e62b7c9d34a9 (diff) | |
download | gleam_stdlib-78b8dc807767b89fcc7234f270610fd2a6c1a2d9.tar.gz gleam_stdlib-78b8dc807767b89fcc7234f270610fd2a6c1a2d9.zip |
optimise drop_start
-rw-r--r-- | src/gleam/string.gleam | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index 8f6b5cb..00d58ad 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -246,9 +246,13 @@ pub fn drop_left(from string: String, up_to num_graphemes: Int) -> String { /// ``` /// pub fn drop_start(from string: String, up_to num_graphemes: Int) -> String { - case num_graphemes < 0 { - True -> string - False -> slice(string, num_graphemes, length(string) - num_graphemes) + case num_graphemes > 0 { + False -> string + True -> + case pop_grapheme(string) { + Ok(#(_, string)) -> drop_start(string, num_graphemes - 1) + Error(Nil) -> string + } } } |