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.

201 lines
5.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1992 - 1997 Microsoft Corporation.
  4. //
  5. // File: cphash.cxx
  6. //
  7. // Contents: Table that maps strings to codepages
  8. //
  9. // Classes: CCodePageTable
  10. //
  11. // Note: Derived from SitaramR's hash table
  12. //
  13. //----------------------------------------------------------------------------
  14. #include <pch.cxx>
  15. #pragma hdrstop
  16. #include <cphash.hxx>
  17. const ULONG CODE_JPN_JIS = 1;
  18. const ULONG CODE_JPN_EUC = 2;
  19. //
  20. // Note: These must be all lowercase and kept in alphabetical order
  21. //
  22. const CCodePageEntry CCodePageTable::_aEntries[] =
  23. {
  24. { L"ansi_x3.4-1968", 1252 },
  25. { L"ansi_x3.4-1986", 1252 },
  26. { L"ascii", 1252 },
  27. { L"big5", 950 },
  28. { L"chinese", 936 },
  29. { L"cp367", 1252 },
  30. { L"cp819", 1252 },
  31. { L"csascii", 1252 },
  32. { L"csbig5", 950 },
  33. { L"cseuckr", 949 },
  34. { L"cseucpkdfmtjapanese", CODE_JPN_EUC },
  35. { L"csgb2312", 936 },
  36. { L"csiso2022jp", CODE_JPN_JIS },
  37. { L"csiso2022kr", 50225 },
  38. { L"csiso58gb231280", 936 },
  39. { L"csisolatin2", 28592 },
  40. { L"csisolatinhebrew", 1255 },
  41. { L"cskoi8r", 20866 },
  42. { L"csksc56011987", 949 },
  43. { L"csshiftjis", 932 },
  44. { L"euc-kr", 949 },
  45. { L"extended_unix_code_packed_format_for_japanese", CODE_JPN_EUC },
  46. { L"gb2312", 936 },
  47. { L"gb_2312-80", 936 },
  48. { L"hebrew", 1255 },
  49. { L"hz-gb-2312", 936 },
  50. { L"ibm367", 1252 },
  51. { L"ibm819", 1252 },
  52. { L"ibm852", 852 },
  53. { L"ibm866", 866 },
  54. { L"iso-2022-jp", CODE_JPN_JIS },
  55. { L"iso-2022-kr", 50225 },
  56. { L"iso-8859-1", 1252 },
  57. { L"iso-8859-2", 28592 },
  58. { L"iso-8859-8", 1255 },
  59. { L"iso-ir-100", 1252 },
  60. { L"iso-ir-101", 28592 },
  61. { L"iso-ir-138", 1255 },
  62. { L"iso-ir-149", 949 },
  63. { L"iso-ir-58", 936 },
  64. { L"iso-ir-6", 1252 },
  65. { L"iso646-us", 1252 },
  66. { L"iso8859-1", 1252 },
  67. { L"iso8859-2", 28592 },
  68. { L"iso_646.irv:1991", 1252 },
  69. { L"iso_8859-1", 1252 },
  70. { L"iso_8859-1:1987", 1252 },
  71. { L"iso_8859-2", 28592 },
  72. { L"iso_8859-2:1987", 28592 },
  73. { L"iso_8859-8", 1255 },
  74. { L"iso_8859-8:1988", 1255 },
  75. { L"koi8-r", 20866 },
  76. { L"korean", 949 },
  77. { L"ks-c-5601", 949 },
  78. { L"ks-c-5601-1987", 949 },
  79. { L"ks_c_5601", 949 },
  80. { L"ks_c_5601-1987", 949 },
  81. { L"ks_c_5601-1989", 949 },
  82. { L"ksc-5601", 949 },
  83. { L"ksc5601", 949 },
  84. { L"ksc_5601", 949 },
  85. { L"l2", 28592 },
  86. { L"latin1", 1252 },
  87. { L"latin2", 28592 },
  88. { L"ms_kanji", 932 },
  89. { L"shift-jis", 932 },
  90. { L"shift_jis", 932 },
  91. { L"us", 1252 },
  92. { L"us-ascii", 1252 },
  93. { L"windows-1250", 1250 },
  94. { L"windows-1251", 1251 },
  95. { L"windows-1252", 1252 },
  96. { L"windows-1253", 1253 },
  97. { L"windows-1254", 1254 },
  98. { L"windows-1255", 1255 },
  99. { L"windows-1256", 1256 },
  100. { L"windows-1257", 1257 },
  101. { L"windows-1258", 1258 },
  102. { L"windows-874", 874 },
  103. { L"x-cp1250", 1250 },
  104. { L"x-cp1251", 1251 },
  105. { L"x-euc", CODE_JPN_EUC },
  106. { L"x-euc-jp", CODE_JPN_EUC },
  107. { L"x-sjis", 932 },
  108. { L"x-x-big5", 950 },
  109. };
  110. const unsigned CCodePageTable::_cEntries = sizeof CCodePageTable::_aEntries /
  111. sizeof CCodePageTable::_aEntries[0];
  112. //+---------------------------------------------------------------------------
  113. //
  114. // Method: EntryCompare, private, static
  115. //
  116. // Synposis: Compares a string with a string in a CCodePageEntry.
  117. // Called by bsearch.
  118. //
  119. // Arguments: [pwcKey] -- key for comparison
  120. // [pEntry] -- entry for comparison
  121. //
  122. // Returns: < 0 if pwcKey < pEntry
  123. // 0 if identical
  124. // > 0 if pwcKey > pEntry
  125. //
  126. // History: 27-Aug-97 dlee Created
  127. //
  128. //----------------------------------------------------------------------------
  129. int __cdecl CCodePageTable::EntryCompare(
  130. WCHAR const * pwcKey,
  131. CCodePageEntry const * pEntry )
  132. {
  133. return wcscmp( pwcKey, pEntry->pwcName );
  134. } //EntryCompare
  135. //+---------------------------------------------------------------------------
  136. //
  137. // Method: Lookup, public, static
  138. //
  139. // Synposis: Finds a codepage based on string and returns the codepage
  140. // The lookup is case-insensitive.
  141. //
  142. // Arguments: [pwcName] -- not-necessarily null terminated string
  143. // [cwcName] -- # of wide characters in pwcName
  144. // [ulCodePage] -- returns the corresponding codepage
  145. //
  146. // Returns: TRUE if the codepage name was found, FALSE otherwise
  147. //
  148. // History: 27-Aug-97 dlee Created
  149. //
  150. //----------------------------------------------------------------------------
  151. BOOL CCodePageTable::Lookup(
  152. WCHAR const * pwcName,
  153. unsigned cwcName,
  154. ULONG & ulCodePage )
  155. {
  156. //
  157. // Limit the length of codepage strings
  158. //
  159. WCHAR awcLowcase[ 100 ];
  160. if ( cwcName >= ( sizeof awcLowcase / sizeof WCHAR ) )
  161. return FALSE;
  162. //
  163. // Convert the string to lowercase.
  164. //
  165. RtlCopyMemory( awcLowcase, pwcName, cwcName * sizeof WCHAR );
  166. awcLowcase[ cwcName ] = 0;
  167. _wcslwr( awcLowcase );
  168. //
  169. // Try to find the codepage using the C runtime binary search function
  170. //
  171. CCodePageEntry * pEntry = (CCodePageEntry *)
  172. bsearch( awcLowcase,
  173. _aEntries,
  174. _cEntries,
  175. sizeof CCodePageEntry,
  176. (int (__cdecl *)(const void *, const void *) )
  177. EntryCompare );
  178. if ( 0 == pEntry )
  179. return FALSE;
  180. ulCodePage = pEntry->ulCodePage;
  181. return TRUE;
  182. } //Lookup