- Subject: Re: iconv module documentation or examples?
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Sat, 30 Aug 2008 16:24:07 -0400
Ethan Blanton <eblanton@xxxxxxxxxxxx> wrote:
> I'm not sure if this is what you want, but ...
>
> #include <langinfo.h>
>
> char *nl_langinfo(nl_item item);
>
> If you pass CODESET as the argument to this function, it should give
> you back the character encoding used by the active locale. This
> function will give you most of the information you would retrieve with
> the locale(1) query commands.
[4:16pm] /tmp>cat foo.c
#include <stdio.h>
#include <locale.h>
#include <langinfo.h>
int main ()
{
setlocale (LC_ALL, "");
fprintf (stdout, "%s\n", nl_langinfo(CODESET));
return 0;
}
[4:16pm] /tmp>gcc foo.c
[4:17pm] /tmp>./a.out
UTF-8
[4:17pm] /tmp>printenv LANG
en_US.UTF-8
For this reason, I think that something like this might work:
define get_encoding ()
{
if (_slang_utf8_ok) return "UTF-8";
variable lang = getenv ("LANG");
if (lang == NULL)
return NULL;
variable fields = strchop (lang, '.', 0);
if (2 == length (fields))
return fields[1];
return NULL;
}
Thanks,
--John
--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.
[2008 date index]
[2008 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]