diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-11-17 07:13:18 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-11-17 07:13:18 -0800 |
commit | 34d7df624c34f7b909da7db08dbcbf7d05de84af (patch) | |
tree | b2ccc1a44a565b9c6db6ea3186c5648a2d356216 /lib.c | |
parent | 290d470eb4c96f12b78667d286d2a11c49d2a619 (diff) | |
download | txr-34d7df624c34f7b909da7db08dbcbf7d05de84af.tar.gz txr-34d7df624c34f7b909da7db08dbcbf7d05de84af.tar.bz2 txr-34d7df624c34f7b909da7db08dbcbf7d05de84af.zip |
* lib.c (split_str): If the separator string is empty,
then unless opt_compat is 100 or less, provide a more
consistent behavior, rather than splitting the string
into characters. This latter behavior was never documented.
* txr.1: Documented.
* dep.mk: Updated.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -57,6 +57,7 @@ #include "eval.h" #include "sysif.h" #include "regex.h" +#include "txr.h" #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) @@ -2778,7 +2779,29 @@ val split_str(val str, val sep) size_t len_sep = c_num(length_str(sep)); if (len_sep == 0) { - return list_str(str); + if (opt_compat && opt_compat <= 100) { + return list_str(str); + } else { + const wchar_t *cstr = c_str(str); + + if (*cstr) { + list_collect_decl (out, iter); + + prot1(&str); + + for (; *cstr; cstr++) { + val piece = mkustring(one); + init_str(piece, cstr); + iter = list_collect(iter, piece); + } + + rel1(&str); + + return out; + } else { + return cons(str, nil); + } + } } else { const wchar_t *cstr = c_str(str); const wchar_t *csep = c_str(sep); |