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.

221 lines
5.3 KiB

  1. #include "private.h"
  2. //
  3. // Globals
  4. //
  5. #if 0
  6. STDAPI EnumRfc1766Info(DWORD dwIndex, PRFC1766INFOA pRfc1766Info)
  7. {
  8. EnsureRfc1766Table();
  9. if (NULL != pRfc1766Info)
  10. {
  11. if (dwIndex < g_cRfc1766)
  12. {
  13. *pRfc1766Info = g_pRfc1766[dwIndex];
  14. return S_OK;
  15. }
  16. else
  17. return S_FALSE;
  18. }
  19. return E_INVALIDARG;
  20. }
  21. #endif
  22. STDAPI LcidToRfc1766A(LCID Locale, LPSTR pszRfc1766, int iMaxLength)
  23. {
  24. UINT i;
  25. HRESULT hr = E_INVALIDARG;
  26. if (0 < iMaxLength)
  27. {
  28. for (i = 0; i < g_cRfc1766; i++)
  29. {
  30. if (MimeRfc1766[i].LcId == Locale)
  31. break;
  32. }
  33. if (i < g_cRfc1766)
  34. {
  35. if (WideCharToMultiByte(1252, 0, MimeRfc1766[i].szRfc1766, -1, pszRfc1766, iMaxLength, NULL, NULL))
  36. hr = S_OK;
  37. }
  38. else
  39. {
  40. CHAR sz[MAX_RFC1766_NAME];
  41. int nISO639 = GetLocaleInfoA(Locale, LOCALE_SISO639LANGNAME, sz, ARRAYSIZE(sz));
  42. if (nISO639)
  43. {
  44. // Two letter language name
  45. if (nISO639 == 3)
  46. {
  47. sz[2] = '-';
  48. if (3 != GetLocaleInfoA(Locale, LOCALE_SISO3166CTRYNAME, &sz[3], ARRAYSIZE(sz)-3))
  49. {
  50. sz[2] = 0;
  51. }
  52. }
  53. // Three letter language name
  54. else if (nISO639 == 4)
  55. {
  56. sz[3] = 0;
  57. }
  58. if (nISO639 <= 4)
  59. {
  60. CharLowerA(sz);
  61. if (lstrcpynA(pszRfc1766, sz, iMaxLength))
  62. {
  63. hr = S_OK;
  64. }
  65. }
  66. }
  67. else
  68. {
  69. hr = E_FAIL;
  70. }
  71. }
  72. }
  73. return hr;
  74. }
  75. STDAPI LcidToRfc1766W(LCID Locale, LPWSTR pwszRfc1766, int nChar)
  76. {
  77. UINT i;
  78. HRESULT hr = E_INVALIDARG;
  79. if (0 < nChar)
  80. {
  81. for (i = 0; i < g_cRfc1766; i++)
  82. {
  83. if (MimeRfc1766[i].LcId == Locale)
  84. break;
  85. }
  86. if (i < g_cRfc1766)
  87. {
  88. MLStrCpyNW(pwszRfc1766, MimeRfc1766[i].szRfc1766, nChar);
  89. hr = S_OK;
  90. }
  91. else
  92. {
  93. CHAR sz[MAX_RFC1766_NAME];
  94. int nISO639 = GetLocaleInfoA(Locale, LOCALE_SISO639LANGNAME, sz, ARRAYSIZE(sz));
  95. if (nISO639)
  96. {
  97. // Two letter language name
  98. if (nISO639 == 3)
  99. {
  100. sz[2] = '-';
  101. if (3 != GetLocaleInfoA(Locale, LOCALE_SISO3166CTRYNAME, &sz[3], ARRAYSIZE(sz)))
  102. {
  103. sz[2] = 0;
  104. }
  105. }
  106. // Three letter language name
  107. else if (nISO639 == 4)
  108. {
  109. sz[3] = 0;
  110. }
  111. if (nISO639 <= 4)
  112. {
  113. CharLowerA(sz);
  114. if (MultiByteToWideChar(1252, 0, sz, lstrlen(sz)+1, pwszRfc1766, nChar))
  115. {
  116. hr = S_OK;
  117. }
  118. }
  119. }
  120. else
  121. {
  122. hr = E_FAIL;
  123. }
  124. }
  125. }
  126. return hr;
  127. }
  128. STDAPI Rfc1766ToLcidW(PLCID pLocale, LPCWSTR pwszRfc1766)
  129. {
  130. UINT i;
  131. HRESULT hr = E_INVALIDARG;
  132. if (NULL != pLocale && NULL != pwszRfc1766)
  133. {
  134. for (i = 0; i < g_cRfc1766; i++)
  135. {
  136. if (!MLStrCmpIW(MimeRfc1766[i].szRfc1766, pwszRfc1766))
  137. break;
  138. }
  139. if (i < g_cRfc1766)
  140. {
  141. *pLocale = MimeRfc1766[i].LcId;
  142. hr = S_OK;
  143. }
  144. else
  145. {
  146. if (InRange(lstrlenW(pwszRfc1766), 2, MAX_RFC1766_NAME-1))
  147. {
  148. WCHAR sz[MAX_RFC1766_NAME];
  149. LPWSTR pDash;
  150. MLStrCpyNW(sz, pwszRfc1766, MAX_RFC1766_NAME);
  151. pDash = wcschr(sz, L'-');
  152. if (pDash && (pDash - sz >= 2))
  153. {
  154. *pDash = 0;
  155. }
  156. for (i = 0; i < g_cRfc1766; i++)
  157. {
  158. if (!MLStrCmpIW(MimeRfc1766[i].szRfc1766, sz))
  159. break;
  160. }
  161. if (i < g_cRfc1766)
  162. {
  163. *pLocale = MimeRfc1766[i].LcId;
  164. hr = S_FALSE;
  165. }
  166. else
  167. hr = E_FAIL;
  168. }
  169. else
  170. hr = E_FAIL;
  171. }
  172. }
  173. return hr;
  174. }
  175. STDAPI Rfc1766ToLcidA(PLCID pLocale, LPCSTR pszRfc1766)
  176. {
  177. HRESULT hr = E_INVALIDARG;
  178. if (NULL != pLocale && NULL != pszRfc1766)
  179. {
  180. int i;
  181. WCHAR sz[MAX_RFC1766_NAME];
  182. for (i = 0; i < MAX_RFC1766_NAME - 1; i++)
  183. {
  184. sz[i] = (WCHAR)pszRfc1766[i];
  185. if (0 == sz[i])
  186. break;
  187. }
  188. if (i == MAX_RFC1766_NAME -1)
  189. sz[i] = 0;
  190. hr = Rfc1766ToLcidW(pLocale, (LPCWSTR)sz);
  191. }
  192. return hr;
  193. }