mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
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.
19 lines
249 B
Plaintext
19 lines
249 B
Plaintext
|
|
!
|
|
hello:world:how:are:you!
|
|
hello<tab>world<tab>how<tab>are<tab><tab>you!
|
|
user<tab>group<tab>id1<tab>id2
|
|
x<tab>ay<tab>az
|
|
x<tab>a <tab>aax <tab> x
|
|
col1<tab>col2:val2<tab>col3<tab>
|
|
|
|
"line1"
|
|
"line2"
|
|
"line3"
|
|
"line4"
|
|
|
|
"line1"
|
|
"line2"
|
|
"line3"
|
|
"line4nonl"
|