From 593eeae98d21da64d0e6a956413d3874fe762369 Mon Sep 17 00:00:00 2001 From: Robert Attard Date: Thu, 8 Apr 2021 14:38:23 -0400 Subject: rename string.drop_before to string.crop; use erl_contains instead of split_once and then concat --- src/gleam/string.gleam | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index 1bec6a5..8bef422 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -171,14 +171,14 @@ pub fn slice(from string: String, at_index idx: Int, length len: Int) -> String /// If the first string does not contain the second string, the first string is returned. /// /// ## Examples -/// > drop_before(from: "The Lone Gunmen", before: "Lone") +/// > crop(from: "The Lone Gunmen", before: "Lone") /// "Lone Gunmen" /// -pub fn drop_before(from string: String, before substring: String) -> String { - case split_once(string, substring) { - Ok(tuple(_, rest)) -> concat([substring, rest]) - Error(Nil) -> string - } +pub fn crop(from string: String, before substring: String) -> String { + string + |> erl_contains(substring) + |> dynamic.string() + |> result.unwrap(string) } /// Drops *n* Graphemes from the left side of a string. -- cgit v1.2.3