www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10162] New: Opposite of std.string.representation

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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: -------
May 24 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10162




An alternative name for such function is "assumeChars".

And it should return char[], const(char)[] or immutable(char)[] according to
the input being a ubyte[], const(ubyte)[] or immutable(ubyte)[].

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 26 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10162






It could also return wchar[], const(wchar)[], immutable(wchar)[] according to
the input being a ushort[], const(ushort)[] or immutable(ushort)[].

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 26 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10162




Most of my use cases are to sort a char[]. It's a common operation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 03 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10162




See also Issue 11356

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 30 2013