mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 23:35:25 +00:00
Estimated hours taken: 0.5
Branches: main
library/string.m:
Fix a bug in string__contains_char which broke
Fergus's string quoting change, causing C compilation
errors due to ill-formed char constants in the generated
code. The C function strchr() considers the terminating
'\0' to be part of the string, so searches for '\0' were
always succeeded. In Mercury, the '\0' is just an
implementation detail, so it shouldn't be considered
to be part of the string.
Improve the efficiency of the Mercury version
of string__contains_char by not recomputing the
length of the string for each character.
tests/hard_coded/Mmakefile:
tests/hard_coded/contains_char.{m,exp}:
Test case.
23 lines
331 B
Mathematica
23 lines
331 B
Mathematica
:- module contains_char.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module char, string.
|
|
|
|
main -->
|
|
(
|
|
{ char__to_int(Nul, 0) },
|
|
{ string__contains_char("", Nul) }
|
|
->
|
|
io__write_string("test failed\n")
|
|
;
|
|
io__write_string("test succeeded\n")
|
|
).
|
|
|