Hash-Table-Based Multiple Arguments Replacement

Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Oct 10 09:19:51 PDT 2015


Is there an algorithm somewhere in Phobos which performs when 
possible a replacement/substitution based on a variadic 
definition of replacements using hash-table search similar to

string replaceWhole(string a)
{
     switch (x)
     {
     case "a": return "1";
     case "b": return "2";
     default:  return x;
     }
}

?

Desired interface

y = x.replaceWhole!("a","x",
                     "b","y",
                     "c","z")

or perhaps

y = x.replaceWhole!(tuple("a","x"),
                     tuple("b","y"),
                     tuple("c","z"))


kind of like

"a".among!("a", "b", "c")

but for replacements.


More information about the Digitalmars-d-learn mailing list