www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Character set conversions

reply Kagamin <spam here.lot> writes:
Daniel Gibson Wrote:

 Am 31.05.2011 09:02, schrieb Kagamin:
 Daniel Gibson Wrote:
 
 In plain C (at least on Linux) you have fun locale-dependent in/output
 as well: printf and scanf are locale dependent, so if you use sprintf
 to generate a string you'll write into a file (or fprintf directly) with
 one locale, reading it with scanf functions with another locale will fail.
 Pretty fucking stupid IMHO.

Doesn't C standard specify the locale to be "C" until you set it explicitly?

At least on Linux it is usually set to whatever you specified on installation (usually you just say "I want a german/english/whatever installation" and the installer then sets the locales to de_DE.UTF8 or whatever). Applications use these settings to decide the language of their menus etc

according to N1425 7.11.1.1 4. At program startup, the equivalent of setlocale(LC_ALL, "C"); is executed. Fun fact is MS conforms with this specification.
May 31 2011
parent reply Daniel Gibson <metalcaedes gmail.com> writes:
Am 31.05.2011 09:12, schrieb Kagamin:
 Daniel Gibson Wrote:
 
 Am 31.05.2011 09:02, schrieb Kagamin:
 Daniel Gibson Wrote:

 In plain C (at least on Linux) you have fun locale-dependent in/output
 as well: printf and scanf are locale dependent, so if you use sprintf
 to generate a string you'll write into a file (or fprintf directly) with
 one locale, reading it with scanf functions with another locale will fail.
 Pretty fucking stupid IMHO.

Doesn't C standard specify the locale to be "C" until you set it explicitly?

At least on Linux it is usually set to whatever you specified on installation (usually you just say "I want a german/english/whatever installation" and the installer then sets the locales to de_DE.UTF8 or whatever). Applications use these settings to decide the language of their menus etc

according to N1425 7.11.1.1 4. At program startup, the equivalent of setlocale(LC_ALL, "C"); is executed. Fun fact is MS conforms with this specification.

So they break it deliberately in Excel? Smart.
May 31 2011
parent reply Kagamin <spam here.lot> writes:
Daniel Gibson Wrote:

 according to N1425
 7.11.1.1
 4. At program startup, the equivalent of
 setlocale(LC_ALL, "C");
 is executed.
 
 Fun fact is MS conforms with this specification.

So they break it deliberately in Excel? Smart.

Excel deliberately localizes data presented to the user. Wouldn't it be strange for user to work with C locale (Excel users aren't programmers)? It even translates builtin function names :) As this presentation is quite customizable, I doubt it's done by c runtime. I think it just gets string values from cells during CSV generation.
May 31 2011
parent reply Daniel Gibson <metalcaedes gmail.com> writes:
Am 31.05.2011 13:12, schrieb Kagamin:
 Daniel Gibson Wrote:
 
 according to N1425
 7.11.1.1
 4. At program startup, the equivalent of
 setlocale(LC_ALL, "C");
 is executed.

 Fun fact is MS conforms with this specification.

So they break it deliberately in Excel? Smart.

Excel deliberately localizes data presented to the user. Wouldn't it be strange for user to work with C locale (Excel users aren't programmers)? It even translates builtin function names :)

I'm not talking about representing the values on the screen - I'm talking about the format of CSV files. And I find translated function names pretty strange.. I'm wondering how well that works when opening a file with another locale etc.
 As this presentation is quite customizable, I doubt it's done by c runtime. I
think it just gets string values from cells during CSV generation.

May 31 2011
next sibling parent reply Kagamin <spam here.lot> writes:
Daniel Gibson Wrote:

 I'm not talking about representing the values on the screen - I'm
 talking about the format of CSV files.
 And I find translated function names pretty strange.. I'm wondering how
 well that works when opening a file with another locale etc.

Isn't it natural to get string from a cell and put it into the output CSV stream? UI also gets string from a cell and presents it.
 As this presentation is quite customizable, I doubt it's done by c runtime. I
think it just gets string values from cells during CSV generation.


May 31 2011
parent Daniel Gibson <metalcaedes gmail.com> writes:
Am 31.05.2011 14:54, schrieb Kagamin:
 Daniel Gibson Wrote:
 
 I'm not talking about representing the values on the screen - I'm
 talking about the format of CSV files.
 And I find translated function names pretty strange.. I'm wondering how
 well that works when opening a file with another locale etc.

Isn't it natural to get string from a cell and put it into the output CSV stream? UI also gets string from a cell and presents it.

It's natural to have an internal representation of the value of a field and different representations in the UI (this could be dependent on locale settings etc) and for saving it on the disk (this should really not depend on a locale, but be portable). Ideally the different representations can be converted to each other in a lossless way. So the representation on the disk (as CSV, .xls, XML, whatever) doesn't have to match the screen representation.
 
 As this presentation is quite customizable, I doubt it's done by c runtime. I
think it just gets string values from cells during CSV generation.



May 31 2011
prev sibling parent reply Kagamin <spam here.lot> writes:
Daniel Gibson Wrote:

 And I find translated function names pretty strange.. I'm wondering how
 well that works when opening a file with another locale etc.

I've checked excel 2007, seems like it stores (in xlsx) numbers and function names in locale independent form. Don't know, how it works in older versions.
May 31 2011
parent Daniel Gibson <metalcaedes gmail.com> writes:
Am 31.05.2011 15:02, schrieb Kagamin:
 Daniel Gibson Wrote:
 
 And I find translated function names pretty strange.. I'm wondering how
 well that works when opening a file with another locale etc.

I've checked excel 2007, seems like it stores (in xlsx) numbers and function names in locale independent form. Don't know, how it works in older versions.

Ok. Everything else would be a really unusable mess, especially for international companies.
May 31 2011