summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-11-17 07:13:18 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-11-17 07:13:18 -0800
commit34d7df624c34f7b909da7db08dbcbf7d05de84af (patch)
treeb2ccc1a44a565b9c6db6ea3186c5648a2d356216 /lib.c
parent290d470eb4c96f12b78667d286d2a11c49d2a619 (diff)
downloadtxr-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.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 62d43b67..796a126c 100644
--- a/lib.c
+++ b/lib.c
@@ -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);