Parse File at compile time, but not embedded

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 11 06:03:47 PDT 2016


On Friday, 10 June 2016 at 18:47:59 UTC, Joerg Joergonson wrote:
>> In any case, this is impossible. D has no such concept as 
>> "compile-time-only" values, so any usage of a value risks 
>> embedding it into the binary.
sure, it has.

template ParseData (string text) {
   private static enum Key = "XXXyyyZZZ33322211\n";
   private static enum TRet = "int data = 3;";
   private static enum FRet = "int data = 4;";
   static if (text.length >= Key.length) {
     static if (text[0..Key.length] == Key)
       enum ParseData = TRet;
     else
       enum ParseData = FRet;
   } else {
     enum ParseData = FRet;
   }
}

void main () {
   mixin(ParseData!(import("a")));
}


look, ma, no traces of our secret key in binary! and no traces of 
`int data` declaration too!


More information about the Digitalmars-d-learn mailing list