1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 17:27:18 +00:00

Address #174 - fix string/trim

This commit is contained in:
Calvin Rose 2019-11-08 08:47:37 -06:00
parent c5010dffb4
commit 9b605b27bd
2 changed files with 5 additions and 0 deletions

View File

@ -500,6 +500,8 @@ static Janet cfun_string_trim(int32_t argc, Janet *argv) {
trim_help_args(argc, argv, &str, &set);
int32_t left_edge = trim_help_leftedge(str, set);
int32_t right_edge = trim_help_rightedge(str, set);
if (right_edge < left_edge)
return janet_stringv(NULL, 0);
return janet_stringv(str.bytes + left_edge, right_edge - left_edge);
}

View File

@ -190,4 +190,7 @@
(assert-error "with-vars 2" (with-vars [abc 456] (error :oops)))
(assert (= abc 123) "with-vars 3")
# Trim empty string
(assert (= "" (string/trim " ")) "string/trim regression")
(end-suite)