From c85ccad0a68ed9f2da523635c37b8296f7c92fd3 Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 20 Feb 2020 22:14:54 +0300 Subject: [PATCH] string: update check if a char is a space --- vlib/builtin/string.v | 10 +++++----- vlib/compiler/scanner.v | 2 +- vlib/v/scanner/scanner.v | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index a41e9fd786..c84ba6ea16 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -815,9 +815,10 @@ pub fn (a []string) to_c() voidptr { } */ - pub fn (c byte) is_space() bool { - return c in [` `, `\n`, `\t`, `\v`, `\f`, `\r`] + // 0x0085 is NEXT LINE (NEL) + // 0x00a0 is NO-BREAK SPACE + return c in [` `, `\n`, `\t`, `\v`, `\f`, `\r`, 0x85, 0xa0] } pub fn (s string) trim_space() string { @@ -1223,10 +1224,9 @@ pub fn (s string) limit(max int) string { return u.substr(0, max) } -// TODO is_white_space() +[deprecated] pub fn (c byte) is_white() bool { - i := int(c) - return i == 10 || i == 32 || i == 9 || i == 13 || c == `\r` + panic('Use `string.is_space` instead of `string.is_white') } pub fn (s string) hash() int { diff --git a/vlib/compiler/scanner.v b/vlib/compiler/scanner.v index a18462b8bb..941c0ca04c 100644 --- a/vlib/compiler/scanner.v +++ b/vlib/compiler/scanner.v @@ -264,7 +264,7 @@ fn (s mut Scanner) ident_number() string { fn (s mut Scanner) skip_whitespace() { // if s.is_vh { println('vh') return } - for s.pos < s.text.len && s.text[s.pos].is_white() { + for s.pos < s.text.len && s.text[s.pos].is_space() { if is_nl(s.text[s.pos]) && s.is_vh { return } diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index efe6dcc64b..1a87307127 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -258,7 +258,7 @@ fn (s mut Scanner) ident_number() string { fn (s mut Scanner) skip_whitespace() { // if s.is_vh { println('vh') return } - for s.pos < s.text.len && s.text[s.pos].is_white() { + for s.pos < s.text.len && s.text[s.pos].is_space() { if is_nl(s.text[s.pos]) && s.is_vh { return }