Bug 5247 – std.utf.stride() should not return 0xFF

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-11-21T01:12:00Z
Last change time
2010-11-24T07:57:11Z
Assigned to
nobody
Creator
rsinfu

Comments

Comment #0 by rsinfu — 2010-11-21T01:12:18Z
stride(s, i) returns 0xFF, or 255, if s[i] is not a UTF-8 lead byte. This design allows the function to silently succeed when the input is broken: auto str = new char[](300); str[0] = '\xFE'; // broken str = str[str.stride(0) .. $]; // jumps 255 bytes stride(s, i) should throw an exception if s[i] is not a lead byte. Or at least the error value should not be 255.
Comment #1 by doob — 2010-11-21T02:59:58Z
Are you sure that you understand how stride works? stride returns the length of an UTF sequence, not an index. Why would you try to use the return value of stride as an index?
Comment #2 by nfxjfg — 2010-11-21T05:10:52Z
(In reply to comment #1) > Are you sure that you understand how stride works? stride returns the length of > an UTF sequence, not an index. Why would you try to use the return value of > stride as an index? You use the length to index into the string or to slice it. Obviously stride() should return a valid value, and not some undocumented magic (well it's a bug most likely, and not a feature gone wrong). I don't get what's your problem.
Comment #3 by repeatedly — 2010-11-24T07:57:11Z