digitalmars.D - swritef()
- Sebastian Beschke (20/20) Jan 08 2005 I've copied and pasted this little snippet so much now that I thought
- h3r3tic (13/40) Jan 08 2005 How bout this ?
- Sebastian Beschke (3/53) Jan 08 2005 You're right, I overlooked the encode() function. Thanks :)
- teqDruid (3/30) Jan 08 2005 I think std.string.format() provides this functionality.
- Sebastian Beschke (5/6) Jan 09 2005 Not only that, but it's identic to what h3r3tic posted...
- h3r3tic (7/15) Jan 09 2005 Wow, I've just reinvented the wheel :D
- Sebastian Beschke (2/9) Jan 09 2005
- Sebastian Beschke (4/7) Jan 09 2005 I added a small section in the documentation amendments in Wiki4d.
I've copied and pasted this little snippet so much now that I thought I'd post it: char[] swritef(...) { char[] result; void putc(dchar c) { char[4] buf; char[] b; b = std.utf.toUTF8(buf, c); for (size_t i = 0; i < b.length; i++) { result ~= b[i]; } } std.format.doFormat(&putc, _arguments, _argptr); return result; } Dunno if it's very efficient or anything, but I think such a thing is really needed, and as far as I can tell, phobos doesn't contain it yet. -Sebastian
Jan 08 2005
Sebastian Beschke wrote:I've copied and pasted this little snippet so much now that I thought I'd post it: char[] swritef(...) { char[] result; void putc(dchar c) { char[4] buf; char[] b; b = std.utf.toUTF8(buf, c); for (size_t i = 0; i < b.length; i++) { result ~= b[i]; } } std.format.doFormat(&putc, _arguments, _argptr); return result; } Dunno if it's very efficient or anything, but I think such a thing is really needed, and as far as I can tell, phobos doesn't contain it yet. -SebastianHow bout this ? char[] str(...) // or call it swritef; this name's from Python { char[] result; void putc(dchar c) { std.utf.encode(result, c); } std.format.doFormat(&putc, _arguments, _argptr); return result; } Tom
Jan 08 2005
h3r3tic schrieb:Sebastian Beschke wrote:You're right, I overlooked the encode() function. Thanks :) -SebastianI've copied and pasted this little snippet so much now that I thought I'd post it: char[] swritef(...) { char[] result; void putc(dchar c) { char[4] buf; char[] b; b = std.utf.toUTF8(buf, c); for (size_t i = 0; i < b.length; i++) { result ~= b[i]; } } std.format.doFormat(&putc, _arguments, _argptr); return result; } Dunno if it's very efficient or anything, but I think such a thing is really needed, and as far as I can tell, phobos doesn't contain it yet. -SebastianHow bout this ? char[] str(...) // or call it swritef; this name's from Python { char[] result; void putc(dchar c) { std.utf.encode(result, c); } std.format.doFormat(&putc, _arguments, _argptr); return result; } Tom
Jan 08 2005
I think std.string.format() provides this functionality. John On Sat, 08 Jan 2005 16:07:25 +0100, Sebastian Beschke wrote:I've copied and pasted this little snippet so much now that I thought I'd post it: char[] swritef(...) { char[] result; void putc(dchar c) { char[4] buf; char[] b; b = std.utf.toUTF8(buf, c); for (size_t i = 0; i < b.length; i++) { result ~= b[i]; } } std.format.doFormat(&putc, _arguments, _argptr); return result; } Dunno if it's very efficient or anything, but I think such a thing is really needed, and as far as I can tell, phobos doesn't contain it yet. -Sebastian
Jan 08 2005
teqDruid schrieb:I think std.string.format() provides this functionality.Not only that, but it's identic to what h3r3tic posted... This should be in the docs! ;) I still prefer the name swritef, though. -Sebastian
Jan 09 2005
Sebastian Beschke wrote:teqDruid schrieb:Wow, I've just reinvented the wheel :D I'll have to patent it <g>I think std.string.format() provides this functionality.Not only that, but it's identic to what h3r3tic posted...This should be in the docs! ;)Definitely...I still prefer the name swritef, though.As for std.string.format ... It's quite scary... Say I want to make a string with the drive letter in it. Shall I do it with 'format("C:")' ? ;) Tom
Jan 09 2005
h3r3tic schrieb:Sebastian Beschke wrote:LOL, good one :)I still prefer the name swritef, though.As for std.string.format ... It's quite scary... Say I want to make a string with the drive letter in it. Shall I do it with 'format("C:")' ? ;)Tom
Jan 09 2005
Sebastian Beschke schrieb:This should be in the docs! ;)I added a small section in the documentation amendments in Wiki4d. http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Phobos -Sebastian
Jan 09 2005