[Issue 7281] New: std.string.reversed
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 12 10:47:03 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7281
Summary: std.string.reversed
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-01-12 10:47:00 PST ---
I suggest to add a reversed() function to std.string (the "-ed" suffix is a
Python convention that means it's not an in-place function. It creates a copy
of the input data, works on it, and returns it):
import std.stdio, std.algorithm, std.traits;
immutable(T)[] reversed(T)(immutable(T[]) s)
@safe pure /*nothrow*/ if (isSomeChar!T) {
auto sr = s.dup; // druntime BUG not nothrow
sr.reverse();
return sr; // Implicit immutable cast because it's pure.
}
unittest {
assert("red".reversed() == "der"); // UTF-8
assert("red"w.reversed() == "der"); // UTF-16
assert("red"d.reversed() == "der"); // UTF-32
}
It's not nothrow yet because someArray.dup is not nothrow yet.
--
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