Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions std/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -1728,19 +1728,19 @@ private void testFloatingToIntegral(Floating, Integral)()


/**
String to non-string conversion runs parsing.
String, or string-like input range, to non-string conversion runs parsing.
$(UL
$(LI When the source is a wide string, it is first converted to a narrow
string and then parsed.)
$(LI When the source is a narrow string, normal text parsing occurs.))
*/
private T toImpl(T, S)(S value)
if ( isExactSomeString!S && isDynamicArray!S &&
if (isInputRange!S && isSomeChar!(ElementEncodingType!S) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When did this isExactSomeString come about? Sigh...

!isExactSomeString!T && is(typeof(parse!T(value))))
{
scope(success)
{
if (value.length)
if (!value.empty)
{
throw convError!(S, T)(value);
}
Expand All @@ -1750,12 +1750,12 @@ private T toImpl(T, S)(S value)

/// ditto
private T toImpl(T, S)(S value, uint radix)
if ( isExactSomeString!S && isDynamicArray!S &&
if (isInputRange!S && isSomeChar!(ElementEncodingType!S) &&
!isExactSomeString!T && is(typeof(parse!T(value, radix))))
{
scope(success)
{
if (value.length)
if (!value.empty)
{
throw convError!(S, T)(value);
}
Expand Down Expand Up @@ -1784,6 +1784,24 @@ private T toImpl(T, S)(S value, uint radix)
assert(n == 255);
}

// bugzilla 15800
unittest
{
import std.utf : byCodeUnit, byChar, byWchar, byDchar;

assert(to!int(byCodeUnit("10")) == 10);
assert(to!int(byCodeUnit("10"), 10) == 10);
assert(to!int(byCodeUnit("10"w)) == 10);
assert(to!int(byCodeUnit("10"w), 10) == 10);

assert(to!int(byChar("10")) == 10);
assert(to!int(byChar("10"), 10) == 10);
assert(to!int(byWchar("10")) == 10);
assert(to!int(byWchar("10"), 10) == 10);
assert(to!int(byDchar("10")) == 10);
assert(to!int(byDchar("10"), 10) == 10);
}

/**
Convert a value that is implicitly convertible to the enum base type
into an Enum value. If the value does not match any enum member values
Expand Down