[Issue 8141] New: Two small improvements for std.string maketrans and translate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 24 14:28:33 PDT 2012


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

           Summary: Two small improvements for std.string maketrans and
                    translate
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2012-05-24 14:30:14 PDT ---
A small documentation bug report and a little related enhancement request.

This is part of the std.string Phobos module:


/************************************
 * $(RED Scheduled for deprecation in March 2012.)
 *
 * Construct translation table for translate().
 * BUGS: only works with ASCII
 */

string maketrans(in char[] from, in char[] to)
...
}

/******************************************
 * $(RED Scheduled for deprecation in March 2012.
 *   Please use the version of $(D translate) which takes an AA instead.)
 *
 * Translate characters in s[] using table created by maketrans().
 * Delete chars in delchars[].
 * BUGS: only works with ASCII
 */

string translate()(in char[] s, in char[] transtab, in char[] delchars)

--------------------

My suggestions are:

1) To remove from both ddocs the "$(RED Scheduled for deprecation in March
2012.)" and replace "BUGS: only works with ASCII" with something like: "NOTE:
only works with ASCII."


2) This is the signature of the ascii version of translate:

string translate()(in char[] s, in char[] transtab, in char[] delchars)

I suggest to add a null default argument for the "delchars" argument:

string translate()(in char[] s, in char[] transtab, in char[] delchars=null)

This makes translate() more handy, and it's more similar to the Python
str.translate() method this D function is *copied* from:


>>> from string import maketrans
>>> t = maketrans("abc", "XYZ")
>>> "absent".translate(t, "tn")
'XYse'
>>> "absent".translate(t)
'XYsent'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list