mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
Estimated hours taken: 0.5 Branches: main. Move the string builder stream from extras to the standard library. library/string.builder.m: Move stream_util.string_builder to string.builder. Use builtin.copy instead of unsafe_promise_unique in the implementation of put/4 for the string builder stream. library/string.m: Include string.builder. tests/hard_coded/Mmakefile: tests/hard_coded/string_builder_test.exp: tests/hard_coded/string_builder_test.m: Add a test case. extras/Mmakefile: extras/README: extras/stream/Mmakefile: extras/stream/README: extras/stream/impure.m: extras/stream/lowlevel.m: extras/stream/stream_old.m: extras/stream/stream_util.m: extras/stream/stream_util.string_builder.m: extras/stream/tests/Makefile: extras/stream/tests/stream_util_test.exp: extras/stream/tests/stream_util_test.m: Completely remove the streams modules from extras. These modules are all deprecated now.
41 lines
1.2 KiB
Mathematica
41 lines
1.2 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
:- module string_builder_test.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list.
|
|
:- import_module pprint.
|
|
:- import_module stream.
|
|
:- import_module stream.string_writer.
|
|
:- import_module string.
|
|
:- import_module string.builder.
|
|
:- import_module term_to_xml.
|
|
|
|
main(!IO) :-
|
|
some [!State] (
|
|
!:State = string.builder.init,
|
|
Stream = string.builder.handle,
|
|
put(Stream, "Hello", !State),
|
|
put(Stream, ',', !State),
|
|
put(Stream, " world!", !State),
|
|
put(Stream, "\n", !State),
|
|
write_xml_doc_general(Stream, [1, 2, 3],
|
|
simple, no_stylesheet, no_dtd, _, !State),
|
|
put(Stream, "\n", !State),
|
|
pprint.write(Stream, 0, to_doc([4, 5, 6]),
|
|
!State),
|
|
put(Stream, "\n", !State),
|
|
string_writer.format(Stream, "%.2f", [f(3.14)], !State),
|
|
put(Stream, "\n", !State),
|
|
String = string.builder.to_string(!.State),
|
|
io.write_string(String, !IO)
|
|
).
|