Skip to content

Commit

Permalink
fix: #19 do not smash repeated separators
Browse files Browse the repository at this point in the history
  • Loading branch information
nalgeon committed Sep 28, 2021
1 parent 752dd06 commit 68d364c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
make test suite=reverse
make test suite=split_part
make test suite=stats
make test suite=text
- name: Build for Windows
if: matrix.os == 'windows-latest'
Expand Down
2 changes: 2 additions & 0 deletions docs/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Splits `source` string on `sep` and returns the given `part` (counting from one)
```
sqlite> select split_part('one;two;three', ';', 2);
two
sqlite> select split_part('one;;three', ';', 2);
```

If `sep` is composed of multiple characters, each character is treated as separator. E.g.:
Expand Down
3 changes: 0 additions & 3 deletions src/sqlite3-text.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ static char *split_part(char *source, const char *sep, int64_t part) {
char *token;
int64_t index = 1;
while ((token = str_sep(&source, sep)) != NULL) {
if (strcmp(token, "") == 0) {
continue;
}
if (index == part) {
break;
}
Expand Down
7 changes: 7 additions & 0 deletions test/text.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.load dist/unicode
.load dist/text
select '01', split_part('one,two,three', ',', 2) = 'two';
select '02', split_part('один,два,три', ',', 3) = 'три';
select '03', split_part('one,,,four', ',', 2) = '';
select '04', split_part('one,,,four', ',', 4) = 'four';
select '05', split_part('one/two|three', '/|', 2) = 'two';

0 comments on commit 68d364c

Please sign in to comment.