[444] | 1 | /* |
---|
| 2 | FUNCTION |
---|
| 3 | <<toupper>>, <<toupper_l>>---translate characters to uppercase |
---|
| 4 | |
---|
| 5 | INDEX |
---|
| 6 | toupper |
---|
| 7 | |
---|
| 8 | INDEX |
---|
| 9 | toupper_l |
---|
| 10 | |
---|
| 11 | INDEX |
---|
| 12 | _toupper |
---|
| 13 | |
---|
| 14 | SYNOPSIS |
---|
| 15 | #include <ctype.h> |
---|
| 16 | int toupper(int <[c]>); |
---|
| 17 | int _toupper(int <[c]>); |
---|
| 18 | |
---|
| 19 | #include <ctype.h> |
---|
| 20 | int toupper_l(int <[c]>, locale_t <[locale]>); |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | DESCRIPTION |
---|
| 24 | <<toupper>> is a macro which converts lowercase characters to uppercase, |
---|
| 25 | leaving all other characters unchanged. It is only defined when |
---|
| 26 | <[c]> is an integer in the range <<EOF>> to <<255>>. |
---|
| 27 | |
---|
| 28 | <<toupper_l>> is like <<toupper>> but performs the function based on the |
---|
| 29 | locale specified by the locale object locale. If <[locale]> is |
---|
| 30 | LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined. |
---|
| 31 | |
---|
| 32 | You can use a compiled subroutine instead of the macro definition by |
---|
| 33 | undefining this macro using `<<#undef toupper>>' or `<<#undef toupper_l>>'. |
---|
| 34 | |
---|
| 35 | <<_toupper>> performs the same conversion as <<toupper>>, but should |
---|
| 36 | only be used when <[c]> is known to be a lowercase character (<<a>>--<<z>>). |
---|
| 37 | |
---|
| 38 | RETURNS |
---|
| 39 | <<toupper>>, <<toupper_l>> return the uppercase equivalent of <[c]> when |
---|
| 40 | <[c]> is a lowercase character, and <[c]> otherwise. |
---|
| 41 | |
---|
| 42 | <<_toupper>> returns the uppercase equivalent of <[c]> when it is a |
---|
| 43 | character between <<a>> and <<z>>. If <[c]> is not one of these |
---|
| 44 | characters, the behaviour of <<_toupper>> is undefined. |
---|
| 45 | |
---|
| 46 | PORTABILITY |
---|
| 47 | <<toupper>> is ANSI C. <<_toupper>> is not recommended for portable programs. |
---|
| 48 | <<toupper_l>> is POSIX-1.2008. |
---|
| 49 | |
---|
| 50 | No supporting OS subroutines are required. |
---|
| 51 | */ |
---|
| 52 | |
---|
| 53 | #include <_ansi.h> |
---|
| 54 | #include <ctype.h> |
---|
| 55 | #if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS) |
---|
| 56 | #include <limits.h> |
---|
| 57 | #include <stdio.h> |
---|
| 58 | #include <stdlib.h> |
---|
| 59 | #include <wctype.h> |
---|
| 60 | #include <wchar.h> |
---|
| 61 | #endif |
---|
| 62 | |
---|
| 63 | #undef toupper |
---|
| 64 | int |
---|
| 65 | toupper (int c) |
---|
| 66 | { |
---|
| 67 | #if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS) |
---|
| 68 | if ((unsigned char) c <= 0x7f) |
---|
| 69 | return islower (c) ? c - 'a' + 'A' : c; |
---|
| 70 | else if (c != EOF && MB_CUR_MAX == 1 && islower (c)) |
---|
| 71 | { |
---|
| 72 | char s[MB_LEN_MAX] = { c, '\0' }; |
---|
| 73 | wchar_t wc; |
---|
| 74 | if (mbtowc (&wc, s, 1) >= 0 |
---|
| 75 | && wctomb (s, (wchar_t) towupper ((wint_t) wc)) == 1) |
---|
| 76 | c = (unsigned char) s[0]; |
---|
| 77 | } |
---|
| 78 | return c; |
---|
| 79 | #else |
---|
| 80 | return islower (c) ? c - 'a' + 'A' : c; |
---|
| 81 | #endif |
---|
| 82 | } |
---|