[Issue 9131] New: Invalid UTF-8 when using std.algorithm.equal with dstring and string
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Dec 9 21:57:13 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9131
Summary: Invalid UTF-8 when using std.algorithm.equal with
dstring and string
Product: D
Version: D2
Platform: x86_64
OS/Version: Mac OS X
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: hsteoh at quickfur.ath.cx
--- Comment #0 from hsteoh at quickfur.ath.cx 2012-12-09 21:57:11 PST ---
This is found by the autotester with
https://github.com/D-Programming-Language/phobos/pull/987. As I have no access
to OSX/64, I have no way to reduce the failing case:
auto joiner(RoR)(RoR r)
if (isInputRange!RoR && isInputRange!(ElementType!RoR))
{
static struct Result
{
private:
RoR _items;
ElementType!RoR _current;
void prepare()
{
// Skip over empty subranges.
if (_items.empty) return;
while (_items.front.empty)
{
_items.popFront();
if (_items.empty) return;
}
_current = _items.front;
}
public:
this(RoR r)
{
_items = r;
prepare();
}
static if (isInfinite!RoR)
{
enum bool empty = false;
}
else
{
@property auto empty()
{
return _items.empty;
}
}
@property auto ref front()
{
assert(!empty);
return _current.front;
}
void popFront()
{
assert(!_current.empty);
_current.popFront();
if (_current.empty)
{
assert(!_items.empty);
_items.popFront();
prepare();
}
}
static if (isForwardRange!RoR && isForwardRange!(ElementType!RoR))
{
@property auto save()
{
Result copy;
copy._items = _items.save;
copy._current = _current.save;
return copy;
}
}
}
return Result(r);
}
unittest
{
struct TransientRange
{
dchar[128] _buf;
dstring[] _values;
this(dstring[] values)
{
_values = values;
}
@property bool empty()
{
return _values.length == 0;
}
@property auto front()
{
foreach (i; 0 .. _values.front.length)
{
_buf[i] = _values[0][i];
}
return _buf[0 .. _values.front.length];
}
void popFront()
{
_values = _values[1 .. $];
}
}
auto rr = TransientRange(["abc"d, "12"d, "def"d, "34"d]);
// Can't use array() or equal() directly because they fail with transient
// .front.
dchar[] result;
foreach (c; rr.joiner()) {
result ~= c;
}
assert(equal(result, "abc12def34"),
"Unexpected result: '%s'".format(result));
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list