[phobos] substring for std.metastrings

Igor Lesik curoles at yahoo.com
Sun Feb 28 13:44:14 PST 2010


Hi Philippe,

thanks for the remarks

>1- I guess that  when t is the empty string you should return true, not false: the empty string is present in any string.
That is true, empty string is present in any string. But usually when I look for an empty substring it happens by mistake. On other hand, returning true is probably what most people would expect, so I tend to agree with you.

>2- the .found necessary to get the result could be hidden with a two-levels template:
>auto s = substring!("fun with gun", "run");
I try to comply to the style of std.metastrigns, they do not do it there.
And when I see "auto s = substring!("fun with gun", "run");" I presume s is substring, not
boolean.

>3- Maybe you could do a (string s, char c) version which casts the char into a string and look for it.
Agree.

I would like to hear if people think that substring deserves to be in std.metastrings. Otherwise all this discussion is pointless.

Thanks,
Igor


 

________________________________
From: Philippe Sigaud <philippe.sigaud at gmail.com>
To: Discuss the phobos library for D <phobos at puremagic.com>
Sent: Sun, February 28, 2010 9:59:50 AM
Subject: Re: [phobos] substring for std.metastrings

(hmm, first time post there. Hello, I'm mostly human and mostly harmless).

On Fri, Feb 26, 2010 at 11:45, Igor Lesik <curoles at yahoo.com> wrote:

I believe, I have a function that is good candidate to be in std.metastrings.
>Feedback is appreciated.
>
>

Hi Igor,

Some remarks:

1- I guess that  when t is the empty string you should return true, not false: the empty string is present in any string. So your first static if should be cut in two.

2- the .found necessary to get the result could be hidden with a two-levels template:

template substring(string s, string t)
{
    enum bool substring = substringImpl!(s,t).found;
}

and rename your substring into substringImpl. Then you can do:

auto s = substring!("fun with gun", "run");

I don't know if you can put substringImpl as a private template inside substring?

3- Maybe you could do a (string s, char c) version which casts the char into a string and look for it.


Philippe


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100228/307548c1/attachment.htm>


More information about the phobos mailing list