Bug 5265 – std.array.back does not work correctly for wchar-based arrays

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-11-24T05:11:00Z
Last change time
2013-02-11T06:58:43Z
Assigned to
andrei
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2010-11-24T05:11:09Z
In std.array, back() is the same for both char[] based and wchar[] based arrays, but wchar[] based arrays are encoded differently than char[] based ones. It appears the back() function works in most cases, but fails on a few. Here is an example (thank you to Stephan): import std.array; import std.conv; void main() { dchar c = cast(dchar) 0x10000; auto ws = to!wstring(c); assert(ws.length == 2); // decoded as surrogate pair assert(ws.back == c); // fails with decoding error } This should be added as a unit test, and back(wstring) should get its own implementation.
Comment #1 by andrej.mitrovich — 2013-02-03T13:09:53Z
Works in 2.061. Was a test-case added though? If not it should be put in.
Comment #2 by schveiguy — 2013-02-11T06:58:43Z
It was fixed around June of 2011 by Jonathan Davis. He simply changed the implementation from using an incorrect local algorithm to using std.utf.