%---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% % % Test string prefix- and suffix-related predicates. % :- module string_presuffix. :- interface. :- import_module io. :- pred main(io::di, io::uo) is det. %---------------------------------------------------------------------------% %---------------------------------------------------------------------------% :- implementation. :- import_module int. :- import_module list. :- import_module solutions. :- import_module string. %---------------------------------------------------------------------------% main(!IO) :- Str = "aĆŸĪ¾å••š€€.", io.write_string("prefix(in, in):\n", !IO), ( if string.prefix(Str, ""), string.prefix(Str, "a"), string.prefix(Str, "aß"), string.prefix(Str, "aßξ"), string.prefix(Str, "aĆŸĪ¾å••"), string.prefix(Str, "aĆŸĪ¾å••š€€"), string.prefix(Str, "aĆŸĪ¾å••š€€."), not string.prefix(Str, "aĆŸĪ¾å••š€€.z") then io.write_string("pass\n", !IO) else io.write_string("fail\n", !IO) ), io.write_string("\nsuffix(in, in):\n", !IO), ( if not string.suffix(Str, "aĆŸĪ¾å••š€€.z"), string.suffix(Str, "aĆŸĪ¾å••š€€."), string.suffix(Str, "ĆŸĪ¾å••š€€."), string.suffix(Str, "ξ啕𐀀."), string.suffix(Str, "啕𐀀."), string.suffix(Str, "𐀀."), string.suffix(Str, "."), string.suffix(Str, "") then io.write_string("pass\n", !IO) else io.write_string("fail\n", !IO) ), io.write_string("\nremove_prefix:\n", !IO), ( if string.remove_prefix(Str, Str, ""), string.remove_prefix("aßξ", Str, "啕𐀀."), not string.remove_prefix("☿", Str, Str) then io.write_string("pass\n", !IO) else io.write_string("fail\n", !IO) ), io.write_string("\nremove_suffix:\n", !IO), ( if string.remove_suffix(Str, Str, ""), string.remove_suffix(Str, "啕𐀀.", "aßξ"), not string.remove_suffix(Str, "☿", Str) then io.write_string("pass\n", !IO) else io.write_string("fail\n", !IO) ).