www.digitalmars.com         C & C++   DMDScript  

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

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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: -------
May 24 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8141


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PDT ---
https://github.com/D-Programming-Language/phobos/pull/609



-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 28 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8141


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |FIXED



I'm guessing this was fixed sufficiently by
https://github.com/D-Programming-Language/phobos/commit/94c06fb2469c0d98be842438b749e61571b42fe3

Please reopen if that's not the case.

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