IniLikeGroup.validateKey

Validate key before setting value to key for this group and throw exception if not valid. Can be reimplemented in derived classes.

Default implementation checks if key is not empty string, does not look like comment and does not contain new line or carriage return characters.

class IniLikeGroup
protected @trusted const
void
validateKey
(
string key
,
string value
)

Parameters

key string

key to validate.

value string

value that is being set to key.

Throws

IniLikeEntryException if either key is invalid.

Examples

auto ilf = new IniLikeFile();
ilf.addGenericGroup("Group");

auto entryException = collectException!IniLikeEntryException(ilf.group("Group")[""] = "Value1");
assert(entryException !is null);
assert(entryException.groupName == "Group");
assert(entryException.key == "");
assert(entryException.value == "Value1");

entryException = collectException!IniLikeEntryException(ilf.group("Group")["    "] = "Value2");
assert(entryException !is null);
assert(entryException.key == "    ");
assert(entryException.value == "Value2");

entryException = collectException!IniLikeEntryException(ilf.group("Group")["New\nLine"] = "Value3");
assert(entryException !is null);
assert(entryException.key == "New\nLine");
assert(entryException.value == "Value3");

entryException = collectException!IniLikeEntryException(ilf.group("Group")["# Comment"] = "Value4");
assert(entryException !is null);
assert(entryException.key == "# Comment");
assert(entryException.value == "Value4");

entryException = collectException!IniLikeEntryException(ilf.group("Group")["Everyone=Is"] = "Equal");
assert(entryException !is null);
assert(entryException.key == "Everyone=Is");
assert(entryException.value == "Equal");

See Also

validateValue Note: Implementer should ensure that their implementation still validates key for format consistency (i.e. no new line characters, etc.). If not sure, just call super.validateKey(key, value) in your implementation.

Meta