mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 01:43:35 +00:00
library/string.m:
Make string.index_next and string.unsafe_index_next
return either U+FFFD or an unpaired surrogate code point
when an ill-formed code unit sequence is detected.
tests/hard_coded/Mmakefile:
tests/hard_coded/string_index_next_ilseq.exp:
tests/hard_coded/string_index_next_ilseq.exp2:
tests/hard_coded/string_index_next_ilseq.m:
Add test case.
45 lines
1.3 KiB
Mathematica
45 lines
1.3 KiB
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_index_next_ilseq.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module char.
|
|
:- import_module list.
|
|
:- import_module string.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
S0 = "😀",
|
|
S1 = string.between(S0, 0, 1),
|
|
S2 = string.between(S0, 1, 2),
|
|
S = S0 ++ S2 ++ S1 ++ S0,
|
|
test_index_next(S, 0, !IO).
|
|
|
|
:- pred test_index_next(string::in, int::in, io::di, io::uo) is det.
|
|
|
|
test_index_next(S, Index, !IO) :-
|
|
( if string.index_next(S, Index, NextIndex, Char) then
|
|
io.format("string.index_next(S, %d, %d, %#x)\n",
|
|
[i(Index), i(NextIndex), i(char.to_int(Char))], !IO),
|
|
test_index_next(S, NextIndex, !IO)
|
|
else
|
|
io.format("string.index_next(S, %d, _, _) failed\n",
|
|
[i(Index)], !IO)
|
|
).
|