Function IniLikeGroup.validateKey

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

void validateKey (
  string key,
  string value
) @trusted const;

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

Parameters

NameDescription
key key to validate.
value value that is being set to key.

Throws

IniLikeEntryException if either key is invalid.

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.

Example

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

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

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

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

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

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