mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 01:43:35 +00:00
Estimated hours taken: 1 Branches: main library/string.m: Fix an off-by-one bug in string.split_at_separator. The index in the initial call to split_at_separator2 was one past the end of the string, which worked in the C backends because strings are NUL terminated. Rename split_at_separator2 to split_at_separator_2 and make it more readable. tests/hard_coded/string_split.exp: tests/hard_coded/string_split.m: Add a couple of cases which seem more likely to fail with an incorrect implementation.
45 lines
1.1 KiB
Mathematica
45 lines
1.1 KiB
Mathematica
:- module string_split.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module string, char.
|
|
|
|
main(!IO) :-
|
|
io__write_list(
|
|
split_at_separator(char__is_upper, ""),
|
|
":", io__write_string, !IO),
|
|
io__nl(!IO),
|
|
io__write_list(
|
|
split_at_separator(char__is_upper, "!"),
|
|
":", io__write_string, !IO),
|
|
io__nl(!IO),
|
|
io__write_list(
|
|
split_at_separator(char__is_upper, "helloXworldXhowXareYyou!"),
|
|
":", io__write_string, !IO),
|
|
io__nl(!IO),
|
|
io__write_list(
|
|
split_at_separator(char__is_whitespace, "hello world\thow are\t\tyou!"),
|
|
"<tab>", io__write_string, !IO),
|
|
io__nl(!IO),
|
|
io__write_list(
|
|
split_at_char(':', "user:group:id1:id2"),
|
|
"<tab>", io__write_string, !IO),
|
|
io__nl(!IO),
|
|
io__write_list(
|
|
split_at_string("aa", "xaaayaaaz"),
|
|
"<tab>", io__write_string, !IO),
|
|
io__nl(!IO),
|
|
io__write_list(
|
|
split_at_string("aaa", "xaaaa aaaaax aaa x"),
|
|
"<tab>", io__write_string, !IO),
|
|
io__nl(!IO),
|
|
io__write_list(
|
|
split_at_string(":::", "col1:::col2:val2:::col3:::"),
|
|
"<tab>", io__write_string, !IO),
|
|
io__nl(!IO),
|
|
true.
|