From e6011e83cec6be9c84cfbee305e7d13ff077d122 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 11 May 2021 13:59:44 +0300 Subject: [PATCH] builtin: cleanup string.v --- vlib/builtin/string.v | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index d3520c48f8..f638b5bef2 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -243,7 +243,7 @@ fn (a string) clone_static() string { // clone returns a copy of the V string `a`. pub fn (a string) clone() string { - if a == '' { + if a.len == 0 { // TODO perf? an extra check in each clone() is not nice. return '' } @@ -1733,7 +1733,8 @@ pub fn (s string) repeat(count int) string { } // fields returns a string array of the string split by `\t` and ` ` -// Example: assert '\t\tv = v'.fields() == ['', '', 'v', '=', 'v'] +// Example: assert '\t\tv = v'.fields() == ['v', '=', 'v'] +// Example: assert ' sss ssss'.fields() == ['sss', 'ssss'] pub fn (s string) fields() []string { mut res := []string{} mut word_start := 0 @@ -1827,11 +1828,3 @@ pub fn (s string) strip_margin_custom(del byte) string { return ret.vstring_with_len(count) } } - -// split_by_whitespace - extract only the non whitespace tokens/words from the given string `s`. -// example: ' sss ssss'.split_by_whitespace() => ['sss', 'ssss'] - -[deprecated: 'use string.fields() instead'] -pub fn (s string) split_by_whitespace() []string { - return s.fields() -}