Bug 17180 – to!string('\0') makes "\0" which breaks concatination

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-02-14T03:33:00Z
Last change time
2017-02-14T16:03:02Z
Assigned to
nobody
Creator
jiki

Comments

Comment #0 by jiki — 2017-02-14T03:33:49Z
import std.conv; import std.stdio; void main() { char c = 0; string s = to!string(c); writeln(`"` ~ s ~ `"` ); stdout.flush(); // the last quate GONE assert(s.length == 0 || s[0] != '\0'); } # We want one of these, at least. * Empty string * Alternative character or message * Raising an error
Comment #1 by ag0aep6g — 2017-02-14T11:21:10Z
1) I see two quotes when I run your code. The last one is not gone. I'm running dmd 2.073.0 on Ubuntu linux. What version of dmd and what operating system are you on? 2) If there is a problem here, I don't think it's with to!string. For any char c, it returns a string [c]. Making '\0' an exception would be surprising. '\0' is a valid char, and "\0" is a valid string (with length 1).
Comment #2 by jiki — 2017-02-14T16:03:02Z
(In reply to ag0aep6g from comment #1) > 1) I see two quotes when I run your code. The last one is not gone. I'm > running dmd 2.073.0 on Ubuntu linux. What version of dmd and what operating > system are you on? Ooops! I should have tested it _without_ my development tool... On windows command prompt, it works correctly. I am sorry. closing this.