Solved

Cross-platform code page identifier.

Posted on 2003-11-12
5
417 Views
Last Modified: 2010-04-15
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.
0
Comment
Question by:frogger1999
5 Comments
 
LVL 17

Accepted Solution

by:
rstaveley earned 250 total points
ID: 9740091
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
 
LVL 5

Assisted Solution

by:g0rath
g0rath earned 250 total points
ID: 9740150

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Eclipse Luna does not see MinGW 5 234
libcurl and C++ - Post JSON Data 8 1,075
C++ vs C compilers 13 155
Problem to scan all sheets 3 82
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now