Adam D. Ruppe wrote: > On Friday, 21 June 2013 at 22:35:55 UTC, Andrei Alexandrescu > wrote: >> Post it and I'll destroy it. > > > inout(char)* mystrstr(inout(char)* haystack, const(char*) needle) > { > assert(haystack !is null); > > if(needle is null) > return haystack; > > const(char)* where = needle; > inout(char)* gotit; > > while(*haystack) { > if(*haystack == *where) { > if(gotit is null) > gotit = haystack; // store where the match started > where++; > haystack++; > if(*where == 0) > return gotit; > } else { > // if we were in the middle of a match, we'll want to > // check the current character again so only advance > if > // we're at the beginning > if(gotit is null) > haystack++; > else { > // partial match, but not complete so no good > // start over, including the current *haystack > where = needle; > gotit = null; > } > } > } > > return null; > } > I haven't tried running it, but this looks to me like it won't find "ababc" in "abababc"...
Jerome -- mailto:jeber...@free.fr http://jeberger.free.fr Jabber: jeber...@jabber.fr
signature.asc
Description: OpenPGP digital signature