Parser

A quantity parser.

struct Parser (
N
alias numberParser =
(
ref s
)
=> parse!N(s)
) if (
isNumeric!N
) {}

Members

Functions

parse
QVariant!N parse(S str)

Parses a QVariant from str.

Variables

symbolList
SymbolList!N symbolList;

A list of registered symbols for units and prefixes.

Parameters

N

The numeric type of the quantities.

numberParser

a function that takes a reference to any kind of string and returns the parsed number.

Examples

// From http://en.wikipedia.org/wiki/List_of_humorous_units_of_measurement

import std.conv : parse;

auto century = unit!real("T");
alias LectureLength = typeof(century);

auto symbolList = SymbolList!real().addUnit("Cy", century).addPrefix("µ", 1e-6L);
alias numberParser = (ref s) => parse!real(s);
auto parser = Parser!(real, numberParser)(symbolList);

auto timing = 1e-6L * century;
assert(timing == parser.parse("1 µCy"));

Meta