diff --git a/std/string/ascii.wave b/std/string/ascii.wave index 79bba315..2118e35b 100644 --- a/std/string/ascii.wave +++ b/std/string/ascii.wave @@ -77,6 +77,10 @@ pub fun is_space(c: u8) -> bool { return true; } + if (c == 11 || c == 12) { + return true; + } + if (c == 13) { return true; } diff --git a/std/string/trim.wave b/std/string/trim.wave index a157f0b1..19f3a58c 100644 --- a/std/string/trim.wave +++ b/std/string/trim.wave @@ -16,13 +16,15 @@ // // SPDX-License-Identifier: Apache-2.0 +import("std::string::ascii")::{is_space}; + pub fun trim_left_index(s: str) -> i32 { var i: i32 = 0; while (s[i] != 0) { var c: u8 = s[i]; - if (c == 32 || c == 9 || c == 10 || c == 13) { + if (is_space(c)) { i += 1; } else { return i; @@ -48,7 +50,7 @@ pub fun trim_right_index(s: str) -> i32 { while (i >= 0) { var c: u8 = s[i]; - if (c == 32 || c == 9 || c == 10 || c == 13) { + if (is_space(c)) { i -= 1; } else { return i + 1; diff --git a/tests/cases/shared/test81.wave b/tests/cases/shared/test81.wave index 7d906f34..622be054 100644 --- a/tests/cases/shared/test81.wave +++ b/tests/cases/shared/test81.wave @@ -29,9 +29,11 @@ fun main() -> i32 { if (!starts_with("wave-lang", "wave") || !ends_with("main.wave", ".wave")) { failed += 1; } if (find_char("banana", 97) != 1 || rfind_char("banana", 97) != 5) { failed += 1; } if (!contains_char("wave", 118) || count_char("banana", 97) != 3) { failed += 1; } - if (!is_alpha(87) || !is_digit(55) || !is_space(10)) { failed += 1; } + if (!is_alpha(87) || !is_digit(55)) { failed += 1; } + if (!is_space(9) || !is_space(10) || !is_space(11) || !is_space(12) || !is_space(13) || !is_space(32) || is_space(8)) { failed += 1; } if (to_lower(87) != 119 || to_upper(119) != 87) { failed += 1; } if (trim_left_index(" wave \n") != 2 || trim_right_index(" wave \n") != 6) { failed += 1; } + if (trim_left_index("\x0b\x0cwave") != 2 || trim_right_index("wave\x0b\x0c") != 4) { failed += 1; } if (djb2_32("wave") == 0 || fnv1a_64("wave") == 0) { failed += 1; } return failed;