How to know whether a file's encoding is ansi or utf8?

2014-07-22 Thread Sam Hu via Digitalmars-d-learn
Greetings! As subjected,how can I know whether a file is in UTF8 encoding or ansi? Thanks for the help in advance. Regards, Sam

Re: How to know whether a file's encoding is ansi or utf8?

2014-07-22 Thread Sam Hu via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 09:50:00 UTC, Sam Hu wrote: Greetings! As subjected,how can I know whether a file is in UTF8 encoding or ansi? Thanks for the help in advance. Regards, Sam Sorry,I mean by by code,for example,when I try to read a file content and printed to a text control in

Re: fork/waitpid and std.concurrency.spawn

2014-07-22 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 07:58:50 UTC, Puming wrote: Is there a fork()/wait() API similar to std.concurrency spawn()? The best thing I've got so far is module core.sys.posix.unistd.fork(), but it seems to only work in posix. Is there a unified API for process level concurrency? ideally

Re: How to know whether a file's encoding is ansi or utf8?

2014-07-22 Thread Alexandre via Digitalmars-d-learn
Read the BOM ? module main; import std.stdio; enum Encoding { UTF7, UTF8, UTF32, Unicode, BigEndianUnicode, ASCII }; Encoding GetFileEncoding(string fileName) { import std.file; auto bom = cast(ubyte[]) read(fileName, 4);

Re: Calling dynamically bound functions from weakly pure function

2014-07-22 Thread Rene Zwanenburg via Digitalmars-d-learn
On Saturday, 19 July 2014 at 11:12:00 UTC, Marc Schütz wrote: Casting to pure would break purity if the called function is not actually pure. AFAIU, the problem is that the mutable function pointers are not accessible from inside the pure function at all, in which case the solution is to cast

Re: fork/waitpid and std.concurrency.spawn

2014-07-22 Thread Puming via Digitalmars-d-learn
I've only found spawnProcess/spawnShell and the like, which executes a new command, but not a function pointer, like fork() and std.concurrency.spawn does. What is the function that does what I describe? On Tuesday, 22 July 2014 at 10:43:58 UTC, FreeSlave wrote: On Tuesday, 22 July 2014 at

Re: How to know whether a file's encoding is ansi or utf8?

2014-07-22 Thread Sam Hu via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 11:59:34 UTC, Alexandre wrote: Read the BOM ? module main; import std.stdio; enum Encoding { UTF7, UTF8, UTF32, Unicode, BigEndianUnicode, ASCII }; Encoding GetFileEncoding(string fileName) { import std.file;

Re: How to know whether a file's encoding is ansi or utf8?

2014-07-22 Thread FreeSlave via Digitalmars-d-learn
Note that BOMs are optional and may be not presented in Unicode file. Also presence of leading bytes which look BOM does not necessarily mean that file is encoded in some kind of Unicode.

Re: Map one tuple to another Tuple of different type

2014-07-22 Thread Vlad Levenfeld via Digitalmars-d-learn
I'm just confused about how static while is supposed to work because static foreach, to my understanding, would have to work by making a new type for each iteration. I say this because, 1) runtime foreach works like that (with type = range), and 2) without ctfe foreach, the only way I know of

Re: How to know whether a file's encoding is ansi or utf8?

2014-07-22 Thread Alexandre via Digitalmars-d-learn
http://www.architectshack.com/TextFileEncodingDetector.ashx On Tuesday, 22 July 2014 at 15:53:23 UTC, FreeSlave wrote: Note that BOMs are optional and may be not presented in Unicode file. Also presence of leading bytes which look BOM does not necessarily mean that file is encoded in some kind

Re: fork/waitpid and std.concurrency.spawn

2014-07-22 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 14:26:05 UTC, Puming wrote: I've only found spawnProcess/spawnShell and the like, which executes a new command, but not a function pointer, like fork() and std.concurrency.spawn does. What is the function that does what I describe? On Tuesday, 22 July 2014 at

Re: Map one tuple to another Tuple of different type

2014-07-22 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 22, 2014 at 03:52:14PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: I'm just confused about how static while is supposed to work because static foreach, to my understanding, would have to work by making a new type for each iteration. I say this because, 1) runtime foreach

Need help with basic functional programming

2014-07-22 Thread Eric via Digitalmars-d-learn
I have been writing several lexers and parsers. The grammars I need to parse are really complex, and consequently I didn't feel confident about the code quality, especially in the lexers. So I decided to jump on the functional progamming bandwagon to see if that would help. It definitely

Re: Need help with basic functional programming

2014-07-22 Thread bearophile via Digitalmars-d-learn
Eric: while (!buf.empty()) { p++; buf.popFront(); Those () can be omitted, if you mind the noise (but you can also keep them). if (buf.front() = '0' || buf.front() = '9') break; std.ascii.isDigit helps. curTok.image = cast(string) cbuffer[0 .. (p -

Re: Need help with basic functional programming

2014-07-22 Thread anonymous via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 16:50:47 UTC, Eric wrote: private void getNumber(MCInputStreamRange buf) { auto s = buf.until(a = '0' || a = '9'); curTok.kind = Token_t.NUMBER; curTok.image = to!string(s); } The problem is that until seems to not stop at the end of the number, and

Re: Need help with basic functional programming

2014-07-22 Thread Eric via Digitalmars-d-learn
By the way, do you really mean to stop on '0' and '9'? Do you perhaps mean a '0' || a '9'? Yes, my bad...

Re: Need help with basic functional programming

2014-07-22 Thread Eric via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 17:09:29 UTC, bearophile wrote: Eric: while (!buf.empty()) { p++; buf.popFront(); Those () can be omitted, if you mind the noise (but you can also keep them). if (buf.front() = '0' || buf.front() = '9') break; std.ascii.isDigit

Re: Need help with basic functional programming

2014-07-22 Thread via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 17:09:29 UTC, bearophile wrote: Eric: while (!buf.empty()) { p++; buf.popFront(); Those () can be omitted, if you mind the noise (but you can also keep them). Actually, the ones behind `empty` and `front` are wrong, because these are

Re: Map one tuple to another Tuple of different type

2014-07-22 Thread via Digitalmars-d-learn
On Tuesday, 22 July 2014 at 16:42:14 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Jul 22, 2014 at 03:52:14PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: Anyway my actual question is: if all values are constant at compile time, how would a static while loop terminate?

Re: Map one tuple to another Tuple of different type

2014-07-22 Thread Vlad Levenfeld via Digitalmars-d-learn
Yes, though the loop unrolling is news to me. I'll have to keep that in mind next time I'm trying to squeeze some extra performance out of a loop. btw, found a static switch enhancement request here: https://issues.dlang.org/show_bug.cgi?id=6921