Leaked source code of windows server 2003
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.

160 lines
4.8 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #define FE_SB
  6. #define IS_DBCS_ENABLED() (!!NLS_MB_CODE_PAGE_TAG)
  7. /***************************************************************************\
  8. * IsCharLowerA (API)
  9. *
  10. * History:
  11. * 14-Jan-1991 mikeke from win 3.0
  12. * 22-Jun-1991 GregoryW Modified to support code page 1252 (Windows ANSI
  13. * code page). This is for the PDK only. After the
  14. * PDK this routine will be rewritten to use the
  15. * NLSAPI.
  16. * 02-Feb-1992 GregoryW Modified to use NLS API.
  17. \***************************************************************************/
  18. BOOL LZIsCharLowerA(
  19. char cChar)
  20. {
  21. WORD ctype1info = 0;
  22. WCHAR wChar = 0;
  23. #ifdef FE_SB // IsCharLowerA()
  24. /*
  25. * if only DBCS Leadbyte was passed, just return FALSE.
  26. * Same behavior as Windows 3.1J and Windows 95 FarEast version.
  27. */
  28. if (IS_DBCS_ENABLED() && IsDBCSLeadByte(cChar)) {
  29. return FALSE;
  30. }
  31. #endif // FE_SB
  32. /*
  33. * The following 2 calls cannot fail here
  34. */
  35. RtlMultiByteToUnicodeN(&wChar, sizeof(WCHAR), NULL, &cChar, sizeof(CHAR));
  36. GetStringTypeW(CT_CTYPE1, &wChar, 1, &ctype1info);
  37. return (ctype1info & C1_LOWER) == C1_LOWER;
  38. }
  39. /***************************************************************************\
  40. * IsCharUpperA (API)
  41. *
  42. * History:
  43. * 22-Jun-1991 GregoryW Created to support code page 1252 (Windows ANSI
  44. * code page). This is for the PDK only. After the
  45. * PDK this routine will be rewritten to use the
  46. * NLSAPI.
  47. * 02-Feb-1992 GregoryW Modified to use NLS API.
  48. \***************************************************************************/
  49. BOOL LZIsCharUpperA(
  50. char cChar)
  51. {
  52. WORD ctype1info = 0;
  53. WCHAR wChar = 0;
  54. #ifdef FE_SB // IsCharUpperA()
  55. /*
  56. * if only DBCS Leadbyte was passed, just return FALSE.
  57. * Same behavior as Windows 3.1J and Windows 95 FarEast version.
  58. */
  59. if (IS_DBCS_ENABLED() && IsDBCSLeadByte(cChar)) {
  60. return FALSE;
  61. }
  62. #endif // FE_SB
  63. /*
  64. * The following 2 calls cannot fail here
  65. */
  66. RtlMultiByteToUnicodeN(&wChar, sizeof(WCHAR), NULL, &cChar, sizeof(CHAR));
  67. GetStringTypeW(CT_CTYPE1, &wChar, 1, &ctype1info);
  68. return (ctype1info & C1_UPPER) == C1_UPPER;
  69. }
  70. /***************************************************************************\
  71. * CharNextA (API)
  72. *
  73. * Move to next character in string unless already at '\0' terminator
  74. * DOES NOT WORK CORRECTLY FOR DBCS (eg: Japanese)
  75. *
  76. * History:
  77. * 12-03-90 IanJa Created non-NLS version.
  78. * 06-22-91 GregoryW Renamed API to conform to new naming conventions.
  79. * AnsiNext is now a #define which resolves to this
  80. * routine. This routine is only intended to support
  81. * code page 1252 for the PDK release.
  82. \***************************************************************************/
  83. LPSTR LZCharNextA(
  84. LPCSTR lpCurrentChar)
  85. {
  86. #ifdef FE_SB // CharNextA(): dbcs enabling
  87. if (IS_DBCS_ENABLED() && IsDBCSLeadByte(*lpCurrentChar)) {
  88. lpCurrentChar++;
  89. }
  90. /*
  91. * if we have only DBCS LeadingByte, we will point string-terminaler.
  92. */
  93. #endif // FE_SB
  94. if (*lpCurrentChar) {
  95. lpCurrentChar++;
  96. }
  97. return (LPSTR)lpCurrentChar;
  98. }
  99. /***************************************************************************\
  100. * CharPrevA (API)
  101. *
  102. * Move to previous character in string, unless already at start
  103. * DOES NOT WORK CORRECTLY FOR DBCS (eg: Japanese)
  104. *
  105. * History:
  106. * 12-03-90 IanJa Created non-NLS version.
  107. * 06-22-91 GregoryW Renamed API to conform to new naming conventions.
  108. * AnsiPrev is now a #define which resolves to this
  109. * routine. This routine is only intended to support
  110. * code page 1252 for the PDK release.
  111. \***************************************************************************/
  112. LPSTR LZCharPrevA(
  113. LPCSTR lpStart,
  114. LPCSTR lpCurrentChar)
  115. {
  116. #ifdef FE_SB // CharPrevA : dbcs enabling
  117. if (lpCurrentChar > lpStart) {
  118. if (IS_DBCS_ENABLED()) {
  119. LPCSTR lpChar;
  120. BOOL bDBC = FALSE;
  121. for (lpChar = --lpCurrentChar - 1 ; lpChar >= lpStart ; lpChar--) {
  122. if (!IsDBCSLeadByte(*lpChar))
  123. break;
  124. bDBC = !bDBC;
  125. }
  126. if (bDBC)
  127. lpCurrentChar--;
  128. }
  129. else
  130. lpCurrentChar--;
  131. }
  132. return (LPSTR)lpCurrentChar;
  133. #else
  134. if (lpCurrentChar > lpStart) {
  135. lpCurrentChar--;
  136. }
  137. return (LPSTR)lpCurrentChar;
  138. #endif // FE_SB
  139. }