Bug 16210 – std.utf.byUTF can be made into a bidirectional range

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-06-27T19:49:07Z
Last change time
2021-08-06T06:31:13Z
Keywords
pull, trivial
Assigned to
Vlăduț Chicoș
Creator
Jack Stouffer
Depends on
16323

Comments

Comment #0 by jack — 2016-06-27T19:49:07Z
... for certain inputs at least. Currently it's only a forward range.
Comment #1 by uaaabbjjkl — 2017-03-11T22:24:33Z
Assuming "ö" == [0xC3, 0xB6], which one version would be correct: a) behaviour of std.utf.byCodeUnit, just go by code units backward: "ö".byUTF!char().back == 0xB6 b) decode the character and return its first code unit: "ö".byUTF!char().back == 0xC3 Personally I thought the b) version is desired (docs says that byUTF encodes input), but at the moment it passes some inputs to byCodeUnit - it means for some ranges byUTF is bidirectional already and version a) applies.
Comment #2 by jack — 2017-03-12T04:14:43Z
(In reply to Jakub Łabaj from comment #1) > Assuming "ö" == [0xC3, 0xB6], which one version would be correct: > a) behaviour of std.utf.byCodeUnit, just go by code units backward: > "ö".byUTF!char().back == 0xB6 > > b) decode the character and return its first code unit: > "ö".byUTF!char().back == 0xC3 > > Personally I thought the b) version is desired (docs says that byUTF encodes > input), but at the moment it passes some inputs to byCodeUnit - it means for > some ranges byUTF is bidirectional already and version a) applies. Well damn. IMO B is more intuitive in all situations, so byUTF returning by byCodeUnit isn't want we really want. But because we can't break code, we would have to have B be the behavior only when some encoding has to be done inside of byUTF and clearly document this odd behavior.
Comment #3 by uaaabbjjkl — 2017-03-13T01:32:19Z
Or we should implement another function e.g. byCodePoint which would behave as we want in all cases? For me it seems a better solution than function logic dependent on argument's type.
Comment #4 by uaaabbjjkl — 2017-03-13T01:33:39Z
Or maybe add a templated switch which would default to the a), but allow to choose b)?
Comment #5 by dlang-bot — 2021-08-01T02:42:33Z
@vladchicos created dlang/phobos pull request #8183 "[DSSv3] Fix Issue 16210 - std.utf.byUTF can be made into a bidirectional range" fixing this issue: - Fix Issue 16210 - std.utf.byUTF can be made into a bidirectional range. https://github.com/dlang/phobos/pull/8183
Comment #6 by dlang-bot — 2021-08-01T20:42:53Z
@vladchicos created dlang/phobos pull request #8185 "[DSSv3] Fix Issue 19727 - std.algorithm.endsWith fails to compile while startsWith succeeds" fixing this issue: - Fix Issue 16210 - std.utf.byUTF can be made into a bidirectional range. https://github.com/dlang/phobos/pull/8185
Comment #7 by dlang-bot — 2021-08-06T06:31:13Z
dlang/phobos pull request #8183 "[DSSv3] Fix Issue 16210 - std.utf.byUTF can be made into a bidirectional range" was merged into master: - c76af8242253220d66a82616d64853ccb5ea8cfb by vladchicos: Fix Issue 16210 - std.utf.byUTF can be made into a bidirectional range. https://github.com/dlang/phobos/pull/8183