D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5247 - std.utf.stride() should not return 0xFF
Summary: std.utf.stride() should not return 0xFF
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-21 01:12 UTC by Shin Fujishiro
Modified: 2010-11-24 07:57 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Shin Fujishiro 2010-11-21 01:12:18 UTC
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 Jacob Carlborg 2010-11-21 02:59:58 UTC
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 nfxjfg 2010-11-21 05:10:52 UTC
(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 Masahiro Nakagawa 2010-11-24 07:57:11 UTC
Fixed in changeset 2190.
http://dsource.org/projects/phobos/changeset/2190