On Wed, 30 Dec 2009 19:45:02 +0100, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> wrote:
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
Sound nice. I've also wanted to see the two combined.
I take it the NoCase range is a lazy wrapper of a (d|w)?char range?
Some testing shows that 3659 can be sidestepped by making opEquals a
template function, or by creating more than one opEquals, where one
matches const bool( const ref typeof( this ) ).
--
Simen