Jump to page: 1 2
Thread overview
I can ask questions about dmd on windows here in this forum?
Aug 31, 2014
Cassio Butrico
Aug 31, 2014
Vladimir Panteleev
Aug 31, 2014
Cassio Butrico
Aug 31, 2014
Ali Çehreli
Aug 31, 2014
Cassio Butrico
Aug 31, 2014
Ali Çehreli
Aug 31, 2014
Cassio Butrico
Aug 31, 2014
bearophile
Aug 31, 2014
Ali Çehreli
Aug 31, 2014
Jonathan M Davis
Sep 02, 2014
Kagamin
Sep 02, 2014
Cassio Butrico
Sep 02, 2014
Cassio Butrico
August 31, 2014
I'm new to this language, and I wonder if I will have some support simple questions.
Thank you for your attention.

August 31, 2014
On Sunday, 31 August 2014 at 03:16:38 UTC, Cassio Butrico wrote:
> I'm new to this language, and I wonder if I will have some support simple questions.
> Thank you for your attention.

Yes.
August 31, 2014
On Sunday, 31 August 2014 at 03:20:00 UTC, Vladimir Panteleev wrote:
> On Sunday, 31 August 2014 at 03:16:38 UTC, Cassio Butrico wrote:
>> I'm new to this language, and I wonder if I will have some support simple questions.
>> Thank you for your attention.
>
> Yes.

My question is about wstring and dstring,
which and the best way to input data, converting and which should I use
August 31, 2014
On 08/30/2014 08:37 PM, Cassio Butrico wrote:

> My question is about wstring and dstring,
> which and the best way to input data, converting and which should I use

Unless there is a specific reason not to, use 'string'. When you really need random access to characters, then use 'dstring'.

To input data, readf() is for formatted input:

    int i;
    readf(" %s", &i);

When reading a whole line as a string, consider

import std.stdio;
import std.string;

// ...

    string line = chomp(readln());

Ali

August 31, 2014
On Sunday, 31 August 2014 at 05:27:15 UTC, Ali Çehreli wrote:
> On 08/30/2014 08:37 PM, Cassio Butrico wrote:
>
> > My question is about wstring and dstring,
> > which and the best way to input data, converting and which
> should I use
>
> Unless there is a specific reason not to, use 'string'. When you really need random access to characters, then use 'dstring'.
>
> To input data, readf() is for formatted input:
>
>     int i;
>     readf(" %s", &i);
>
> When reading a whole line as a string, consider
>
> import std.stdio;
> import std.string;
>
> // ...
>
>     string line = chomp(readln());
>
> Ali
Thanks so much for answering me.
I was having trouble setting on my terminal in windows, I'm still trying to solve.
August 31, 2014
On 08/30/2014 10:37 PM, Cassio Butrico wrote:

> I was having trouble setting on my terminal in windows, I'm still trying
> to solve.

In addition to what Vladimir Panteleev said, you should also select a Unicode font for your terminal like Lucida Console.

Basically:

1) Set the code page to 65001 by

    chcp 65001

2) Select a Unicode font from the console window's menu.

You can set those two for the entire system. (I don't remember how.)

As Vladimir Panteleev said, you can set both of those from inside each program as well.

Ali

August 31, 2014
On Sunday, 31 August 2014 at 06:08:46 UTC, Ali Çehreli wrote:
> On 08/30/2014 10:37 PM, Cassio Butrico wrote:
>
>> I was having trouble setting on my terminal in windows, I'm still trying
>> to solve.
>
> In addition to what Vladimir Panteleev said, you should also select a Unicode font for your terminal like Lucida Console.
>
> Basically:
>
> 1) Set the code page to 65001 by
>
>     chcp 65001
>
> 2) Select a Unicode font from the console window's menu.
>
> You can set those two for the entire system. (I don't remember how.)
>
> As Vladimir Panteleev said, you can set both of those from inside each program as well.
>
> Ali
Ali Çehreli you is very attentive, answering for me.
I do not know how to use SetConsoleCP or SetConsoleOutputCP on a progrtama in d.
I'll try to find out.
August 31, 2014
Ali Çehreli:

> Unless there is a specific reason not to, use 'string'. When you really need random access to characters, then use 'dstring'.

So are the use cases for wstring limited?

Bye,
bearophile
August 31, 2014
On 08/31/2014 12:37 AM, bearophile wrote:
> Ali Çehreli:
>
>> Unless there is a specific reason not to, use 'string'. When you
>> really need random access to characters, then use 'dstring'.
>
> So are the use cases for wstring limited?
>
> Bye,
> bearophile

Yes, without real experience, I am under that impression. Let's see:

- char is UTF-8. UTF-8 is a variable-length encoding, from 1 up to 6 bytes per character.

- wchar is UTF-16. UTF-16 is a variable-length encoding, 2 or 4 bytes per character.

- dchar is UTF-32. UTF-32 is a fixed-length encoding, exactly 4 bytes per characters.

As I understand it, wchar would make sense when UTF-8 would take considerably more space than UTF-16 for a given text. Another case is when a wchar array is guaranteed to consist solely of 2-byte characters; it can then safely be used as a random access range.

In contrast, a dchar array provides random access for any text but takes up more space for certain text than UTF-8 and UTF-16 (e.g. text consisting mostly of 1-byte characters in UTF-8 (e.g. ASCII)).

So yes, wchar has limited use compared to the others.

Ali

August 31, 2014
On Sun, 31 Aug 2014 01:11:02 -0700
Ali Çehreli via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> On 08/31/2014 12:37 AM, bearophile wrote:
> > Ali Çehreli:
> >
> >> Unless there is a specific reason not to, use 'string'. When you really need random access to characters, then use 'dstring'.
> >
> > So are the use cases for wstring limited?
> >
> > Bye,
> > bearophile
>
> Yes, without real experience, I am under that impression. Let's see:
>
> - char is UTF-8. UTF-8 is a variable-length encoding, from 1 up to 6 bytes per character.
>
> - wchar is UTF-16. UTF-16 is a variable-length encoding, 2 or 4 bytes per character.
>
> - dchar is UTF-32. UTF-32 is a fixed-length encoding, exactly 4 bytes per characters.
>
> As I understand it, wchar would make sense when UTF-8 would take considerably more space than UTF-16 for a given text. Another case is when a wchar array is guaranteed to consist solely of 2-byte characters; it can then safely be used as a random access range.
>
> In contrast, a dchar array provides random access for any text but
> takes up more space for certain text than UTF-8 and UTF-16 (e.g. text
> consisting mostly of 1-byte characters in UTF-8 (e.g. ASCII)).
>
> So yes, wchar has limited use compared to the others.

The main use case for an array of wchar is to interact with Windows functions which use UTF-16. There may be rare cases to use it otherwise, but the average D program should just use string unless it needs random-access, in which case, it should use dstring. wstring is ultimately of marginal use.

- Jonathan M Davis

« First   ‹ Prev
1 2