[Issue 10162] New: Opposite of std.string.representation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 24 05:21:03 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10162

           Summary: Opposite of std.string.representation
           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 2013-05-24 05:21:01 PDT ---
I suggest to add to Phobos a simple (unsafe) function that does the opposite of
std.string.representation.


An use case is for sorting an array of chars. sort() can't be used on a char[],
so you have to conver it to ubyte[] with "representation", but later often you
want an array of chars again):

char[] word = ...;
immutable key =
word.representation.sort().release.unrepresentation.assumeUnique;

Or if you start with a word:

string word = ...;
immutable key =
word.dup.representation.sort().release.unrepresentation.assumeUnique;


Such "unrepresentation" function is not safe. If you want to make it a bit
safer its post-condition can run std.utf.validate on the result in non-release
mode.

-- 
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