Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.parse

@nogc and nothrow Parsing Utilities

License:
Authors:
Ilia Ki
struct ParsePosition;
Parsing position
string file;
uint line;
0 is for unknown
uint column;
0 is for unknown
const void toString(W)(ref scope W w) scope;
enum DecimalExponentKey: int;
none
infinity
nan
dot
d
e
D
E
struct DecimalExponentInfo;
Examples:
mir.conv: to extension.
import mir.test: should;
import mir.conv: to;

"123.0".to!double.should == 123;
"123".to!int.should == 123;
"123".to!byte.should == 123;

import mir.small_string;
alias S = SmallString!32;
"123.0".SmallString!32.to!double.should == 123;
long exponent;
DecimalExponentKey key;
template fromString(T) if (isMutable!T)
Performs nothrow and @nogc string to native type conversion.
Returns:
parsed value
Throws:
nogc Exception in case of parse error or non-empty remaining input.

Floating point Mir parsing supports up-to quadruple precision. The conversion error is 0 ULP for normal numbers. Subnormal numbers with an exponent greater than or equal to -512 have upper error bound equal to 1 ULP.

T fromString(C)(scope const(C)[] str)
if (isSomeChar!C);
@trusted bool fromString(T, C)(scope const(C)[] str, ref T value)
if (isSomeChar!C && isFloatingPoint!T);

bool fromString(T, C)(scope const(C)[] str, ref T value)
if (isSomeChar!C && !isFloatingPoint!T);
Performs nothrow and @nogc string to native type conversion.

Rseturns true if success and false otherwise.

Examples:
int value;
assert("123".fromString(value) && value == 123);
Examples:
double value = 0;
assert("+Inf".fromString(value) && value == double.infinity);
assert("-nan".fromString(value) && value != value);
bool parse(T, C)(ref scope inout(C)[] str, ref scope T value)
if (isSomeChar!C && isSomeChar!T && (T.sizeof == C.sizeof));
Single character parsing utilities.
Returns:
true if success and false otherwise.
Examples:
auto s = "str";
char c;
assert(parse(s, c));
assert(c == 's');
assert(s == "tr");
bool parse(T, C)(ref scope inout(C)[] str, out scope T value)
if ((is(T == byte) || is(T == short)) && isSomeChar!C);
Integer parsing utilities.
Returns:
true if success and false otherwise.