endsWith: wrong function call, no error
Dicebot
public at dicebot.lv
Mon Oct 21 08:19:33 PDT 2013
On Monday, 21 October 2013 at 15:12:36 UTC, Chris wrote:
> The following code compiles:
>
> import std.stdio;
>
> void main() {
>
> auto text = "Hello world!";
> if (!std.algorithm.endsWith(text, "!" ".")) {
> writeln("No punctuation!");
> } else {
> writeln("Has punctuation");
> }
> }
>
> The bug is in line 6 a missing comma between "!" and ".":
>
> !std.algorithm.endsWith(text, "!" ".")
>
> If you insert the comma, it will behave as expected.
>
> Is this ok or a bug?
It C-compatible behavior, two string literal separated with only
spaces are concatenated into one. So your code was essentially
`endsWith(text, "!.")`
More information about the Digitalmars-d
mailing list