The optional third parameter of `indexOf' can be called with
`CaseSensitive.no'. But that parameter is left untouched. Instead a check with `toUpper( c)' is used, thereby risking a further visitation of the whole string .

Using CaseSensitive.no is a lot slower

Hmmm then perhaps a whole re-write. I've gotten this done, although I'll need someone to tell me how well it does. Far as I can tell it's O(n). It's based loosely on the ascii version, except templatized. Hope it's not too ugly...



import std.stdio, std.string, std.traits, std.uni, std.conv;

string T_isPangram(string name, string set, string uset = "") {
        string x = "bool " ~ name ~ "(S)(S s) if (isSomeString!S) {\n";
        if(set.length > 32) {
                x ~= "\tulong bitset;\n";
        } else {
                x ~= "\tuint bitset;\n";
        }
        x ~= "\tforeach(dchar c; s) {\n\t\tswitch(toLower(c)) {\n";
        foreach(i, c; set) {
                x ~= "\t\t\tcase '" ~ c ~ "':";
                x ~= "\tbitset |= 1 << " ~ to!string(i) ~ "; break;\n";
        }

        int i = set.length;
        while(uset.length >= 6) {
                x ~= "\t\t\tcase '" ~ uset[0 .. 6] ~ "':";
                x ~= "\tbitset |= 1 << " ~ to!string(i) ~ "; break;\n";
                uset = uset[6 .. $];
                i++;
        }

x ~= "\t\t\tdefault:\n\t\t}\n\t}\n\treturn bitset == (1 << " ~ to!string(i) ~ ") - 1;\n}";

        return x;
}


mixin(T_isPangram("EN_isPangram", "abcdefghijklmnopqrstuvwxyz"));
mixin(T_isPangram("DE_isPangram", "abcdefghijklmnopqrstuvwxyz", "\\u00DF\\u00e4\\u00f6\\u00dc")); mixin(T_isPangram("SV_isPangram", "abcdefghijklmnopqrstuvwxyz", "\\u00e5\\u00e4\\u00f6"));

unittest {
writeln(T_isPangram("TEST_isPangram", "ab", "\\u00DF\\u00e4")); //example output below

        assert(!EN_isPangram("this doesn't cover everything"));
assert(EN_isPangram("the quick brown fox jumps over the LAZY dog")); //to-lower check along with english assert(DE_isPangram("Falsches Üben von Xylophonmusik quält jeden größeren Zwerg"));
   assert(SV_isPangram("Yxskaftbud, ge vår wczonmö iqhjälp"w));
}

/*
bool TEST_isPangram(S)(S s) if (isSomeString!S) {
       uint bitset;
       foreach(dchar c; s) {
               switch(toLower(c)) {
                       case 'a':       bitset |= 1 << 0; break;
                       case 'b':       bitset |= 1 << 1; break;
                       case '\u00DF':  bitset |= 1 << 2; break;
                       case '\u00e4':  bitset |= 1 << 3; break;
                       default:
               }
       }
       return bitset == (1 << 4) - 1;
}
*/

Reply via email to