Solved

Cross-platform code page identifier.

Posted on 2003-11-12
5
418 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

895 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

19 Experts available now in Live!

Get 1:1 Help Now