library/io.m:
Add two new predicates.
The new predicate read_named_file_as_string reads in a named file,
and returns its contents as a single giant string. This is effectively
a combination of open_input, read_file_as_string, and close_input.
The new predicate read_named_file_as_lines reads in a named file,
and returns its contents as a list of strings, each containing
the contents one line (minus the newline char at the end, if any).
This is effectively a combination of open_input, read_file_as_string,
split_into_lines (see below), and close_input.
library/string.m:
Add a new function, split_into_lines, which breaks up a string into
its constituent lines, returning each line minus its newline.
This differs from the old split_at_char('\n', ...) in that it
expects the input string to end with a newline, and does not return
an empty string after a final newline. (If there *are* characters
after the final newline, it does return *them* as the final line.)
NEWS:
Announce the new predicates and function.
compiler/source_file_map.m:
Use the new functionality to simplify the code that reads in
Mercury.modules files.
tests/hard_coded/string_split.{m,exp}:
Add tests for split_into_lines.
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.
Estimated hours taken: 3
Branches: main
A few handy functions for splitting a string added.
library/string.m:
Added remove_suffix_if_present, split_at_separator, split_at_char,
split_at_string
tests/hard_coded/string_split.m:
A simple test of split_at_* functions.
tests/hard_coded/string_split.exp:
Expected results of the tests of split_at_* functions.
tests/hard_coded/string_various.m:
Created. Added testcase for remove_suffix_if_present.
tests/hard_coded/string_various.exp:
Created. Added results for remove_suffix_if_present.
NEWS:
Added a comment that the functions have been added.