Files
mercury/tests/hard_coded/string_count_codepoints_ilseq.m
Peter Wang 250b5bcc2e Define behaviour of string.count_codepoints with ill-formed sequences.
library/string.m:
    Make each code unit in an ill-formed sequence contribute one
    to the value of string.count_codepoints.

tests/hard_coded/Mmakefile:
tests/hard_coded/string_count_codepoints_ilseq.exp:
tests/hard_coded/string_count_codepoints_ilseq.exp2:
tests/hard_coded/string_count_codepoints_ilseq.m:
    Add test case.
2019-10-24 09:14:46 +11:00

36 lines
1019 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% The .exp file is for backends using UTF-8 string encoding.
% The .exp2 file is for backends using UTF-16 string encoding.
%
%---------------------------------------------------------------------------%
:- module string_count_codepoints_ilseq.
:- 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) :-
S0 = "😀",
S1 = string.between(S0, 0, 1),
S2 = string.between(S0, 1, count_code_units(S0)),
S = S0 ++ S1 ++ "," ++ S2 ++ S0,
string.count_codepoints(S, Num),
io.write_int(Num, !IO),
io.nl(!IO).