Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.string.tr should not be decoding strings #10383

Open
dlangBugzillaToGithub opened this issue Aug 18, 2019 · 0 comments
Open

std.string.tr should not be decoding strings #10383

dlangBugzillaToGithub opened this issue Aug 18, 2019 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

bugzilla (@WalterBright) reported this on 2019-08-18T22:29:00Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=20140

Description

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`.
@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants