std.algorithm.startsWith with maximal matching

H. S. Teoh hsteoh at
Sun Jan 15 11:23:04 PST 2012

On Sat, Jan 14, 2012 at 07:53:10PM -0800, Jonathan M Davis wrote:
> Actually, if the word has to match exactly, then startsWith isn't
> going to cut it. What you need to do is outright strip the punctuation
> from both ends.  You'd need something more like
> word = find!(not!(std.uni.isPunctuation))(word);
> word = array(until!(std.uni.isPunctuation)(word));
> if(canFind(wordList, word))
> {
>     //...
> }

Thanks for the info, but this method has the flaw that the original
punctuation is lost, unless I work with a copy of the word. I was hoping
for a nice way to do matching in-place.

But perhaps what I need is a full-fledged lexer after all. Unless
there's a nice way of saying "match up to some predicate that determines
the end of the word" in the current infrastructure.


Claiming that your operating system is the best in the world because more people use it is like saying McDonalds makes the best food in the world. -- Carl B. Constantine

More information about the Digitalmars-d-learn mailing list