[Issue 17905] New: byCodeUnit should allow access to underlying range

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 17 01:18:43 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=17905

          Issue ID: 17905
           Summary: byCodeUnit should allow access to underlying range
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: issues.dlang at jmdavisProg.com

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.

--


More information about the Digitalmars-d-bugs mailing list