Re: Converting Unicode Escape Sequences to UTF-8

2015-10-24 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 24 October 2015 at 08:54:40 UTC, Nordlöw wrote: Working first version at https://github.com/nordlow/justd/blob/master/conv_ex.d#L207 Next I'll make it a range. Made it a range: https://github.com/nordlow/justd/blob/master/conv_ex.d#L207

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-24 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 21:52:05 UTC, anonymous wrote: On 22.10.2015 21:13, Nordlöw wrote: Hmm, why isn't this already in Phobos? Working first version at https://github.com/nordlow/justd/blob/master/conv_ex.d#L207 Next I'll make it a range.

Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
How do I convert a `string` containing Unicode escape sequences such as "\u" into UTF-8?

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread anonymous via Digitalmars-d-learn
On Thursday, October 22, 2015 08:10 PM, Nordlöw wrote: > How do I convert a `string` containing Unicode escape sequences > such as "\u" into UTF-8? Ali explained that "\u" is already UTF-8. But if you actually want to interpret such escape sequences from user input or some such, then

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 19:16:36 UTC, Nordlöw wrote: Can somebody point out in which function/file DMD does this decoding? std.conv.parseEscape includes this logic. But why is it private?

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 18:40:06 UTC, anonymous wrote: On Thursday, October 22, 2015 08:10 PM, Nordlöw wrote: How do I convert a `string` containing Unicode escape sequences such as "\u" into UTF-8? Ali explained that "\u" is already UTF-8. But if you actually want to

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/2015 11:10 AM, Nordlöw wrote: How do I convert a `string` containing Unicode escape sequences such as "\u" into UTF-8? It's already UTF-8 because it's a 'string'. :) import std.stdio; void main() { auto s = "\u1234"; foreach (codeUnit; s) { writefln("%02x %08b",

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 19:13:20 UTC, Nordlöw wrote: * Drop the backslash and the 'u'. * Parse as a hexadecimal integer, and cast to dchar. * Use std.utf.encode to convert to UTF-8. std.conv.to can probably do it too, and possibly simpler, but would allocate. Also be aware of the

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread anonymous via Digitalmars-d-learn
On 22.10.2015 21:13, Nordlöw wrote: Hmm, why isn't this already in Phobos? I think parsing only Unicode escape sequences is not a common task. You usually need to parse some larger language of which escape sequences are only a part. For example, parsing JSON or XML are common tasks, and we