Struct IniLikeFile.ReadOptions

Behavior of ini-like file reading.

struct ReadOptions ;

Constructors

NameDescription
this Setting parameters in any order, leaving not mentioned ones in default state.

Fields

NameTypeDescription
duplicateGroupPolicy IniLikeFile.DuplicateGroupPolicyBehavior on groups with duplicate names.
duplicateKeyPolicy IniLikeFile.DuplicateKeyPolicyBehavior on duplicate keys.
invalidKeyPolicy IniLikeGroup.InvalidKeyPolicyBehavior on invalid keys.
preserveComments std.typecons.Flag!("preserveComments")Whether to preserve comments on reading.

Methods

NameDescription
assign Assign arg to the struct member of corresponding type.

Example

string contents = `# The first comment
[First Entry]
# Comment
GenericName=File manager
GenericName[ru]=Файловый менеджер
# Another comment
[Another Group]
Name=Commander
# The last comment`;

alias IniLikeFile.ReadOptions ReadOptions;
alias IniLikeFile.DuplicateKeyPolicy DuplicateKeyPolicy;
alias IniLikeFile.DuplicateGroupPolicy DuplicateGroupPolicy;

IniLikeFile ilf = new IniLikeFile(iniLikeStringReader(contents), null, ReadOptions(No.preserveComments));
assert(!ilf.readOptions().preserveComments);
assert(ilf.leadingComments().empty);
assert(equal(
    ilf.group("First Entry").byIniLine(),
    [IniLikeLine.fromKeyValue("GenericName", "File manager"), IniLikeLine.fromKeyValue("GenericName[ru]", "Файловый менеджер")]
));
assert(equal(
    ilf.group("Another Group").byIniLine(),
    [IniLikeLine.fromKeyValue("Name", "Commander")]
));

contents = `[Group]
Duplicate=First
Key=Value
Duplicate=Second`;

ilf = new IniLikeFile(iniLikeStringReader(contents), null, ReadOptions(DuplicateKeyPolicy.skip));
assert(equal(
    ilf.group("Group").byIniLine(),
    [IniLikeLine.fromKeyValue("Duplicate", "First"), IniLikeLine.fromKeyValue("Key", "Value")]
));

ilf = new IniLikeFile(iniLikeStringReader(contents), null, ReadOptions(DuplicateKeyPolicy.preserve));
assert(equal(
    ilf.group("Group").byIniLine(),
    [IniLikeLine.fromKeyValue("Duplicate", "First"), IniLikeLine.fromKeyValue("Key", "Value"), IniLikeLine.fromKeyValue("Duplicate", "Second")]
));
assert(ilf.group("Group").escapedValue("Duplicate") == "First");

contents = `[Duplicate]
Key=First
[Group]
[Duplicate]
Key=Second`;

ilf = new IniLikeFile(iniLikeStringReader(contents), null, ReadOptions(DuplicateGroupPolicy.preserve));
auto byGroup = ilf.byGroup();
assert(byGroup.front.escapedValue("Key") == "First");
assert(byGroup.back.escapedValue("Key") == "Second");

auto byNode = ilf.byNode();
assert(byNode.front.group.groupName == "Duplicate");
assert(byNode.front.key == "Duplicate");
assert(byNode.back.key is null);

contents = `[Duplicate]
Key=First
[Group]
[Duplicate]
Key=Second`;

ilf = new IniLikeFile(iniLikeStringReader(contents), null, ReadOptions(DuplicateGroupPolicy.skip));
auto byGroup2 = ilf.byGroup();
assert(byGroup2.front.escapedValue("Key") == "First");
assert(byGroup2.back.groupName == "Group");