Bug 8141 – Two small improvements for std.string maketrans and translate

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-24T14:30:00Z
Last change time
2012-12-26T04:48:16Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-05-24T14:30:14Z
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'
Comment #1 by issues.dlang — 2012-05-28T17:17:53Z
https://github.com/D-Programming-Language/phobos/pull/609 does this as part of fixing issue# 7515.
Comment #2 by yebblies — 2012-12-26T04:48:16Z
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.