Files
mercury/tests/general/string_foldr_substring.m
Peter Wang 3621cfa650 Delete deprecated substring predicates and functions.
library/string.m:
    Delete long-deprecated substring/3 function and substring/4 predicate.
    The newly introduced `string_piece' type has a substring/3 data
    constructor which takes (start, end) offsets into the base string,
    whereas the function and predicate take (start, count) arguments.
    To reduce potential confusion, delete the deprecated function and
    predicate.

    Delete other deprecated substring predicates and functions as well.

tests/general/Mercury.options:
tests/general/string_foldl_substring.exp:
tests/general/string_foldl_substring.m:
tests/general/string_foldr_substring.exp:
tests/general/string_foldr_substring.m:
tests/hard_coded/Mercury.options:
tests/hard_coded/string_substring.m:
    Delete tests for deprecated predicates.

tests/tabling/mercury_java_parser_dead_proc_elim_bug.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m:
tests/valid/mercury_java_parser_follow_code_bug.m:
    Replace calls to unsafe_substring with unsafe_between.

NEWS:
    Announce the changes.
2019-11-08 14:25:23 +11:00

57 lines
1.9 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
% string_foldr_substring.m
% Ralph Becket <rafe@cs.mu.oz.au>
% Mon Oct 28 16:32:19 EST 2002
%---------------------------------------------------------------------------%
:- module string_foldr_substring.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module char.
:- import_module int.
:- import_module list.
:- import_module string.
%---------------------------------------------------------------------------%
main(!IO) :-
io__write_strings([
"sub(\"Hello, World!\", 0, 5) = \"",
sub("Hello, World!", 0, 5),
"\"\nsub(\"Hello, World!\", 0, 50) = \"",
sub("Hello, World!", 0, 50),
"\"\nsub(\"Hello, World!\", 0, -5) = \"",
sub("Hello, World!", 0, -5),
"\"\nsub(\"Hello, World!\", -5, 12) = \"",
sub("Hello, World!", -5, 12),
"\"\nsub(\"Hello, World!\", -5, 50) = \"",
sub("Hello, World!", -5, 50),
"\"\nsub(\"Hello, World!\", 7, 0) = \"",
sub("Hello, World!", 7, 0),
"\"\nsub(\"Hello, World!\", 7, 12) = \"",
sub("Hello, World!", 7, 12),
"\"\nsub(\"Hello, World!\", 50, 10) = \"",
sub("Hello, World!", 50, 10),
"\"\n"
], !IO).
:- func sub(string, int, int) = string.
sub(S, I, N) =
from_char_list(foldr_between(func(X, Xs) = [X | Xs], S, I, N, [])).
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%