[Issue 1630] New: Few suggestions for std.conv (D language 2.0)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 31 02:25:51 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1630

           Summary: Few suggestions for std.conv (D language 2.0)
           Product: D
           Version: 2.006
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: aarti at interia.pl


First of all I found new additions to Phobos really great! Thanks!

I would like to suggest here some extensions which could be useful:
1. parse() function does not allow to apply additional, user defined
transformations on consumed tokens. I mean for example additional checking for
matching parsed token to regular expression pattern. It would be probably
better to have just template function consume(T)() which returns consumed token
of specific type as string. Then it would be possible to convert consumed token
with to!(T) template. I see here 2 possibilities: replace parse with consume or
add additional template consume.

2. Conversion function template to!(T)() works great. It can even convert
arrays into string. Unfortunately the other way (converting from string into
array) is not possible, although I think it should. If it work properly it
would allow easy serialization of complex types. If request would be applied,
then probably it would be necessary to change representation of strings in
serialized form to use "" or ''. (See also next point.)

3. String parsing functions. It seems to be quite common task to parse
delimited with "" or '' strings from text. I think that in case of such
delimited strings there should be also escape characters supported, so e.g.
when in delimited string there is \" it should be properly interpreted as
character, not as delimiter. (BTW. Conversion to/from escape characters is also
quite common, so some functions in standard library would be great also.). I
think that quite a good solution would be to allow 3 forms for strings:
delimited with ", delimited with ' and without delimiters. In 3rd case there
should be no conversion for escape characters.

4. It should be possible to add custom parsers and converters. It will allow
full serialization solution on compile time.

In my library Doost/ProgramOptions I can not use much of new functionality
directly because of above problems.


-- 



More information about the Digitalmars-d-bugs mailing list