Re: Sort characters in string

2017-12-07 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 15:12:22 UTC, Steven Schveighoffer wrote: On 12/6/17 4:34 AM, Ola Fosheim Grøstad wrote: On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M Davis wrote: UTF-32 on the other hand is guaranteed to have a code unit be a full code point. I don't think the

Re: Sort characters in string

2017-12-07 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:34:48 UTC, Ola Fosheim Grøstad wrote: On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M Davis wrote: UTF-32 on the other hand is guaranteed to have a code unit be a full code point. I don't think the standard says that? Isn't this only because the

Re: Sort characters in string

2017-12-07 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M Davis wrote: a full code point (IIRC, 1 - 6 code units for UTF-8 and 1 - 2 for UTF-16), YDNRC, 1 - 4 code units for UTF-8. Unicode is defined only up to U+10. Everything above is illegal.

Re: Sort characters in string

2017-12-07 Thread Mengu via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 12:43:09 UTC, Fredrik Boulund wrote: On Wednesday, 6 December 2017 at 10:42:31 UTC, Dgame wrote: Or you simply do writeln("longword".array.sort); This is so strange. I was dead sure I tried that but it failed for some reason. But after trying it

Re: Sort characters in string

2017-12-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 06, 2017 at 10:32:03AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 12/06/2017 04:43 AM, Fredrik Boulund wrote: > > On Wednesday, 6 December 2017 at 10:42:31 UTC, Dgame wrote: > > > >> > >> Or you simply do > >> > >> writeln("longword".array.sort); > >> > > > >

Re: Sort characters in string

2017-12-06 Thread Ali Çehreli via Digitalmars-d-learn
On 12/06/2017 04:43 AM, Fredrik Boulund wrote: > On Wednesday, 6 December 2017 at 10:42:31 UTC, Dgame wrote: > >> >> Or you simply do >> >> writeln("longword".array.sort); >> > > This is so strange. I was dead sure I tried that but it failed for some > reason. But after trying it just

Re: Sort characters in string

2017-12-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/6/17 4:34 AM, Ola Fosheim Grøstad wrote: On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M Davis wrote: UTF-32 on the other hand is guaranteed to have a code unit be a full code point. I don't think the standard says that? Isn't this only because the current set is small enough

Re: Sort characters in string

2017-12-06 Thread Fredrik Boulund via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 10:42:31 UTC, Dgame wrote: Or you simply do writeln("longword".array.sort); This is so strange. I was dead sure I tried that but it failed for some reason. But after trying it just now it also seems to work just fine. Thanks! :)

Re: Sort characters in string

2017-12-06 Thread Dgame via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:25:20 UTC, Biotronic wrote: On Wednesday, 6 December 2017 at 08:59:09 UTC, Fredrik Boulund wrote: string word = "longword"; writeln(sort(word)); But that doesn't work because I guess a string is not the type of range required for sort? Yeah, narrow

Re: Sort characters in string

2017-12-06 Thread Fredrik Boulund via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:25:20 UTC, Biotronic wrote: In addition, sort does in-place sorting, so the input range is changed. Since D strings are immutable(char)[], changing the elements is disallowed. So in total, you'll need to convert from a string (immutable(char)[]) to a

Re: Sort characters in string

2017-12-06 Thread Fredrik Boulund via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M Davis wrote: If you have a string, and you _know_ that it's only ASCII, then either use representation or byCodeUnit to wrap it for the call to sort, but it _will_ have to be mutable, so string won't actually work. e.g. char[] str =

Re: Sort characters in string

2017-12-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, December 06, 2017 09:34:48 Ola Fosheim Grøstad via Digitalmars-d-learn wrote: > On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M Davis > > wrote: > > UTF-32 on the other hand is guaranteed to have a code unit be a > > full code point. > > I don't think the standard says

Re: Sort characters in string

2017-12-06 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M Davis wrote: UTF-32 on the other hand is guaranteed to have a code unit be a full code point. I don't think the standard says that? Isn't this only because the current set is small enough to fit? So this may change as Unicode grows?

Re: Sort characters in string

2017-12-06 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 08:59:09 UTC, Fredrik Boulund wrote: string word = "longword"; writeln(sort(word)); But that doesn't work because I guess a string is not the type of range required for sort? Yeah, narrow (non-UTF-32) strings are not random-access, since characters like 

Re: Sort characters in string

2017-12-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, December 06, 2017 08:59:09 Fredrik Boulund via Digitalmars-d- learn wrote: > Hi, > > I'm having some trouble sorting the individual characters in a > string. Searching around, I found this thread > (http://forum.dlang.org/post/mailman.612.1331659665.4860.digitalmars-d-lea >

Sort characters in string

2017-12-06 Thread Fredrik Boulund via Digitalmars-d-learn
Hi, I'm having some trouble sorting the individual characters in a string. Searching around, I found this thread (http://forum.dlang.org/post/mailman.612.1331659665.4860.digitalmars-d-le...@puremagic.com) about a similar issue, but it feels quite old so I wanted to check if there is a clear