www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - produce standard notation for strings

Hello,

I need to write one or more tool functions that produce standard notation for 
strings. Something like python's repr(s). For instance:
`abc
def     "ghi" jkl`
-->
"abc\ndef\t\"ghi\" jkl"
which, fed back into D code, reproduces the original string. I have actually 
several formats in mind, depending on which class(es) of chars are conserved 
literally or not (eg only \x20..\x7f), including a hex-only one.

First, is there something like that in stock (phobos or not) and I haven't 
searched well?

Else, I wonder about the best way to do it? Use replace(), manually iterate, 
use regexes (with replace func)? What else. How would you do it?

Thank you,
Denis
-- 
_________________
vita es estrany
spir.wikidot.com
Feb 13 2011