1 module hunt.time.format.SettingsParser; 2 3 import hunt.time.format.DateTimeParseContext; 4 import hunt.time.format.DateTimePrinterParser; 5 import hunt.time.format.DateTimePrintContext; 6 import hunt.time.temporal.TemporalField; 7 import hunt.util.StringBuilder; 8 9 import hunt.time.util.Common; 10 11 import hunt.Exceptions; 12 13 //----------------------------------------------------------------------- 14 /** 15 * Enumeration to apply simple parse settings. 16 */ 17 static class SettingsParser : DateTimePrinterParser 18 { 19 // static SettingsParser SENSITIVE; 20 // static SettingsParser INSENSITIVE; 21 // static SettingsParser STRICT; 22 // static SettingsParser LENIENT; 23 24 private int _ordinal; 25 int ordinal() 26 { 27 return _ordinal; 28 } 29 30 // static this() 31 // { 32 // SENSITIVE = new SettingsParser(0); 33 mixin(MakeGlobalVar!(SettingsParser)("SENSITIVE",`new SettingsParser(0)`)); 34 // INSENSITIVE = new SettingsParser(1); 35 mixin(MakeGlobalVar!(SettingsParser)("INSENSITIVE",`new SettingsParser(1)`)); 36 // STRICT = new SettingsParser(2); 37 mixin(MakeGlobalVar!(SettingsParser)("STRICT",`new SettingsParser(2)`)); 38 39 // LENIENT = new SettingsParser(3); 40 mixin(MakeGlobalVar!(SettingsParser)("LENIENT",`new SettingsParser(3)`)); 41 42 // } 43 44 this(int ordinal) 45 { 46 _ordinal = ordinal; 47 } 48 49 override public bool format(DateTimePrintContext context, StringBuilder buf) 50 { 51 return true; // nothing to do here 52 } 53 54 override public int parse(DateTimeParseContext context, string text, int position) 55 { 56 // using ordinals to avoid javac synthetic inner class 57 switch (ordinal()) 58 { 59 case 0: 60 context.setCaseSensitive(true); 61 break; 62 case 1: 63 context.setCaseSensitive(false); 64 break; 65 case 2: 66 context.setStrict(true); 67 break; 68 case 3: 69 context.setStrict(false); 70 break; 71 default: 72 break; 73 } 74 return position; 75 } 76 77 override public string toString() 78 { 79 // using ordinals to avoid javac synthetic inner class 80 switch (ordinal()) 81 { 82 case 0: 83 return "ParseCaseSensitive(true)"; 84 case 1: 85 return "ParseCaseSensitive(false)"; 86 case 2: 87 return "ParseStrict(true)"; 88 case 3: 89 return "ParseStrict(false)"; 90 default: 91 break; 92 } 93 throw new IllegalStateException("Unreachable"); 94 } 95 } 96