• C

Cross-platform code page identifier.

I need a way to record the default (encoding) codepage for text and store this off in a file.  This must work on windows, Mac OS X and Linux/Solaris.

Ideally they would be comparable to each other, but, if the identifier is only comparable to other "codepages" on the same system, that is, Windows to Windows, Mac to Mac, etc, then that will be okay too.

In other words, I just need to know how on each platform to get the current default codepage for text input.  Ideally, I would like to store this in a platform agnostic way.

I don't necessarily need code snippets, just pointers to web resources, that basically outline how to do this for each platform...

Anyway, I hope someone can help.
LVL 1
frogger1999Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rstaveleyCommented:
In a Win32 console, you can use the command "chcp" to get the codepage. I'm really up to speed on i18n (I hope a more knowledgeable expert chips in), but I don't think life is so easy on other platforms.

You are probably best off reading the locale from getenv("LANG") on POSIX systems, and using a look-up to get the codepage e.g. http://www.cryer.co.uk/brian/windows/info_windows_locale_table.htm. Having said that, I've just spotted from chcp on my Windows XP PC that my codepage is 437 and yet my locale is en-gb/en_GB which ought to have a codepage of 1252/850 ... so perhaps there's more to this :-(
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
g0rathCommented:

linux:

#include <locale.h>

setlocale(LC_ALL, NULL); // Returns current locale
setlocale(LC_ALL,"C");
setlocale(LC_ALL,"POSIX");

LC_ALL
    for all of the locale.
LC_COLLATE
    for regular expression matching (it determines the meaning of range expressions and equivalence classes) and string
    collation.
LC_CTYPE
    for regular expression matching, character classification, conversion, case-sensitive comparison, and wide character    
    functions.
LC_MESSAGES
    for localizable natural-language messages.
LC_MONETARY
    for monetary formatting.
LC_NUMERIC
    for number formatting (such as the decimal point and the thousands separator).
LC_TIME
    for time and date formatting.


getenv("LANG");
getenv("LC_ALL");

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.