initial: re-vendor @ c00e0fa

c00e0fa avoid converting objects twice
baafe10 fix doc comment
This commit is contained in:
Jeremy Baxter 2024-06-18 17:48:37 +12:00
parent 6bd5af01f8
commit d5cacb0401

View file

@ -218,7 +218,7 @@ struct INISection
keys = new string[string]; keys = new string[string];
} }
/+ /++
+ Returns the value of `k` in this section or + Returns the value of `k` in this section or
+ `defaultValue` if the key is not present. + `defaultValue` if the key is not present.
+/ +/
@ -234,10 +234,10 @@ struct INISection
+ with a message containing location information. + with a message containing location information.
+/ +/
T T
keyAs(T)(string k, string defaultValue = null) keyAs(T)(string k, T defaultValue)
{ {
try try
return key(k, defaultValue).to!T(); return k in keys ? keys[k].to!T() : defaultValue;
catch (ConvException) catch (ConvException)
throw new INITypeException( throw new INITypeException(
format!"unable to convert [%s].%s to %s"(name, k, T.stringof)); format!"unable to convert [%s].%s to %s"(name, k, T.stringof));