wctrans.c (d390e53270d48bf9dfefd11700e40a2db0abdd4e) | wctrans.c (3c87aa1d3dc1d8dad3efad322852a8e1e76dee55) |
---|---|
1/*- 2 * Copyright (c) 2002 Tim J. Robbins. 3 * All rights reserved. 4 * | 1/*- 2 * Copyright (c) 2002 Tim J. Robbins. 3 * All rights reserved. 4 * |
5 * Copyright (c) 2011 The FreeBSD Foundation 6 * All rights reserved. 7 * Portions of this software were developed by David Chisnall 8 * under sponsorship from the FreeBSD Foundation. 9 * |
|
5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. --- 12 unchanged lines hidden (view full) --- 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD$"); 29 30#include <errno.h> 31#include <string.h> 32#include <wctype.h> | 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. --- 12 unchanged lines hidden (view full) --- 30 */ 31 32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD$"); 34 35#include <errno.h> 36#include <string.h> 37#include <wctype.h> |
38#include "xlocale_private.h" |
|
33 34enum { 35 _WCT_ERROR = 0, 36 _WCT_TOLOWER = 1, 37 _WCT_TOUPPER = 2 38}; 39 40wint_t | 39 40enum { 41 _WCT_ERROR = 0, 42 _WCT_TOLOWER = 1, 43 _WCT_TOUPPER = 2 44}; 45 46wint_t |
41towctrans(wint_t wc, wctrans_t desc) | 47towctrans_l(wint_t wc, wctrans_t desc, locale_t locale) |
42{ | 48{ |
43 | |
44 switch (desc) { 45 case _WCT_TOLOWER: | 49 switch (desc) { 50 case _WCT_TOLOWER: |
46 wc = towlower(wc); | 51 wc = towlower_l(wc, locale); |
47 break; 48 case _WCT_TOUPPER: | 52 break; 53 case _WCT_TOUPPER: |
49 wc = towupper(wc); | 54 wc = towupper_l(wc, locale); |
50 break; 51 case _WCT_ERROR: 52 default: 53 errno = EINVAL; 54 break; 55 } 56 57 return (wc); 58} | 55 break; 56 case _WCT_ERROR: 57 default: 58 errno = EINVAL; 59 break; 60 } 61 62 return (wc); 63} |
64wint_t 65towctrans(wint_t wc, wctrans_t desc) 66{ 67 return towctrans_l(wc, desc, __get_locale()); 68} |
|
59 | 69 |
70/* 71 * wctrans() calls this will a 0 locale. If this is ever modified to actually 72 * use the locale, wctrans() must be modified to call __get_locale(). 73 */ |
|
60wctrans_t | 74wctrans_t |
61wctrans(const char *charclass) | 75wctrans_l(const char *charclass, locale_t locale) |
62{ 63 struct { 64 const char *name; 65 wctrans_t trans; 66 } ccls[] = { 67 { "tolower", _WCT_TOLOWER }, 68 { "toupper", _WCT_TOUPPER }, 69 { NULL, _WCT_ERROR }, /* Default */ 70 }; 71 int i; 72 73 i = 0; 74 while (ccls[i].name != NULL && strcmp(ccls[i].name, charclass) != 0) 75 i++; 76 77 if (ccls[i].trans == _WCT_ERROR) 78 errno = EINVAL; 79 return (ccls[i].trans); 80} | 76{ 77 struct { 78 const char *name; 79 wctrans_t trans; 80 } ccls[] = { 81 { "tolower", _WCT_TOLOWER }, 82 { "toupper", _WCT_TOUPPER }, 83 { NULL, _WCT_ERROR }, /* Default */ 84 }; 85 int i; 86 87 i = 0; 88 while (ccls[i].name != NULL && strcmp(ccls[i].name, charclass) != 0) 89 i++; 90 91 if (ccls[i].trans == _WCT_ERROR) 92 errno = EINVAL; 93 return (ccls[i].trans); 94} |
95 96wctrans_t 97wctrans(const char *charclass) 98{ 99 return wctrans_l(charclass, 0); 100} 101 |
|