From: Jean Privat Date: Fri, 27 Feb 2015 05:06:06 +0000 (+0700) Subject: string: update *trim to use `is_whitespace` X-Git-Tag: v0.7.3~41^2~3 X-Git-Url: http://nitlanguage.org string: update *trim to use `is_whitespace` Signed-off-by: Jean Privat --- diff --git a/lib/standard/string.nit b/lib/standard/string.nit index 88c4074..9724c31 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -350,12 +350,12 @@ abstract class Text # # assert " \n\thello \n\t".l_trim == "hello \n\t" # - # A whitespace is defined as any character which ascii value is less than or equal to 32 + # `Char::is_whitespace` determines what is a whitespace. fun l_trim: SELFTYPE do var iter = self.chars.iterator while iter.is_ok do - if iter.item.ascii > 32 then break + if not iter.item.is_whitespace then break iter.next end if iter.index == length then return self.empty @@ -366,12 +366,12 @@ abstract class Text # # assert " \n\thello \n\t".r_trim == " \n\thello" # - # A whitespace is defined as any character which ascii value is less than or equal to 32 + # `Char::is_whitespace` determines what is a whitespace. fun r_trim: SELFTYPE do var iter = self.chars.reverse_iterator while iter.is_ok do - if iter.item.ascii > 32 then break + if not iter.item.is_whitespace then break iter.next end if iter.index < 0 then return self.empty @@ -379,10 +379,11 @@ abstract class Text end # Trims trailing and preceding white spaces - # A whitespace is defined as any character which ascii value is less than or equal to 32 # # assert " Hello World ! ".trim == "Hello World !" # assert "\na\nb\tc\t".trim == "a\nb\tc" + # + # `Char::is_whitespace` determines what is a whitespace. fun trim: SELFTYPE do return (self.l_trim).r_trim # Returns `self` removed from its last line terminator (if any).