diff --git a/programs/tests/fixtures/arrays/split_delimiters_more.rock b/programs/tests/fixtures/arrays/split_delimiters_more.rock new file mode 100644 index 0000000..5886c93 --- /dev/null +++ b/programs/tests/fixtures/arrays/split_delimiters_more.rock @@ -0,0 +1,23 @@ +letters = "ABC" + +split letters into middle with "B" ( -> "A", "C" ) +say middle at 0 +say middle at 1 +say middle at 2 + +split letters into start with "A" ( -> "", "BC" ) +say start at 0 +say start at 1 +say start at 2 + +split letters into end with "C" ( -> "AB" ) ( expected "AB", "") +say end at 0 +say end at 1 +say end at 2 + +split letters into nosep with "" +say nosep at 0 +say nosep at 1 +say nosep at 2 +say nosep at 3 + diff --git a/programs/tests/fixtures/arrays/split_delimiters_more.rock.out b/programs/tests/fixtures/arrays/split_delimiters_more.rock.out new file mode 100644 index 0000000..ad4e665 --- /dev/null +++ b/programs/tests/fixtures/arrays/split_delimiters_more.rock.out @@ -0,0 +1,13 @@ +A +C +mysterious + +BC +mysterious +AB + +mysterious +A +B +C +mysterious diff --git a/rocky.jar b/rocky.jar index 88cdc5e..eb326e0 100644 Binary files a/rocky.jar and b/rocky.jar differ diff --git a/src/rockstar/statement/SplitStatement.java b/src/rockstar/statement/SplitStatement.java index 163be7f..27a53ef 100644 --- a/src/rockstar/statement/SplitStatement.java +++ b/src/rockstar/statement/SplitStatement.java @@ -57,7 +57,7 @@ private List split(String orig, String sep) { int start = 0; int len = orig.length(); - while (start < len) { + while (start < len || (start == len && !emptySep)) { int end = (emptySep ? start + 1 : orig.indexOf(sep, start)); if (end < 0) { end = len;