build/stlport/src/c_locale_glibc/c_locale_glibc2.c

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 #include <locale.h>
michael@0 2 #include <langinfo.h>
michael@0 3 #include <stdio.h>
michael@0 4 #include <stdlib.h>
michael@0 5 #include <wctype.h>
michael@0 6 #include <string.h>
michael@0 7 #include <stdint.h>
michael@0 8
michael@0 9 static const char *_empty_str = "";
michael@0 10 static const char *_C_name = "C";
michael@0 11
michael@0 12 static wchar_t* _ToWChar(const char* buf, wchar_t *wbuf, size_t wbufSize) {
michael@0 13 wchar_t *wcur = wbuf;
michael@0 14 wchar_t *wend = wbuf + wbufSize - 1;
michael@0 15 for (; wcur != wend && *buf != 0; ++buf, ++wcur)
michael@0 16 *wcur = *buf;
michael@0 17 *wcur = 0;
michael@0 18 return wbuf;
michael@0 19 }
michael@0 20
michael@0 21 #if 0
michael@0 22 struct _Locale_ctype
michael@0 23 {
michael@0 24 locale_t __cloc;
michael@0 25 };
michael@0 26
michael@0 27 struct _Locale_numeric
michael@0 28 {
michael@0 29 locale_t __cloc;
michael@0 30 };
michael@0 31
michael@0 32 struct _Locale_time
michael@0 33 {
michael@0 34 locale_t __cloc;
michael@0 35 };
michael@0 36
michael@0 37 struct _Locale_collate
michael@0 38 {
michael@0 39 locale_t __cloc;
michael@0 40 };
michael@0 41
michael@0 42 struct _Locale_monetary
michael@0 43 {
michael@0 44 locale_t __cloc;
michael@0 45 };
michael@0 46
michael@0 47 struct _Locale_messages
michael@0 48 {
michael@0 49 locale_t __cloc;
michael@0 50 };
michael@0 51 #endif
michael@0 52
michael@0 53 void _Locale_init()
michael@0 54 {}
michael@0 55
michael@0 56 void _Locale_final()
michael@0 57 {}
michael@0 58
michael@0 59 struct _Locale_ctype *_Locale_ctype_create(const char *nm, struct _Locale_name_hint* hint,
michael@0 60 int *__err_code) {
michael@0 61 *__err_code = _STLP_LOC_UNKNOWN_NAME;
michael@0 62 return (struct _Locale_ctype*)newlocale(LC_CTYPE_MASK, nm, NULL);
michael@0 63 }
michael@0 64
michael@0 65 struct _Locale_codecvt *_Locale_codecvt_create(const char *nm, struct _Locale_name_hint* hint,
michael@0 66 int *__err_code) {
michael@0 67 // Glibc do not support multibyte manipulation for the moment, it simply implements "C".
michael@0 68 if (nm[0] == 'C' && nm[1] == 0)
michael@0 69 { return (struct _Locale_codecvt*)0x01; }
michael@0 70 *__err_code = _STLP_LOC_NO_PLATFORM_SUPPORT; return 0;
michael@0 71 }
michael@0 72
michael@0 73 struct _Locale_numeric *_Locale_numeric_create(const char *nm, struct _Locale_name_hint* hint,
michael@0 74 int *__err_code) {
michael@0 75 *__err_code = _STLP_LOC_UNKNOWN_NAME;
michael@0 76 return (struct _Locale_numeric*)newlocale(LC_NUMERIC_MASK, nm, NULL);
michael@0 77 }
michael@0 78
michael@0 79 struct _Locale_time *_Locale_time_create(const char *nm, struct _Locale_name_hint* hint,
michael@0 80 int *__err_code) {
michael@0 81 *__err_code = _STLP_LOC_UNKNOWN_NAME;
michael@0 82 return (struct _Locale_time*)newlocale(LC_TIME_MASK, nm, NULL);
michael@0 83 }
michael@0 84
michael@0 85 struct _Locale_collate *_Locale_collate_create(const char *nm, struct _Locale_name_hint* hint,
michael@0 86 int *__err_code) {
michael@0 87 *__err_code = _STLP_LOC_UNKNOWN_NAME;
michael@0 88 return (struct _Locale_collate*)newlocale(LC_COLLATE_MASK, nm, NULL);
michael@0 89 }
michael@0 90
michael@0 91 struct _Locale_monetary *_Locale_monetary_create(const char *nm, struct _Locale_name_hint* hint,
michael@0 92 int *__err_code) {
michael@0 93 *__err_code = _STLP_LOC_UNKNOWN_NAME;
michael@0 94 return (struct _Locale_monetary*)newlocale(LC_MONETARY_MASK, nm, NULL);
michael@0 95 }
michael@0 96
michael@0 97 struct _Locale_messages *_Locale_messages_create(const char *nm, struct _Locale_name_hint* hint,
michael@0 98 int *__err_code) {
michael@0 99 *__err_code = _STLP_LOC_UNKNOWN_NAME;
michael@0 100 return (struct _Locale_messages*)newlocale(LC_MESSAGES_MASK, nm, NULL);
michael@0 101 }
michael@0 102
michael@0 103 /*
michael@0 104 try to see locale category LC should be used from environment;
michael@0 105 according POSIX, the order is
michael@0 106 1. LC_ALL
michael@0 107 2. category (LC_CTYPE, LC_NUMERIC, ... )
michael@0 108 3. LANG
michael@0 109 If set nothing, return "C" (this really implementation-specific).
michael@0 110 */
michael@0 111 static const char *_Locale_aux_default( const char *LC, char *nm )
michael@0 112 {
michael@0 113 char *name = getenv( "LC_ALL" );
michael@0 114
michael@0 115 if ( name != NULL && *name != 0 ) {
michael@0 116 return name;
michael@0 117 }
michael@0 118 name = getenv( LC );
michael@0 119 if ( name != NULL && *name != 0 ) {
michael@0 120 return name;
michael@0 121 }
michael@0 122 name = getenv( "LANG" );
michael@0 123 if ( name != NULL && *name != 0 ) {
michael@0 124 return name;
michael@0 125 }
michael@0 126
michael@0 127 return _C_name;
michael@0 128 }
michael@0 129
michael@0 130 const char *_Locale_ctype_default( char *nm )
michael@0 131 {
michael@0 132 return _Locale_aux_default( "LC_CTYPE", nm );
michael@0 133 }
michael@0 134
michael@0 135 const char *_Locale_numeric_default( char *nm )
michael@0 136 {
michael@0 137 return _Locale_aux_default( "LC_NUMERIC", nm );
michael@0 138 }
michael@0 139
michael@0 140 const char *_Locale_time_default( char *nm )
michael@0 141 {
michael@0 142 return _Locale_aux_default( "LC_TIME", nm );
michael@0 143 }
michael@0 144
michael@0 145 const char *_Locale_collate_default( char *nm )
michael@0 146 {
michael@0 147 return _Locale_aux_default( "LC_COLLATE", nm );
michael@0 148 }
michael@0 149
michael@0 150 const char *_Locale_monetary_default( char *nm )
michael@0 151 {
michael@0 152 return _Locale_aux_default( "LC_MONETARY", nm );
michael@0 153 }
michael@0 154
michael@0 155 const char *_Locale_messages_default( char *nm )
michael@0 156 {
michael@0 157 return _Locale_aux_default( "LC_MESSAGES", nm );
michael@0 158 }
michael@0 159
michael@0 160 char const*_Locale_ctype_name( const struct _Locale_ctype *__loc, char *buf )
michael@0 161 {
michael@0 162 return ((locale_t)__loc)->__names[LC_CTYPE];
michael@0 163 }
michael@0 164
michael@0 165 char const*_Locale_codecvt_name( const struct _Locale_codecvt *__loc, char *buf )
michael@0 166 {
michael@0 167 return _C_name;
michael@0 168 }
michael@0 169
michael@0 170 char const*_Locale_numeric_name( const struct _Locale_numeric *__loc, char *buf )
michael@0 171 {
michael@0 172 return ((locale_t)__loc)->__names[LC_NUMERIC];
michael@0 173 }
michael@0 174
michael@0 175 char const*_Locale_time_name( const struct _Locale_time *__loc, char *buf )
michael@0 176 {
michael@0 177 return ((locale_t)__loc)->__names[LC_TIME];
michael@0 178 }
michael@0 179
michael@0 180 char const*_Locale_collate_name( const struct _Locale_collate *__loc, char *buf )
michael@0 181 {
michael@0 182 return ((locale_t)__loc)->__names[LC_COLLATE];
michael@0 183 }
michael@0 184
michael@0 185 char const*_Locale_monetary_name( const struct _Locale_monetary *__loc, char *buf )
michael@0 186 {
michael@0 187 return ((locale_t)__loc)->__names[LC_MONETARY];
michael@0 188 }
michael@0 189
michael@0 190 char const*_Locale_messages_name( const struct _Locale_messages *__loc, char *buf )
michael@0 191 {
michael@0 192 return ((locale_t)__loc)->__names[LC_MESSAGES];
michael@0 193 }
michael@0 194
michael@0 195 void _Locale_ctype_destroy( struct _Locale_ctype *__loc )
michael@0 196 { freelocale((locale_t)__loc); }
michael@0 197
michael@0 198 void _Locale_codecvt_destroy( struct _Locale_codecvt *__loc )
michael@0 199 {}
michael@0 200
michael@0 201 void _Locale_numeric_destroy( struct _Locale_numeric *__loc )
michael@0 202 { freelocale((locale_t)__loc); }
michael@0 203
michael@0 204 void _Locale_time_destroy( struct _Locale_time *__loc )
michael@0 205 { freelocale((locale_t)__loc); }
michael@0 206
michael@0 207 void _Locale_collate_destroy( struct _Locale_collate *__loc )
michael@0 208 { freelocale((locale_t)__loc); }
michael@0 209
michael@0 210 void _Locale_monetary_destroy( struct _Locale_monetary *__loc )
michael@0 211 { freelocale((locale_t)__loc); }
michael@0 212
michael@0 213 void _Locale_messages_destroy( struct _Locale_messages* __loc )
michael@0 214 { freelocale((locale_t)__loc); }
michael@0 215
michael@0 216 /*
michael@0 217 * locale loc expected either locale name indeed (platform-specific)
michael@0 218 * or string like "LC_CTYPE=LocaleNameForCType;LC_NUMERIC=LocaleNameForNum;"
michael@0 219 *
michael@0 220 */
michael@0 221
michael@0 222 static char const*__Extract_locale_name( const char *loc, const char *category, char *buf )
michael@0 223 {
michael@0 224 char *expr;
michael@0 225 size_t len_name;
michael@0 226
michael@0 227 if( loc[0]=='L' && loc[1]=='C' && loc[2]=='_') {
michael@0 228 expr = strstr( (char*)loc, category );
michael@0 229 if ( expr == NULL )
michael@0 230 return NULL; /* Category not found. */
michael@0 231 ++expr;
michael@0 232 len_name = strcspn( expr, ";" );
michael@0 233 len_name = len_name >= _Locale_MAX_SIMPLE_NAME ? _Locale_MAX_SIMPLE_NAME - 1 : len_name;
michael@0 234 strncpy( buf, expr, len_name );
michael@0 235 buf[len_name] = 0;
michael@0 236 return buf;
michael@0 237 }
michael@0 238 return loc;
michael@0 239 }
michael@0 240
michael@0 241 char const*_Locale_extract_ctype_name(const char *loc, char *buf,
michael@0 242 struct _Locale_name_hint* hint, int *__err_code)
michael@0 243 { return __Extract_locale_name( loc, "LC_CTYPE=", buf ); }
michael@0 244
michael@0 245 char const*_Locale_extract_numeric_name(const char *loc, char *buf,
michael@0 246 struct _Locale_name_hint* hint, int *__err_code)
michael@0 247 { return __Extract_locale_name( loc, "LC_NUMERIC=", buf ); }
michael@0 248
michael@0 249 char const*_Locale_extract_time_name(const char *loc, char *buf,
michael@0 250 struct _Locale_name_hint* hint, int *__err_code)
michael@0 251 { return __Extract_locale_name( loc, "LC_TIME=", buf ); }
michael@0 252
michael@0 253 char const*_Locale_extract_collate_name(const char *loc, char *buf,
michael@0 254 struct _Locale_name_hint* hint, int *__err_code)
michael@0 255 { return __Extract_locale_name( loc, "LC_COLLATE=", buf ); }
michael@0 256
michael@0 257 char const*_Locale_extract_monetary_name(const char *loc, char *buf,
michael@0 258 struct _Locale_name_hint* hint, int *__err_code)
michael@0 259 { return __Extract_locale_name( loc, "LC_MONETARY=", buf ); }
michael@0 260
michael@0 261 char const*_Locale_extract_messages_name(const char *loc, char *buf,
michael@0 262 struct _Locale_name_hint* hint, int *__err_code)
michael@0 263 { return __Extract_locale_name( loc, "LC_MESSAGES=", buf ); }
michael@0 264
michael@0 265 struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype* ctype)
michael@0 266 { return 0; }
michael@0 267 struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric* numeric)
michael@0 268 { return 0; }
michael@0 269 struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time* time)
michael@0 270 { return 0; }
michael@0 271 struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate* collate)
michael@0 272 { return 0; }
michael@0 273 struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary* monetary)
michael@0 274 { return 0; }
michael@0 275 struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages* messages)
michael@0 276 { return 0; }
michael@0 277
michael@0 278 /* ctype */
michael@0 279
michael@0 280 const _Locale_mask_t *_Locale_ctype_table( struct _Locale_ctype *__loc )
michael@0 281 {
michael@0 282 /* return table with masks (upper, lower, alpha, etc.) */
michael@0 283 _STLP_STATIC_ASSERT( sizeof(_Locale_mask_t) == sizeof(((locale_t)__loc)->__ctype_b[0]) )
michael@0 284 return ((locale_t)__loc)->__ctype_b;
michael@0 285 }
michael@0 286
michael@0 287 int _Locale_toupper( struct _Locale_ctype *__loc, int c )
michael@0 288 { return ((locale_t)__loc)->__ctype_toupper[c]; }
michael@0 289
michael@0 290 int _Locale_tolower( struct _Locale_ctype *__loc, int c )
michael@0 291 { return ((locale_t)__loc)->__ctype_tolower[c]; }
michael@0 292
michael@0 293 #if !defined (_STLP_NO_WCHAR_T)
michael@0 294 _Locale_mask_t _WLocale_ctype( struct _Locale_ctype *__loc, wint_t wc, _Locale_mask_t __mask )
michael@0 295 {
michael@0 296 _Locale_mask_t ret = 0;
michael@0 297 if ((__mask & _Locale_ALPHA) != 0 && iswalpha_l(wc, (locale_t)__loc))
michael@0 298 ret |= _Locale_ALPHA;
michael@0 299
michael@0 300 if ((__mask & _Locale_CNTRL) != 0 && iswcntrl_l(wc, (locale_t)__loc))
michael@0 301 ret |= _Locale_CNTRL;
michael@0 302
michael@0 303 if ((__mask & _Locale_DIGIT) != 0 && iswdigit_l(wc, (locale_t)__loc))
michael@0 304 ret |= _Locale_DIGIT;
michael@0 305
michael@0 306 if ((__mask & _Locale_PRINT) != 0 && iswprint_l(wc, (locale_t)__loc))
michael@0 307 ret |= _Locale_PRINT;
michael@0 308
michael@0 309 if ((__mask & _Locale_PUNCT) != 0 && iswpunct_l(wc, (locale_t)__loc))
michael@0 310 ret |= _Locale_PUNCT;
michael@0 311
michael@0 312 if ((__mask & _Locale_SPACE) != 0 && iswspace_l(wc, (locale_t)__loc))
michael@0 313 ret |= _Locale_SPACE;
michael@0 314
michael@0 315 if ((__mask & _Locale_XDIGIT) != 0 && iswxdigit_l(wc, (locale_t)__loc))
michael@0 316 ret |= _Locale_XDIGIT;
michael@0 317
michael@0 318 if ((__mask & _Locale_UPPER) != 0 && iswupper_l(wc, (locale_t)__loc))
michael@0 319 ret |= _Locale_UPPER;
michael@0 320
michael@0 321 if ((__mask & _Locale_LOWER) != 0 && iswlower_l(wc, (locale_t)__loc))
michael@0 322 ret |= _Locale_LOWER;
michael@0 323
michael@0 324 return ret;
michael@0 325 }
michael@0 326
michael@0 327 wint_t _WLocale_tolower( struct _Locale_ctype *__loc, wint_t c )
michael@0 328 {
michael@0 329 return towlower_l( c, ((locale_t)__loc) );
michael@0 330 }
michael@0 331
michael@0 332 wint_t _WLocale_toupper( struct _Locale_ctype *__loc, wint_t c )
michael@0 333 {
michael@0 334 return towupper_l( c, ((locale_t)__loc) );
michael@0 335 }
michael@0 336 #endif
michael@0 337
michael@0 338 int _WLocale_mb_cur_max( struct _Locale_codecvt * lcodecvt) { return 1; }
michael@0 339 int _WLocale_mb_cur_min( struct _Locale_codecvt * lcodecvt) { return 1; }
michael@0 340 int _WLocale_is_stateless( struct _Locale_codecvt * lcodecvt) { return 1; }
michael@0 341
michael@0 342 #if !defined (_STLP_NO_WCHAR_T)
michael@0 343 size_t _WLocale_mbtowc(struct _Locale_codecvt *lcodecvt,
michael@0 344 wchar_t *to,
michael@0 345 const char *from, size_t n,
michael@0 346 mbstate_t *st)
michael@0 347 { *to = *from; return 1; }
michael@0 348
michael@0 349 size_t _WLocale_wctomb(struct _Locale_codecvt *lcodecvt,
michael@0 350 char *to, size_t n,
michael@0 351 const wchar_t c,
michael@0 352 mbstate_t *st)
michael@0 353 { *to = (char)c; return 1; }
michael@0 354 #endif
michael@0 355
michael@0 356 size_t _WLocale_unshift(struct _Locale_codecvt *lcodecvt,
michael@0 357 mbstate_t *st,
michael@0 358 char *buf, size_t n, char ** next)
michael@0 359 { *next = buf; return 0; }
michael@0 360
michael@0 361 /* Collate */
michael@0 362 int _Locale_strcmp(struct _Locale_collate * __loc,
michael@0 363 const char *s1, size_t n1,
michael@0 364 const char *s2, size_t n2) {
michael@0 365 int ret = 0;
michael@0 366 char buf1[64], buf2[64];
michael@0 367 while (n1 > 0 || n2 > 0) {
michael@0 368 size_t bufsize1 = n1 < 63 ? n1 : 63;
michael@0 369 size_t bufsize2 = n2 < 63 ? n2 : 63;
michael@0 370 strncpy(buf1, s1, bufsize1); buf1[bufsize1] = 0;
michael@0 371 strncpy(buf2, s2, bufsize2); buf2[bufsize2] = 0;
michael@0 372
michael@0 373 ret = strcoll_l(buf1, buf2, (locale_t)__loc);
michael@0 374 if (ret != 0) return ret;
michael@0 375 s1 += bufsize1; n1 -= bufsize1;
michael@0 376 s2 += bufsize2; n2 -= bufsize2;
michael@0 377 }
michael@0 378 return ret;
michael@0 379 }
michael@0 380
michael@0 381 #if !defined (_STLP_NO_WCHAR_T)
michael@0 382 int _WLocale_strcmp(struct _Locale_collate *__loc,
michael@0 383 const wchar_t *s1, size_t n1,
michael@0 384 const wchar_t *s2, size_t n2) {
michael@0 385 int ret = 0;
michael@0 386 wchar_t buf1[64], buf2[64];
michael@0 387 while (n1 > 0 || n2 > 0) {
michael@0 388 size_t bufsize1 = n1 < 63 ? n1 : 63;
michael@0 389 size_t bufsize2 = n2 < 63 ? n2 : 63;
michael@0 390 wcsncpy(buf1, s1, bufsize1); buf1[bufsize1] = 0;
michael@0 391 wcsncpy(buf2, s2, bufsize2); buf2[bufsize2] = 0;
michael@0 392
michael@0 393 ret = wcscoll_l(buf1, buf2, (locale_t)__loc);
michael@0 394 if (ret != 0) return ret;
michael@0 395 s1 += bufsize1; n1 -= bufsize1;
michael@0 396 s2 += bufsize2; n2 -= bufsize2;
michael@0 397 }
michael@0 398 return ret;
michael@0 399 }
michael@0 400
michael@0 401 #endif
michael@0 402
michael@0 403 size_t _Locale_strxfrm(struct _Locale_collate *__loc,
michael@0 404 char *dest, size_t dest_n,
michael@0 405 const char *src, size_t src_n )
michael@0 406 {
michael@0 407 const char *real_src;
michael@0 408 char *buf = NULL;
michael@0 409 size_t result;
michael@0 410
michael@0 411 if (src_n == 0)
michael@0 412 {
michael@0 413 if (dest != NULL) dest[0] = 0;
michael@0 414 return 0;
michael@0 415 }
michael@0 416 if (src[src_n] != 0) {
michael@0 417 buf = malloc(src_n + 1);
michael@0 418 strncpy(buf, src, src_n);
michael@0 419 buf[src_n] = 0;
michael@0 420 real_src = buf;
michael@0 421 }
michael@0 422 else
michael@0 423 real_src = src;
michael@0 424 result = strxfrm_l(dest, real_src, dest_n, (locale_t)__loc);
michael@0 425 if (buf != NULL) free(buf);
michael@0 426 return result;
michael@0 427 }
michael@0 428
michael@0 429 # ifndef _STLP_NO_WCHAR_T
michael@0 430
michael@0 431 size_t _WLocale_strxfrm( struct _Locale_collate *__loc,
michael@0 432 wchar_t *dest, size_t dest_n,
michael@0 433 const wchar_t *src, size_t src_n )
michael@0 434 {
michael@0 435 const wchar_t *real_src;
michael@0 436 wchar_t *buf = NULL;
michael@0 437 size_t result;
michael@0 438
michael@0 439 if (src_n == 0)
michael@0 440 {
michael@0 441 if (dest != NULL) dest[0] = 0;
michael@0 442 return 0;
michael@0 443 }
michael@0 444 if (src[src_n] != 0) {
michael@0 445 buf = malloc((src_n + 1) * sizeof(wchar_t));
michael@0 446 wcsncpy(buf, src, src_n);
michael@0 447 buf[src_n] = 0;
michael@0 448 real_src = buf;
michael@0 449 }
michael@0 450 else
michael@0 451 real_src = src;
michael@0 452 result = wcsxfrm_l(dest, real_src, dest_n, (locale_t)__loc);
michael@0 453 if (buf != NULL) free(buf);
michael@0 454 return result;
michael@0 455 }
michael@0 456
michael@0 457 # endif
michael@0 458
michael@0 459 /* Numeric */
michael@0 460
michael@0 461 char _Locale_decimal_point(struct _Locale_numeric *__loc)
michael@0 462 {
michael@0 463 return *(nl_langinfo_l(RADIXCHAR, (locale_t)__loc));
michael@0 464 }
michael@0 465
michael@0 466 char _Locale_thousands_sep(struct _Locale_numeric *__loc)
michael@0 467 {
michael@0 468 return *(nl_langinfo_l(THOUSEP, (locale_t)__loc));
michael@0 469 }
michael@0 470
michael@0 471 const char* _Locale_grouping(struct _Locale_numeric *__loc)
michael@0 472 {
michael@0 473 return (_Locale_thousands_sep(__loc) != 0 ) ? (nl_langinfo_l(GROUPING, (locale_t)__loc)) : _empty_str;
michael@0 474 }
michael@0 475
michael@0 476 const char *_Locale_true(struct _Locale_numeric *__loc)
michael@0 477 {
michael@0 478 return nl_langinfo_l(YESSTR, (locale_t)__loc);
michael@0 479 }
michael@0 480
michael@0 481 const char *_Locale_false(struct _Locale_numeric *__loc)
michael@0 482 {
michael@0 483 return nl_langinfo_l(NOSTR, (locale_t)__loc);
michael@0 484 }
michael@0 485
michael@0 486 #ifndef _STLP_NO_WCHAR_T
michael@0 487 wchar_t _WLocale_decimal_point(struct _Locale_numeric *__loc)
michael@0 488 { return (wchar_t)_Locale_decimal_point(__loc); }
michael@0 489 wchar_t _WLocale_thousands_sep(struct _Locale_numeric *__loc)
michael@0 490 { return (wchar_t)_Locale_thousands_sep(__loc); }
michael@0 491 const wchar_t *_WLocale_true(struct _Locale_numeric *__loc, wchar_t *buf, size_t bufSize)
michael@0 492 { return _ToWChar(_Locale_true(__loc), buf, bufSize); }
michael@0 493 const wchar_t *_WLocale_false(struct _Locale_numeric *__loc, wchar_t *buf, size_t bufSize)
michael@0 494 { return _ToWChar(_Locale_false(__loc), buf, bufSize); }
michael@0 495 #endif
michael@0 496
michael@0 497 /* Monetary */
michael@0 498
michael@0 499 const char *_Locale_int_curr_symbol(struct _Locale_monetary *__loc)
michael@0 500 {
michael@0 501 return nl_langinfo_l(INT_CURR_SYMBOL, (locale_t)__loc);
michael@0 502 }
michael@0 503
michael@0 504 const char *_Locale_currency_symbol(struct _Locale_monetary *__loc)
michael@0 505 {
michael@0 506 return nl_langinfo_l(CURRENCY_SYMBOL, (locale_t)__loc);
michael@0 507 }
michael@0 508
michael@0 509 char _Locale_mon_decimal_point(struct _Locale_monetary * __loc)
michael@0 510 {
michael@0 511 return *(nl_langinfo_l(MON_DECIMAL_POINT,(locale_t)__loc));
michael@0 512 }
michael@0 513
michael@0 514 char _Locale_mon_thousands_sep(struct _Locale_monetary *__loc)
michael@0 515 {
michael@0 516 return *(nl_langinfo_l(MON_THOUSANDS_SEP, (locale_t)__loc));
michael@0 517 }
michael@0 518
michael@0 519 #ifndef _STLP_NO_WCHAR_T
michael@0 520 const wchar_t *_WLocale_int_curr_symbol(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
michael@0 521 { return _ToWChar(_Locale_int_curr_symbol(__loc), buf, bufSize); }
michael@0 522 const wchar_t *_WLocale_currency_symbol(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
michael@0 523 { return _ToWChar(_Locale_currency_symbol(__loc), buf, bufSize); }
michael@0 524 wchar_t _WLocale_mon_decimal_point(struct _Locale_monetary * __loc)
michael@0 525 { return (wchar_t)_Locale_mon_decimal_point(__loc); }
michael@0 526 wchar_t _WLocale_mon_thousands_sep(struct _Locale_monetary * __loc)
michael@0 527 { return (wchar_t)_Locale_mon_thousands_sep(__loc); }
michael@0 528 const wchar_t *_WLocale_positive_sign(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
michael@0 529 { return _ToWChar(_Locale_positive_sign(__loc), buf, bufSize); }
michael@0 530 const wchar_t *_WLocale_negative_sign(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
michael@0 531 { return _ToWChar(_Locale_negative_sign(__loc), buf, bufSize); }
michael@0 532 #endif
michael@0 533
michael@0 534 const char *_Locale_mon_grouping(struct _Locale_monetary *__loc)
michael@0 535 {
michael@0 536 return (_Locale_mon_thousands_sep( __loc ) != 0 ) ? nl_langinfo_l(MON_GROUPING, (locale_t)__loc) : _empty_str;
michael@0 537 }
michael@0 538
michael@0 539 const char *_Locale_positive_sign(struct _Locale_monetary *__loc)
michael@0 540 {
michael@0 541 return nl_langinfo_l(POSITIVE_SIGN, (locale_t)__loc);
michael@0 542 }
michael@0 543
michael@0 544 const char *_Locale_negative_sign(struct _Locale_monetary *__loc)
michael@0 545 {
michael@0 546 return nl_langinfo_l(NEGATIVE_SIGN, (locale_t)__loc);
michael@0 547 }
michael@0 548
michael@0 549 char _Locale_int_frac_digits(struct _Locale_monetary *__loc)
michael@0 550 {
michael@0 551 /* We are forced to manually handled the "C" locale for consistency with
michael@0 552 * the default implementation in STLport. */
michael@0 553 const char* lname = ((locale_t)__loc)->__names[LC_MONETARY];
michael@0 554 if (lname[0] == 'C' && lname[1] == 0)
michael@0 555 return 0;
michael@0 556 return *(nl_langinfo_l(INT_FRAC_DIGITS, (locale_t)__loc));
michael@0 557 }
michael@0 558
michael@0 559 char _Locale_frac_digits(struct _Locale_monetary *__loc)
michael@0 560 {
michael@0 561 /* We are forced to manually handled the "C" locale for consistency with
michael@0 562 * the default implementation in STLport. */
michael@0 563 const char* lname = ((locale_t)__loc)->__names[LC_MONETARY];
michael@0 564 if (lname[0] == 'C' && lname[1] == 0)
michael@0 565 return 0;
michael@0 566 return *(nl_langinfo_l(FRAC_DIGITS, (locale_t)__loc));
michael@0 567 }
michael@0 568
michael@0 569 /* 1 if currency_symbol precedes a positive value, 0 if succeeds */
michael@0 570 int _Locale_p_cs_precedes(struct _Locale_monetary *__loc)
michael@0 571 {
michael@0 572 return *(nl_langinfo_l(P_CS_PRECEDES, (locale_t)__loc));
michael@0 573 }
michael@0 574
michael@0 575 /* 1 if a space separates currency_symbol from a positive value. */
michael@0 576 int _Locale_p_sep_by_space(struct _Locale_monetary *__loc)
michael@0 577 {
michael@0 578 return *(nl_langinfo_l(P_SEP_BY_SPACE, (locale_t)__loc));
michael@0 579 }
michael@0 580
michael@0 581 /*
michael@0 582 * 0 Parentheses surround the quantity and currency_symbol
michael@0 583 * 1 The sign string precedes the quantity and currency_symbol
michael@0 584 * 2 The sign string succeeds the quantity and currency_symbol.
michael@0 585 * 3 The sign string immediately precedes the currency_symbol.
michael@0 586 * 4 The sign string immediately succeeds the currency_symbol.
michael@0 587 */
michael@0 588 int _Locale_p_sign_posn(struct _Locale_monetary *__loc)
michael@0 589 {
michael@0 590 return *(nl_langinfo_l(P_SIGN_POSN, (locale_t)__loc));
michael@0 591 }
michael@0 592
michael@0 593 /* 1 if currency_symbol precedes a negative value, 0 if succeeds */
michael@0 594 int _Locale_n_cs_precedes(struct _Locale_monetary *__loc)
michael@0 595 {
michael@0 596 return *(nl_langinfo_l(N_CS_PRECEDES, (locale_t)__loc));
michael@0 597 }
michael@0 598
michael@0 599 /* 1 if a space separates currency_symbol from a negative value. */
michael@0 600 int _Locale_n_sep_by_space(struct _Locale_monetary *__loc)
michael@0 601 {
michael@0 602 return *(nl_langinfo_l(N_SEP_BY_SPACE, (locale_t)__loc));
michael@0 603 }
michael@0 604
michael@0 605 /*
michael@0 606 * 0 Parentheses surround the quantity and currency_symbol
michael@0 607 * 1 The sign string precedes the quantity and currency_symbol
michael@0 608 * 2 The sign string succeeds the quantity and currency_symbol.
michael@0 609 * 3 The sign string immediately precedes the currency_symbol.
michael@0 610 * 4 The sign string immediately succeeds the currency_symbol.
michael@0 611 */
michael@0 612 int _Locale_n_sign_posn(struct _Locale_monetary *__loc)
michael@0 613 {
michael@0 614 return *(nl_langinfo_l(N_SIGN_POSN, (locale_t)__loc));
michael@0 615 }
michael@0 616
michael@0 617
michael@0 618 /* Time */
michael@0 619 const char *_Locale_full_monthname(struct _Locale_time *__loc, int _m )
michael@0 620 {
michael@0 621 return nl_langinfo_l(MON_1 + _m, (locale_t)__loc);
michael@0 622 }
michael@0 623
michael@0 624 const char *_Locale_abbrev_monthname(struct _Locale_time *__loc, int _m )
michael@0 625 {
michael@0 626 return nl_langinfo_l(ABMON_1 + _m, (locale_t)__loc);
michael@0 627 }
michael@0 628
michael@0 629 const char *_Locale_full_dayofweek(struct _Locale_time *__loc, int _d )
michael@0 630 {
michael@0 631 return nl_langinfo_l(DAY_1 + _d, (locale_t)__loc);
michael@0 632 }
michael@0 633
michael@0 634 const char *_Locale_abbrev_dayofweek(struct _Locale_time *__loc, int _d )
michael@0 635 {
michael@0 636 return nl_langinfo_l(ABDAY_1 + _d, (locale_t)__loc);
michael@0 637 }
michael@0 638
michael@0 639 const char *_Locale_d_t_fmt(struct _Locale_time *__loc)
michael@0 640 {
michael@0 641 return nl_langinfo_l(D_T_FMT, (locale_t)__loc);
michael@0 642 }
michael@0 643
michael@0 644 const char *_Locale_d_fmt(struct _Locale_time *__loc )
michael@0 645 {
michael@0 646 return nl_langinfo_l(D_FMT, (locale_t)__loc);
michael@0 647 }
michael@0 648
michael@0 649 const char *_Locale_t_fmt(struct _Locale_time *__loc )
michael@0 650 {
michael@0 651 return nl_langinfo_l(T_FMT, (locale_t)__loc);
michael@0 652 }
michael@0 653
michael@0 654 const char *_Locale_long_d_t_fmt(struct _Locale_time *__loc )
michael@0 655 {
michael@0 656 return nl_langinfo_l(ERA_D_T_FMT, (locale_t)__loc);
michael@0 657 }
michael@0 658
michael@0 659 const char *_Locale_long_d_fmt(struct _Locale_time *__loc )
michael@0 660 {
michael@0 661 return nl_langinfo_l(ERA_D_FMT, (locale_t)__loc);
michael@0 662 }
michael@0 663
michael@0 664 const char *_Locale_am_str(struct _Locale_time *__loc )
michael@0 665 {
michael@0 666 return nl_langinfo_l(AM_STR, (locale_t)__loc);
michael@0 667 }
michael@0 668
michael@0 669 const char *_Locale_pm_str(struct _Locale_time* __loc )
michael@0 670 {
michael@0 671 return nl_langinfo_l(PM_STR, (locale_t)__loc);
michael@0 672 }
michael@0 673
michael@0 674 #ifndef _STLP_NO_WCHAR_T
michael@0 675 const wchar_t *_WLocale_full_monthname(struct _Locale_time *__loc, int _m, wchar_t *buf, size_t bufSize)
michael@0 676 { return _ToWChar(_Locale_full_monthname(__loc, _m), buf, bufSize); }
michael@0 677 const wchar_t *_WLocale_abbrev_monthname(struct _Locale_time *__loc, int _m, wchar_t *buf, size_t bufSize)
michael@0 678 { return _ToWChar(_Locale_abbrev_monthname(__loc, _m), buf, bufSize); }
michael@0 679 const wchar_t *_WLocale_full_dayofweek(struct _Locale_time *__loc, int _d, wchar_t *buf, size_t bufSize)
michael@0 680 { return _ToWChar(_Locale_full_dayofweek(__loc, _d), buf, bufSize); }
michael@0 681 const wchar_t *_WLocale_abbrev_dayofweek(struct _Locale_time *__loc, int _d, wchar_t *buf, size_t bufSize)
michael@0 682 { return _ToWChar(_Locale_abbrev_dayofweek(__loc, _d), buf, bufSize); }
michael@0 683 const wchar_t *_WLocale_am_str(struct _Locale_time *__loc, wchar_t *buf, size_t bufSize)
michael@0 684 { return _ToWChar(_Locale_am_str(__loc), buf, bufSize); }
michael@0 685 const wchar_t *_WLocale_pm_str(struct _Locale_time* __loc, wchar_t *buf, size_t bufSize)
michael@0 686 { return _ToWChar(_Locale_pm_str(__loc), buf, bufSize); }
michael@0 687 #endif
michael@0 688
michael@0 689 /* Messages */
michael@0 690
michael@0 691 nl_catd_type _Locale_catopen(struct _Locale_messages *__loc, const char *__cat_name )
michael@0 692 {
michael@0 693 return catopen( __cat_name, NL_CAT_LOCALE );
michael@0 694 }
michael@0 695
michael@0 696 void _Locale_catclose(struct _Locale_messages *__loc, nl_catd_type __cat )
michael@0 697 {
michael@0 698 catclose( __cat );
michael@0 699 }
michael@0 700
michael@0 701 const char *_Locale_catgets(struct _Locale_messages *__loc, nl_catd_type __cat,
michael@0 702 int __setid, int __msgid, const char *dfault)
michael@0 703 {
michael@0 704 return catgets( __cat, __setid, __msgid, dfault );
michael@0 705 }

mercurial