www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17708] New: Escape control characters in std.conv.to error

https://issues.dlang.org/show_bug.cgi?id=17708

          Issue ID: 17708
           Summary: Escape control characters in std.conv.to error
                    messages
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

Currently this program:

///// test.d ////
import std.conv;

void main()
{
    to!int("\r");
}
/////////////////

will produce output which looks like this in a terminal:

' when converting from type string to type intbin/../phobos/std/conv.d(2168):
Unexpected '
----------------
??:? pure  safe int std.conv.parse!(int, immutable(char)[]).parse(ref
immutable(char)[]) [0x4331de]
??:? pure  safe int std.conv.toImpl!(int,
immutable(char)[]).toImpl(immutable(char)[]) [0x436a70]
??:? pure  safe int
std.conv.to!(int).to!(immutable(char)[]).to(immutable(char)[]) [0x432a83]
??:? _Dmain [0x432a5d]

The error message appears malformed.

std.conv.to should escape whitespace / control / non-printable characters in
its error messages. Perhaps the existing functionality in std.conv / std.format
can be reused: format!"%(%s%)"(c.only) will already correctly escape such
characters.

See discussion in https://github.com/dlang/phobos/pull/5591 (which fixed this
issue specifically for the newline character only) for more details.

--
Jul 31