aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2024-10-10 13:21:56 +0200
committerLouis Pilfold <louis@lpil.uk>2024-10-10 15:06:25 +0100
commit8705790acf5c70a15b0e86a0169de32b12e1d3e9 (patch)
tree3e0c06fdedbb67992913dc73f7f11caea333c759
parent6c213dd3127a87121db439bbf5bf8a6185b73f4c (diff)
downloadgleam_stdlib-8705790acf5c70a15b0e86a0169de32b12e1d3e9.tar.gz
gleam_stdlib-8705790acf5c70a15b0e86a0169de32b12e1d3e9.zip
refactor string
-rw-r--r--src/gleam/string.gleam33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam
index caaf6dd..0f073b9 100644
--- a/src/gleam/string.gleam
+++ b/src/gleam/string.gleam
@@ -364,15 +364,18 @@ pub fn split(x: String, on substring: String) -> List(String) {
/// ```
///
pub fn split_once(
- x: String,
+ string: String,
on substring: String,
) -> Result(#(String, String), Nil) {
- do_split_once(x, substring)
+ do_split_once(string, substring)
}
@external(javascript, "../gleam_stdlib.mjs", "split_once")
-fn do_split_once(x: String, substring: String) -> Result(#(String, String), Nil) {
- case erl_split(x, substring) {
+fn do_split_once(
+ string: String,
+ substring: String,
+) -> Result(#(String, String), Nil) {
+ case erl_split(string, substring) {
[first, rest] -> Ok(#(first, rest))
_ -> Error(Nil)
}
@@ -710,7 +713,7 @@ fn do_to_utf_codepoints(string: String) -> List(UtfCodepoint) {
@target(javascript)
@external(javascript, "../gleam_stdlib.mjs", "string_to_codepoint_integer_list")
-fn string_to_codepoint_integer_list(a: String) -> List(Int)
+fn string_to_codepoint_integer_list(string: String) -> List(Int)
/// Converts a `List` of `UtfCodepoint`s to a `String`.
///
@@ -778,10 +781,10 @@ fn do_utf_codepoint_to_int(cp cp: UtfCodepoint) -> Int
/// // -> Some("hats")
/// ```
///
-pub fn to_option(s: String) -> Option(String) {
- case s {
+pub fn to_option(string: String) -> Option(String) {
+ case string {
"" -> None
- _ -> Some(s)
+ _ -> Some(string)
}
}
@@ -801,8 +804,8 @@ pub fn to_option(s: String) -> Option(String) {
/// // -> Ok("i")
/// ```
///
-pub fn first(s: String) -> Result(String, Nil) {
- case pop_grapheme(s) {
+pub fn first(string: String) -> Result(String, Nil) {
+ case pop_grapheme(string) {
Ok(#(first, _)) -> Ok(first)
Error(e) -> Error(e)
}
@@ -824,8 +827,8 @@ pub fn first(s: String) -> Result(String, Nil) {
/// // -> Ok("m")
/// ```
///
-pub fn last(s: String) -> Result(String, Nil) {
- case pop_grapheme(s) {
+pub fn last(string: String) -> Result(String, Nil) {
+ case pop_grapheme(string) {
Ok(#(first, "")) -> Ok(first)
Ok(#(_, rest)) -> Ok(slice(rest, -1, 1))
Error(e) -> Error(e)
@@ -842,8 +845,8 @@ pub fn last(s: String) -> Result(String, Nil) {
/// // -> "Mamouna"
/// ```
///
-pub fn capitalise(s: String) -> String {
- case pop_grapheme(s) {
+pub fn capitalise(string: String) -> String {
+ case pop_grapheme(string) {
Ok(#(first, rest)) -> append(to: uppercase(first), suffix: lowercase(rest))
_ -> ""
}
@@ -858,7 +861,7 @@ pub fn inspect(term: anything) -> String {
@external(erlang, "gleam_stdlib", "inspect")
@external(javascript, "../gleam_stdlib.mjs", "inspect")
-fn do_inspect(term term: anything) -> StringBuilder
+fn do_inspect(term: anything) -> StringBuilder
/// Returns the number of bytes in a `String`.
///