D case insensitive associative array?

146 Views Asked by At

Is it possible? I'm building a REST Api with vibe.d and implementing token authentication. Because I'm not aware in which casing the user will send me Authorization header parameter, I need to query it in case insensitive manner. For example:

string[string] foo;
foo["XXX"] = "YYY";
logInfo(*("xxx" in foo)); // BOOM. Exception here

Is it possible..?

Thanks

2

There are 2 best solutions below

4
cfh On

Simply lowercase all keys of the associative array before you store or query them.

0
dmakarov On

if the case is either all lower or all upper, then you might have something like

"xxx" in foo && logInfo(foo["xxx"]);
"XXX" in foo && logInfo(foo["XXX"]);

maybe there's more efficient way to do this. If you don't have control over how the keys are entered in the AA, then it seems you have to check all casing variants when querying a specific key.