string to character code hex string

bitwise via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 2 13:20:47 PDT 2017


On Saturday, 2 September 2017 at 18:28:02 UTC, Moritz Maxeiner 
wrote:
> [...]

Code will eventually look something like the following.
The point is to be able to retrieve the exported function at 
runtime only by knowing what the template arg would have been.

export extern(C) const(Reflection) dummy(string fqn)(){ ... }

int main(string[] argv)
{
     enum ARG = "AAAAAA";
     auto hex = toAsciiHex(ARG);

     // original
     writeln(dummy!ARG.mangleof);

     // reconstructed at runtime
     auto remangled = dummy!"".mangleof;

     remangled = remangled.replaceFirst(
         "_D7mainMod17", "_D7mainMod" ~ (17 + 
hex.length).to!string);

     remangled = remangled.replaceFirst(
         "VAyaa0_", "VAyaa" ~ ARG.length.to!string ~ "_" ~ hex);

     writeln(remangled);

     return 0;
}




More information about the Digitalmars-d-learn mailing list