digitalmars.D.learn - std.format expand "%s"
- jmh530 (10/10) Aug 20 2017 I'm playing around with std.format and I'm trying to figure out
- Steven Schveighoffer (7/19) Aug 21 2017 Well, for most things, %s does not do the same thing as another
- jmh530 (5/12) Aug 21 2017 I'm pretty sure that isFloatingPoint/isIntegral is not what I
- Steven Schveighoffer (6/19) Aug 21 2017 What I mean is that %s goes to %d for isIntegral!(typeof(x)), and %s
- jmh530 (4/10) Aug 22 2017 I realized I was more interested in the length of the result than
I'm playing around with std.format and I'm trying to figure out if there is any way to identify what "%s" should expand to. So for instance: int x = 1; auto result = x.format!"%s"; I would know that result="1". I could run "1" through unformatValue and get back 1. I'm looking to see if there is a way to get back "%d": really a function would be like f(x, "%s") produces "%d". Is there anything like that in std.format?
Aug 20 2017
On 8/20/17 9:52 PM, jmh530 wrote:I'm playing around with std.format and I'm trying to figure out if there is any way to identify what "%s" should expand to. So for instance: int x = 1; auto result = x.format!"%s"; I would know that result="1". I could run "1" through unformatValue and get back 1. I'm looking to see if there is a way to get back "%d": really a function would be like f(x, "%s") produces "%d". Is there anything like that in std.format?Well, for most things, %s does not do the same thing as another specifier. It's only integers, which format the same as %d, and floating points, which format the same as %g. For all others, the format is specified as %s. I think what you really want is just isFloatingPoint or isIntegral. -Steve
Aug 21 2017
On Monday, 21 August 2017 at 13:57:01 UTC, Steven Schveighoffer wrote:Well, for most things, %s does not do the same thing as another specifier. It's only integers, which format the same as %d, and floating points, which format the same as %g. For all others, the format is specified as %s. I think what you really want is just isFloatingPoint or isIntegral. -SteveI'm pretty sure that isFloatingPoint/isIntegral is not what I need, but I'm also not sure if what I was asking for above is needed either. So I'll just drop it for now.
Aug 21 2017
On 8/21/17 10:58 AM, jmh530 wrote:On Monday, 21 August 2017 at 13:57:01 UTC, Steven Schveighoffer wrote:What I mean is that %s goes to %d for isIntegral!(typeof(x)), and %s goes to %g for isFloatingPoint!(typeof(x)), and stays as %s for everything else. Given this, you could probably write the function you were looking for. -SteveWell, for most things, %s does not do the same thing as another specifier. It's only integers, which format the same as %d, and floating points, which format the same as %g. For all others, the format is specified as %s. I think what you really want is just isFloatingPoint or isIntegral.I'm pretty sure that isFloatingPoint/isIntegral is not what I need, but I'm also not sure if what I was asking for above is needed either. So I'll just drop it for now.
Aug 21 2017
On Monday, 21 August 2017 at 15:39:04 UTC, Steven Schveighoffer wrote:What I mean is that %s goes to %d for isIntegral!(typeof(x)), and %s goes to %g for isFloatingPoint!(typeof(x)), and stays as %s for everything else. Given this, you could probably write the function you were looking for. -SteveI realized I was more interested in the length of the result than the type.
Aug 22 2017