[phobos] substring for std.metastrings

Andrei Alexandrescu andrei at erdani.com
Thu Mar 4 05:57:48 PST 2010


What does substring do?

Andrei

Philippe Sigaud wrote:
> (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 
> <mailto: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
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list