Solved

Cross-platform code page identifier.

Posted on 2003-11-12
5
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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.

726 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