diff options
-rw-r--r-- | lib.c | 16 | ||||
-rw-r--r-- | txr.1 | 9 |
2 files changed, 18 insertions, 7 deletions
@@ -3916,11 +3916,19 @@ val trim_str(val str) const wchar_t *start = c_str(str); const wchar_t *end = start + c_num(length_str(str)); - while (start[0] && iswspace(start[0])) - start++; + if (opt_compat && opt_compat <= 148) { + while (start[0] && iswspace(start[0])) + start++; - while (end > start && iswspace(end[-1])) - end--; + while (end > start && iswspace(end[-1])) + end--; + } else { + while (start[0] && wcschr(L" \t\n", start[0])) + start++; + + while (end > start && wcschr(L" \t\n", end[-1])) + end--; + } if (end == start) { return null_string; @@ -18632,8 +18632,7 @@ The function produces a copy of .meta string from which leading and -trailing whitespace is removed. Whitespace consists of spaces, tabs, -carriage returns, linefeeds, vertical tabs and form feeds. +trailing tabs, spaces and newlines are removed. .coNP Function @ chrp .synb @@ -44798,7 +44797,11 @@ were executed in derived-to-base order, opposite to the order of execution of .code :init handlers. Specifying 148 or earlier compatibility provides this -old behavior. +old behavior. Also, until version 148, the +.code trim-str +function stripped leading and trailing whitespace from a string +consisting of not only spaces, tabs and newlines, but also carriage +returns, vertical tabs and form feeds. .IP 145 In versions 144 and 145, \*(TX opened files in text mode on Cygwin, enabling conversion between CR-LF line endings and abstract newline |