one step towards unification of std.algorithm and std.string

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Dec 30 10:45:02 PST 2009


I've wanted for a long time to move more stuff from std.string into 
std.algorithm. One issue that has kept me from doing that is the case 
issue, i.e. some string functions have mind/ignore case flavors that 
don't make sense for other data types. For example consider cmp() and 
icmp(): http://www.digitalmars.com/d/2.0/phobos/std_string.html#cmp or 
the recently changed indexOf: 
http://www.digitalmars.com/d/2.0/phobos/std_string.html#indexOf

It occurred to me that I can transfer the case sensitivity away from the 
algorithm into the data. To do so, we only need to define one more data 
type NoCase that behaves much like a dchar but defines opEquals to 
compare ignoring case. Then, we need to define a NoCase range that 
behaves like a bidirectional range of dchar but again uses 
case-insensitive comparisons. Add some garnishing and you get to write:

string a = "Hello, World!"
auto x = indexOf(a, nocase("world"));
assert(x == 7);

I'm quite excited about this because it modularizes the entire case 
business, opens strings to many algorithms, and allows generalization of 
string algorithms.

Well, that is until I hit http://d.puremagic.com/issues/show_bug.cgi?id=3659

Any thoughts and ideas would be appreciated.


Andrei



More information about the Digitalmars-d mailing list