1 /* nl_langinfo() replacement: query locale dependent information.
3 Copyright (C) 2007-2010 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #if REPLACE_NL_LANGINFO
25 /* Override nl_langinfo with support for added nl_item values. */
33 rpl_nl_langinfo (nl_item item)
37 # if GNULIB_defined_CODESET
41 static char buf[2 + 10 + 1];
43 locale = setlocale (LC_CTYPE, NULL);
44 if (locale != NULL && locale[0] != '\0')
46 /* If the locale name contains an encoding after the dot, return
48 const char *dot = strchr (locale, '.');
55 /* Look for the possible @... trailer and remove it, if any. */
56 modifier = strchr (dot, '@');
59 if (modifier - dot < sizeof (buf))
61 memcpy (buf, dot, modifier - dot);
62 buf [modifier - dot] = '\0';
70 # if GNULIB_defined_ERA
72 /* The format is not standardized. In glibc it is a sequence of strings
73 of the form "direction:offset:start_date:end_date:era_name:era_format"
74 with an empty string at the end. */
77 /* The %Ex conversion in strftime behaves like %x if the locale does not
78 have an alternative time format. */
82 /* The %Ec conversion in strftime behaves like %c if the locale does not
83 have an alternative time format. */
87 /* The %EX conversion in strftime behaves like %X if the locale does not
88 have an alternative time format. */
92 /* The format is not standardized. In glibc it is a sequence of 10
93 strings, appended in memory. */
94 return "\0\0\0\0\0\0\0\0\0\0";
99 return nl_langinfo (item);
104 /* Provide nl_langinfo from scratch. */
106 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
108 /* Native Windows platforms. */
110 # define WIN32_LEAN_AND_MEAN /* avoid including junk */
111 # include <windows.h>
117 /* An old Unix platform without locales, such as Linux libc5 or BeOS. */
124 nl_langinfo (nl_item item)
128 /* nl_langinfo items of the LC_CTYPE category */
130 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
132 static char buf[2 + 10 + 1];
134 /* Woe32 has a function returning the locale's codepage as a number. */
135 sprintf (buf, "CP%u", GetACP ());
138 # elif defined __BEOS__
143 /* nl_langinfo items of the LC_NUMERIC category */
145 return localeconv () ->decimal_point;
147 return localeconv () ->thousands_sep;
148 /* nl_langinfo items of the LC_TIME category.
149 TODO: Really use the locale. */
152 return "%a %b %e %H:%M:%S %Y";
160 return "%I:%M:%S %p";
244 return "\0\0\0\0\0\0\0\0\0\0";
245 /* nl_langinfo items of the LC_MONETARY category
246 TODO: Really use the locale. */
249 /* nl_langinfo items of the LC_MESSAGES category
250 TODO: Really use the locale. */