April 01, 2012
On 04/01/2012 05:00 AM, Jacob Carlborg wrote:
> On 2012-04-01 01:17, Ali Çehreli wrote:
>> On 03/31/2012 11:53 AM, Ali Çehreli wrote:
>>
>> > The solution is to use ranges when pulling Unicode characters out of
>> > strings. std.stdin does not provide this yet, but it will eventually
>> > happen (so I've heard :)).
>>
>> Here is a Unicode character range, which is unfortunately pretty
>> inefficient because it relies on an exception that is thrown from
>> isValidDchar! :p
>
> Ok, what's the differences compared to the example in your first post:
>
> void main()
> {
> string line = readln();
>
> foreach (dchar c; line) {
> writeln(c);
> }
> }
>

No difference in that example because it consumes the entire input as dchars.

But in general, with that inefficient range, it is possible to pull just one dchar from the input and leave the rest of the stream untouched. For example, it would be possible to readf() an int right after that:

    auto u = byUnicode();

    dchar d = u.front;  // <-- reads just one dchar from the range

    int i;
    readf("%s", &i);    // <-- continues with std.stdio functions
    writeln(i);

With the getline() method, the int must be looked up in the line first, then from the input.

Ali
April 01, 2012
On 2012-04-01 16:02, Ali Çehreli wrote:

> No difference in that example because it consumes the entire input as
> dchars.
>
> But in general, with that inefficient range, it is possible to pull just
> one dchar from the input and leave the rest of the stream untouched. For
> example, it would be possible to readf() an int right after that:
>
> auto u = byUnicode();
>
> dchar d = u.front; // <-- reads just one dchar from the range
>
> int i;
> readf("%s", &i); // <-- continues with std.stdio functions
> writeln(i);
>
> With the getline() method, the int must be looked up in the line first,
> then from the input.
>
> Ali

Ok, I see, thanks.

-- 
/Jacob Carlborg
April 04, 2012
On 2012-03-31 17:56, Jacob Carlborg wrote:
> How would I read a unicode character from the terminal? I've tried using
> "std.cstream.din.getc" but it seems to only work for ascii characters.
> If I try to read and print something that isn't ascii, it just prints a
> question mark.

I solved it like this:

dchar readChar ()
{
    char[4] buffer;

    buffer[0] = din.getc();
    auto len = codeLength!(char)(buffer[0]);

    foreach (i ; 1 .. len)
        buffer[i] = din.getc();

    size_t i;
    return decode(buffer, i);
}

-- 
/Jacob Carlborg
April 04, 2012
On 31/03/2012 23:14, Stewart Gordon wrote:
<snip>
> You might want to try the console module in my utility library:
>
> http://pr.stewartsplace.org.uk/d/sutil/
>
> (For D1 at the moment, but a D2 version will be available any day now!)

The D2 version is now up on the site.

Jacob - would you be up for helping me with testing/implementation of my library on Mac OS?  If you do a search for "todo" you'll see what needs to be done.  Some of it will benefit Unix-type systems generally.  If perchance you have a big-endian CPU, testing the bit arrays on it would also be of value.

Stewart.
April 04, 2012
On 2012-04-04 18:06, Stewart Gordon wrote:

> The D2 version is now up on the site.
>
> Jacob - would you be up for helping me with testing/implementation of my
> library on Mac OS? If you do a search for "todo" you'll see what needs
> to be done. Some of it will benefit Unix-type systems generally. If
> perchance you have a big-endian CPU, testing the bit arrays on it would
> also be of value.
>
> Stewart.

Sure I can help you with testing. I have a lot on my own table so I don't have any time for implementing things (maybe some small things). If I may ask, what is the point of this library? Doesn't it duplicate functionally that's already available in Phobos and/or Tango?

For Mac OS X, if you just follow the Posix standard you'll get very far.

I have an x86 CPU, there were a couple of years ago since Apple last had a PPC based computer.

-- 
/Jacob Carlborg
April 04, 2012
On 04/04/2012 17:37, Jacob Carlborg wrote:
<snip>
> Sure I can help you with testing. I have a lot on my own table so I don't have any time
> for implementing things (maybe some small things). If I may ask, what is the point of this
> library?

Just to hold some miscellaneous utility classes/structs/functions.

> Doesn't it duplicate functionally that's already available in Phobos and/or Tango?
<snip>

It certainly does in places.  But what matters is that it contains functionality that isn't present in Phobos (or wasn't present in Phobos at the time I wrote it).

Stewart.
April 05, 2012
On 2012-04-05 01:21, Stewart Gordon wrote:
> On 04/04/2012 17:37, Jacob Carlborg wrote:
> <snip>
>> Sure I can help you with testing. I have a lot on my own table so I
>> don't have any time
>> for implementing things (maybe some small things). If I may ask, what
>> is the point of this
>> library?
>
> Just to hold some miscellaneous utility classes/structs/functions.
>
>> Doesn't it duplicate functionally that's already available in Phobos
>> and/or Tango?
> <snip>
>
> It certainly does in places. But what matters is that it contains
> functionality that isn't present in Phobos (or wasn't present in Phobos
> at the time I wrote it).
>
> Stewart.

Ok, I see. The functions that need a Posix implementation are mostly in datetime and commandline, if I recall correctly. These are already present in Phobos?

-- 
/Jacob Carlborg
April 05, 2012
On 05/04/2012 07:18, Jacob Carlborg wrote:
<snip>
> Ok, I see. The functions that need a Posix implementation are mostly in datetime and
> commandline, if I recall correctly. These are already present in Phobos?

Maybe it contains the code I need to finish datetime off.  Though I can't really just copy someone else's code, I suppose I can at least see what functions it uses.

I haven't noticed much along the lines of command line manipulation in Phobos - only the code (now in druntime) to populate the args argument to main (which under Posix it just uses argc/argv from the C main).  Or is there something I haven't found?

Stewart.
April 05, 2012
On 2012-04-05 12:55, Stewart Gordon wrote:
> On 05/04/2012 07:18, Jacob Carlborg wrote:
> <snip>
>> Ok, I see. The functions that need a Posix implementation are mostly
>> in datetime and
>> commandline, if I recall correctly. These are already present in Phobos?
>
> Maybe it contains the code I need to finish datetime off. Though I can't
> really just copy someone else's code, I suppose I can at least see what
> functions it uses.
>
> I haven't noticed much along the lines of command line manipulation in
> Phobos - only the code (now in druntime) to populate the args argument
> to main (which under Posix it just uses argc/argv from the C main). Or
> is there something I haven't found?
>
> Stewart.

http://dlang.org/phobos/std_getopt.html

But it might not do what you want.

-- 
/Jacob Carlborg
April 07, 2012
On 05/04/2012 14:51, Jacob Carlborg wrote:
<snip>
> http://dlang.org/phobos/std_getopt.html
>
> But it might not do what you want.

Where is the code in std.getopt that has any relevance whatsoever to what smjg.libs.util.datetime or smjg.libs.util.commandline is for?

Stewart.