Bug 17905 – byCodeUnit should allow access to underlying range

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-10-17T01:18:43Z
Last change time
2017-12-18T22:55:11Z
Assigned to
No Owner
Creator
Jonathan M Davis

Comments

Comment #0 by issues.dlang — 2017-10-17T01:18:43Z
In general, when a range is wrapped in another range, you can't get access to the original range, and that makes sense, because the resulting range is transforming the underlying range such that it would usually cause problems if you could get at the underlying range. However, there are cases where it's a serious problem that you can't get at the underlying range. In particular, it seriously hampers byCodeUnit. The main purpose of byCodeUnit is to wrap narrow strings so that they're not autodecoded, and they're treated as random access ranges of code units. Of course, it also works on other ranges of charaters, but just returns those. And if you're simply consuming the string, that's not a big deal. However, there are plenty of cases where you want to feed a string into a function which would normally trigger autodecoding, which you don't want, so you use byCodeUnit, but you don't want the range's type to change (and it wouldn't need to save for auto-decoding). So, you need to use byCodeUnit to treat the string as a range of code units, but using byCodeUnit traps the string in another range. So, I propose that we add a source property to byCodeUnit so that it's possible to pass a string to a function which would normally auto-decode, have it treat the string as a range of code units instead, and get whatever is left of the string back out again from what the function returns. Then using byCodeUnit doesn't mean that the string is permanently trapped.
Comment #1 by github-bugzilla — 2017-10-17T21:31:57Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/6d7c2b0ba100b4fc117865abb808baef61f7ec26 Fix Issue 17905: Add source property to byCodeUnit. https://github.com/dlang/phobos/commit/5d7ad2df823172b0f43b3d3e4ce9d57dcc62aad9 Merge pull request #5785 from jmdavis/issue_17905 Issue 17905: Add source property to byCodeUnit
Comment #2 by github-bugzilla — 2017-12-18T22:55:11Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/6d7c2b0ba100b4fc117865abb808baef61f7ec26 Fix Issue 17905: Add source property to byCodeUnit. https://github.com/dlang/phobos/commit/5d7ad2df823172b0f43b3d3e4ce9d57dcc62aad9 Merge pull request #5785 from jmdavis/issue_17905