From 78b8dc807767b89fcc7234f270610fd2a6c1a2d9 Mon Sep 17 00:00:00 2001 From: yoshi~ Date: Tue, 3 Dec 2024 16:34:57 +0100 Subject: optimise drop_start --- src/gleam/string.gleam | 10 +++++++--- 1 file 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 + } } } -- cgit v1.2.3