Issue 20140 - std.string.tr should not be decoding strings
Summary: std.string.tr should not be decoding strings
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-18 22:29 UTC by Walter Bright
Modified: 2024-12-01 16:35 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2019-08-18 22:29:00 UTC
See: https://forum.dlang.org/post/mvkbemmgatrfbxnmjada@forum.dlang.org

In the implementation of std.string.tr the main loop is:

    foreach (dchar c; str)

meaning char and wchar strings are getting decoded. This leads to problems as reported on the n.g. link.

The correct way to implement it is to just leave it in the encoding of `str`. This should result in a significant speed improvement.

This leaves open what to do if `from` and `to` contain invalid UTF sequences if the conversion of them is necessary. The most pragmatic solution is to reject `from` and `to` arguments to `tr` that are not of the same UTF encoding as `str`.
Comment 1 dlangBugzillaToGithub 2024-12-01 16:35:27 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10383

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB