From 190a7d667e4b99f8b3c11ef991ce1eb879aa5c9c Mon Sep 17 00:00:00 2001 From: Erik Terpstra <39518+eterps@users.noreply.github.com> Date: Tue, 12 May 2020 13:01:25 +0200 Subject: string.trim_left & string.trim_right --- src/gleam/string.gleam | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index 1dd484a..2cad6f2 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -311,6 +311,8 @@ pub fn join(strings: List(String), with separator: String) -> String { // pub fn pad_right(string: String, to size: Int, with: String) {} type Direction { + Leading + Trailing Both } @@ -328,24 +330,28 @@ pub fn trim(string: String) -> String { erl_trim(string, Both) } -// TODO -// Get rid of whitespace on the left of a String. -// -// ## Examples -// > trim_left(" hats \n") -// "hats \n" -// -// -// pub fn trim_left(string: String) -> String {} -// TODO -// Get rid of whitespace on the right of a String. -// -// ## Examples -// > trim_right(" hats \n") -// " hats" -// -// -// pub fn trim_right(string: String) -> String {} +/// Get rid of whitespace on the left of a String. +/// +/// ## Examples +/// > trim_left(" hats \n") +/// "hats \n" +/// +/// +pub fn trim_left(string: String) -> String { + erl_trim(string, Leading) +} + +/// Get rid of whitespace on the right of a String. +/// +/// ## Examples +/// > trim_right(" hats \n") +/// " hats" +/// +/// +pub fn trim_right(string: String) -> String { + erl_trim(string, Trailing) +} + // TODO // /// Convert a string to a list of Graphemes. // /// -- cgit v1.2.3