Simpler alias that conveys the meaning more appropriately.
Gets the value and converts it to a bool.
Gets the value and converts it to a byte.
Gets the value and converts it to a double.
Gets the value and converts it to a float.
Gets the value and converts it to a int.
Gets the value and converts it to a long.
Gets the value and converts it to a real.
Gets the value and converts it to a short.
Gets the value and converts it to a string.
Converts the value of key to type of T. Works the same as std.variant's coerce.
Determines if the key is found in the config file. The key can be either its name of in the format of groupName.keyName or just the key name.
Determines if the key is found in the config file.
Determines if the given group exists.
Retrieves the value T associated with key where T is the designated type to be converted to.
Retrieves the value T associated with key where T is the designated type to be converted to.
Retrieves key/values associated with the group portion of a config file/string.
Gets the value associated with the group and key.
Retrieves an array containing key/values of all groups in the configfile omitting groupless key/values.
Loads a config fileName(app.config by default) to be processed.
Similar to loadFile but loads and processes the passed string instead.
Allows config values to be accessed as you would with an associative array.
Allows config values to be assigned as you would with an associative array.
Removes a key/value from config file. The key can be either its name of in the format of groupName.keyName or just the keyName.
Removes a key/value from config file. The key can be either its name of in the format of group.keyor just the key.
Removes a group from the config file.
Saves config values to the config file used when loading(loadFile).
Saves config values to the config file.
Sets a config value.
Sets a config value.
1 string text = " 2 aBool=true 3 decimal = 3443.443 4 number=12071 5 #Here is a comment 6 sentence=This is a really long sentence to test for a really long value string! 7 time=12:04 8 [section] 9 groupSection=is really cool if this works! 10 japan=true 11 babymetal=the one 12 [another] 13 #And another comment! 14 world=hello 15 japan=false 16 "; 17 18 VariantConfig config; 19 20 immutable bool loaded = config.loadString(text); 21 assert(loaded, "Failed to load string!"); 22 23 assert(config.containsGroup("section")); 24 config.removeGroup("section"); 25 assert(config.containsGroup("section") == false); 26 27 assert(config.get("aBool", true).coerce!bool == true); 28 assert(config.asBool("aBool")); // Syntactic sugar 29 assert(config["aBool"].coerce!bool == true); // Also works but rather awkward 30 assert(config.coerce!bool("aBool") == true); // Also works and more natural 31 32 assert(config.contains("time")); 33 34 immutable auto number = config["number"]; 35 36 assert(number == 12_071); 37 assert(config["decimal"] == 3443.443); 38 39 assert(config.contains("another.world")); 40 assert(config["another.world"] == "hello"); 41 42 config["another.japan"] = true; 43 assert(config["another.japan"] == true); 44 45 config.remove("another.world"); 46 47 assert(config.contains("another.world") == false); 48 assert(config.contains("anothers", "world") == false); 49 50 assert(config.contains("number")); 51 config.remove("number"); 52 assert(config.contains("number") == false); 53 54 // Tests for nonexistent keys 55 assert(config.asString("nonexistent", "Value doesn't exist!") == "Value doesn't exist!"); 56 config["nonexistent"] = "The value now exists!!!"; 57 assert(config.asString("nonexistent", "The value now exists!!!") == "The value now exists!!!"); 58 59 auto group = config.getGroup("another"); 60 61 foreach(value; group) 62 { 63 assert(value.key == "japan"); 64 assert(value.value == true); 65 } 66 67 config.set("aBool", false); 68 assert(config["aBool"] == false); 69 debug config.save(); 70 71 config["aBool"] = true; 72 assert(config["aBool"] == true); 73 assert(config["aBool"].toString == "true"); 74 75 assert(config.get!int("numberGroup", "numberValue", 1234) == 1234); 76 77 immutable string customFileName = "custom-config-format.dat"; 78 debug config.save(customFileName); 79 80 VariantConfig configLoadTest; 81 82 bool isLoadedTest = configLoadTest.loadFile("doesnt-exist.dat"); 83 assert(isLoadedTest == false); 84 85 isLoadedTest = configLoadTest.loadFile(customFileName); 86 assert(isLoadedTest == true); 87 88 string noEqualSign = " 89 equal=sign 90 time=12:04 91 This is a really long sentence to test for a really long value string! 92 "; 93 94 immutable bool equalSignValue = config.loadString(noEqualSign); 95 assert(equalSignValue == false); 96 97 auto groups = config.getGroups(); 98 99 writeln("Listing groups: "); 100 writeln; 101 102 foreach(currGroup; groups) 103 { 104 writeln(currGroup); 105 } 106 107 string invalidGroup = " 108 [first] 109 equal=sign 110 time=12:04 111 [second 112 another=key value is here 113 "; 114 115 immutable bool invalidGroupValue = config.loadString(invalidGroup); 116 assert(invalidGroupValue == false); 117 118 string emptyString; 119 120 immutable bool emptyLoad = config.loadString(emptyString); 121 assert(emptyLoad == false);
Handles the processing of config files.