digitalmars.D - Rune strings. Like in Go.
- Alexey (1/1) Sep 30 2021 Can we have them in D? :)
- Paul Backus (3/4) Sep 30 2021 We have them already. :) What Go calls a "rune" is called a
- Alexey (7/11) Sep 30 2021 Go's runes and D's dchars - have different behavior.
- H. S. Teoh (11/25) Sep 30 2021 This is not true. D strings are autodecoded with Phobos range functions,
- jfondren (28/31) Sep 30 2021 You're explicitly asking for a byte cast and instead of a byte
- Basile B. (2/3) Sep 30 2021 do you want a verbatim about runs on IRC ?
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/4) Sep 30 2021 Looks like Go "could" have them. ;)
On Thursday, 30 September 2021 at 20:44:54 UTC, Alexey wrote:Can we have them in D? :)We have them already. :) What Go calls a "rune" is called a `dchar` in D, and a string of them is a `dchar[]`.
Sep 30 2021
On Thursday, 30 September 2021 at 20:57:34 UTC, Paul Backus wrote:On Thursday, 30 September 2021 at 20:44:54 UTC, Alexey wrote:Go's runes and D's dchars - have different behavior. Go's rune string, being converted to byte array like so `[]byte(string_var)` and saved to file - results in UTF-8, while dchar is UTF-32. this means - the frequent conversions between string and dstring in D is required for confortable work with unicode.Can we have them in D? :)We have them already. :) What Go calls a "rune" is called a `dchar` in D, and a string of them is a `dchar[]`.
Sep 30 2021
On Thu, Sep 30, 2021 at 10:47:25PM +0000, Alexey via Digitalmars-d wrote:On Thursday, 30 September 2021 at 20:57:34 UTC, Paul Backus wrote:This is not true. D strings are autodecoded with Phobos range functions, i.e., if you iterate over a string with Phobos, you will get a stream of dchars without having to convert the encoding. (Ironically enough, autodecoding is regarded as a bad thing!) Also, IIRC, writing a stream of dchars to a string sink, e.g., appender!string, will automatically encode into UTF-8, so no explicit conversion is needed afterwards. T -- If you look at a thing nine hundred and ninety-nine times, you are perfectly safe; if you look at it the thousandth time, you are in frightful danger of seeing it for the first time. -- G. K. ChestertonOn Thursday, 30 September 2021 at 20:44:54 UTC, Alexey wrote:Go's runes and D's dchars - have different behavior. Go's rune string, being converted to byte array like so `[]byte(string_var)` and saved to file - results in UTF-8, while dchar is UTF-32. this means - the frequent conversions between string and dstring in D is required for confortable work with unicode.Can we have them in D? :)We have them already. :) What Go calls a "rune" is called a `dchar` in D, and a string of them is a `dchar[]`.
Sep 30 2021
On Thursday, 30 September 2021 at 22:47:25 UTC, Alexey wrote:Go's rune string, being converted to byte array like so `[]byte(string_var)` and saved to file - results in UTF-8, while dchar is UTF-32.You're explicitly asking for a byte cast and instead of a byte cast you get a reencoding? You might prefer that because it's familiar, but that's a really confusing thing to do. `std.string.representation` meanwhile turns a `dchar[]` into an `uint[]`. And to get UTF-8 in a file, just write the string: ```d import std; void write() { string noel = "no\u0308el"; dstring dstr = noel.toUTF32; File("a", "w").writeln(noel); File("b", "w").writeln(dstr); } void main() { write; ubyte[] fromA = cast(ubyte[]) read("a"); ubyte[] fromB = cast(ubyte[]) read("b"); assert(fromA == fromB); writeln(fromA, "\n", fromB); } ``` output: ``` [110, 111, 204, 136, 101, 108, 10] [110, 111, 204, 136, 101, 108, 10] ```
Sep 30 2021
On Thursday, 30 September 2021 at 20:44:54 UTC, Alexey wrote:Can we have them in D? :)do you want a verbatim about runs on IRC ?
Sep 30 2021
On 9/30/21 1:44 PM, Alexey wrote:Can we have them in D? :)Looks like Go "could" have them. ;) Ali
Sep 30 2021