Skip to content

Commit

Permalink
Fixed #60
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborsch committed Jun 28, 2024
1 parent ceebd12 commit 6cb7fb1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
23 changes: 23 additions & 0 deletions programs/tests/fixtures/arrays/split_delimiters_more.rock
Original file line number Diff line number Diff line change
@@ -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

13 changes: 13 additions & 0 deletions programs/tests/fixtures/arrays/split_delimiters_more.rock.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
A
C
mysterious

BC
mysterious
AB

mysterious
A
B
C
mysterious
Binary file modified rocky.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/rockstar/statement/SplitStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private List<String> 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;
Expand Down

0 comments on commit 6cb7fb1

Please sign in to comment.