Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
3.4 KiB

  1. // cp1252.h
  2. // James A. Pittman
  3. // Mar 11, 1999
  4. // Functions to support CodePage 1252. Versions of isalpha, isdigit, etc.
  5. // plus tolower(), toupper(), strlower(), and strupper().
  6. // Also translation functions, for translation between codepage 1252 and Unicode.
  7. #ifndef _CP1252_
  8. #define _CP1252_
  9. #include <windows.h>
  10. // Should non-breaking space be an alpha?
  11. #define _UPPER 0x1 /* upper case letter */
  12. #define _LOWER 0x2 /* lower case letter */
  13. #define _DIGIT 0x4 /* digit[0-9] */
  14. #define _SPACE 0x8 /* space, tab, carriage return, newline, */
  15. /* vertical tab, form feed, or non-breaking space */
  16. #define _PUNCT 0x10 /* punctuation character */
  17. #define _CONTROL 0x20 /* control character */
  18. #define _BLANK 0x40 /* space and non-breaking space chars only */
  19. #define _HEX 0x80 /* hexadecimal digit */
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. extern unsigned char _ctype1252[256];
  25. #define isalpha1252(_c) (_ctype1252[(unsigned char)_c] & (_UPPER | _LOWER))
  26. #define isupper1252(_c) (_ctype1252[(unsigned char)_c] & _UPPER)
  27. #define islower1252(_c) (_ctype1252[(unsigned char)_c] & _LOWER)
  28. #define isdigit1252(_c) (_ctype1252[(unsigned char)_c] & _DIGIT)
  29. #define isxdigit1252(_c) (_ctype1252[(unsigned char)_c] & _HEX)
  30. #define isspace1252(_c) (_ctype1252[(unsigned char)_c] & _SPACE)
  31. #define ispunct1252(_c) (_ctype1252[(unsigned char)_c] & _PUNCT)
  32. #define isalnum1252(_c) (_ctype1252[(unsigned char)_c] & (_UPPER | _LOWER | _DIGIT))
  33. #define isprint1252(_c) (_ctype1252[(unsigned char)_c] & (_BLANK | _PUNCT | _UPPER | _LOWER | _DIGIT))
  34. #define isgraph1252(_c) (_ctype1252[(unsigned char)_c] & (_PUNCT | _UPPER | _LOWER | _DIGIT))
  35. #define iscntrl1252(_c) (_ctype1252[(unsigned char)_c] & _CONTROL)
  36. #define isundef1252(_c) (!_ctype1252[(unsigned char)_c])
  37. // These 2 macros will return the arg letter if there is no lowercase (or uppercase)
  38. // equivalent (as far as I can tell this is not true of the ANSI c toupper() and tolower()).
  39. // Note that the German esset is a lowercase letter, but there is no uppercase equivalent.
  40. // caron S and OE diaeresis Y most letters
  41. #define tolower1252(_c) (isupper1252(_c) ? (((_c & 0xF0) == 0x80) ? (_c + 16) : ((_c == 0x9F) ? 0xFF : (_c + 32))) : _c)
  42. // caron s and oe diaeresis y esset most letters
  43. #define toupper1252(_c) (islower1252(_c) ? (((_c & 0xF0) == 0x90) ? (_c - 16) : ((_c == 0xFF) ? 0x9F : ((_c == 0xDF) ? _c : (_c - 32)))) : _c)
  44. // Two functions to translate case in strings. Any characters which do
  45. // not have case translations are preserved.
  46. extern void strlower1252(unsigned char *s);
  47. extern void strupper1252(unsigned char *s);
  48. // If successful, 1 is returned.
  49. // If an undefined code is passed in, 0 is returned and *pwch is unchanged.
  50. extern int CP1252ToUnicode(unsigned char ch, WCHAR *pwch);
  51. // If successful, 1 is returned.
  52. // If a unicode codepoint is passed in which is not supported in 1252,
  53. // 0 is returned and *pch is unchanged.
  54. extern int UnicodeToCP1252(WCHAR u, unsigned char *pch);
  55. extern unsigned char *UnicodeToCP1252String(WCHAR *wsz);
  56. WCHAR *CP1252StringToUnicode(unsigned char *psz, WCHAR *wsz, int *piLen);
  57. #ifdef __cplusplus
  58. };
  59. #endif
  60. #endif