Skip to content

Commit

Permalink
Improved docs for std.conv.parse
Browse files Browse the repository at this point in the history
  • Loading branch information
JackStouffer committed Jul 13, 2016
1 parent 5790171 commit e992522
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions std/conv.d
Expand Up @@ -3089,11 +3089,20 @@ Target parse(Target, Source)(ref Source p)
}

/**
Parsing one character off a string returns the character and bumps the
string up one position.
Parsing one character off a range returns the first element and calls `popFront`.
Params:
Target = the type to convert to
s = the lvalue of an input range
Returns:
A character of type `Target`
Throws:
A $(LREF ConvException) if the range is empty.
*/
Target parse(Target, Source)(ref Source s)
if (isExactSomeString!Source &&
if (isSomeString!Source && !is(Source == enum) &&
staticIndexOf!(Unqual!Target, dchar, Unqual!(ElementEncodingType!Source)) >= 0)
{
if (s.empty)
Expand Down Expand Up @@ -3130,6 +3139,7 @@ Target parse(Target, Source)(ref Source s)
}
}

/// ditto
Target parse(Target, Source)(ref Source s)
if (!isSomeString!Source && isInputRange!Source && isSomeChar!(ElementType!Source) &&
isSomeChar!Target && Target.sizeof >= ElementType!Source.sizeof && !is(Target == enum))
Expand All @@ -3141,6 +3151,15 @@ Target parse(Target, Source)(ref Source s)
return result;
}

///
@safe pure unittest
{
auto s = "Hello, World!";
char first = parse!char(s);
assert(first == 'H');
assert(s == "ello, World!");
}


/*
Tests for to!bool and parse!bool
Expand Down

0 comments on commit e992522

Please sign in to comment.