IniFilteredParser

Low-level INI parser with filtered output

This wrapper will only supply tokens of these types:

  • IniTokenType.key
  • IniTokenType.value
  • IniTokenType.sectionHeader
  • IniTokenType.invalid

Constructors

this
this(IniParser!(dialect, string) parser)
this
this(string rawIni)

Members

Aliases

Token
alias Token = IniToken!string

Functions

empty
bool empty()
front
inout(Token) front()
popFront
void popFront()
save
inout(typeof(this)) save()

Manifest constants

isDestructive
enum isDestructive;

Examples

	// INI document (demo data)
	static immutable string rawIniDocument = `; This is a comment.
[section1]
foo = bar ;another comment
oachkatzl = schwoaf ;try pronouncing that
`;

	// Combine feature flags to build the required dialect.
	const myDialect = (IniDialect.defaults | IniDialect.inlineComments);

	// Instantiate a new parser and supply our document string.
	auto parser = IniParser!(myDialect)(rawIniDocument);

	int comments = 0;
	int sections = 0;
	int keys = 0;
	int values = 0;

	// Process token by token.
	foreach (const parser.Token token; parser) {
		if (token.type == IniTokenType.comment) {
			++comments;
		}
		if (token.type == IniTokenType.sectionHeader) {
			++sections;
		}
		if (token.type == IniTokenType.key) {
			++keys;
		}
		if (token.type == IniTokenType.value) {
			++values;
		}
	}

	assert(comments == 3);
	assert(sections == 1);
	assert(keys == 2);
	assert(values == 2);

See Also

Meta