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.

81 lines
2.2 KiB

  1. // ========================================================================
  2. //
  3. // Module: langtocpid.cpp
  4. //
  5. // Copyright Microsoft Corporation 1997, All Rights Reserved.
  6. //
  7. // Description: Implements language to cpid mapping cache
  8. // defined in inc\langtocpid.cpp
  9. //
  10. // ========================================================================
  11. #include "_davprs.h"
  12. #include <langtocpid.h>
  13. // ========================================================================
  14. //
  15. // Singleton class CLangToCpidCache
  16. //
  17. // The CLangToCpidCache singleton class which provides a cache for fast
  18. // retrieval of code pages based on values in the Accept-Language header.
  19. //
  20. // ========================================================================
  21. // CLangToCpidCache::FCreateInstance() ------------------------------------
  22. //
  23. // Initialization of the singleton class
  24. //
  25. BOOL
  26. CLangToCpidCache::FCreateInstance()
  27. {
  28. BOOL fSuccess = FALSE;
  29. UINT uiCpid; // Index into the static table mapping language strings and cpids
  30. // Init ourselves
  31. //
  32. CreateInstance();
  33. // Init our cache
  34. //
  35. if (!Instance().m_cacheAcceptLangToCPID.FInit())
  36. goto ret;
  37. // Fill our cache with all the language strings from
  38. // the static table defined in the header.
  39. //
  40. for (uiCpid = 0; uiCpid < gc_cAcceptLangToCPIDTable; uiCpid++)
  41. {
  42. CRCSzi szKey (gc_rgAcceptLangToCPIDTable[uiCpid].pszLang);
  43. // Check that we don't have duplicate NAMES in our table
  44. // by doing a Lookup before we actually add each prop -- debug only!
  45. //
  46. Assert (!Instance().m_cacheAcceptLangToCPID.Lookup (szKey));
  47. // Add the lang string. Report a failure if we can't add.
  48. //
  49. if (!Instance().m_cacheAcceptLangToCPID.FAdd (szKey,
  50. gc_rgAcceptLangToCPIDTable[uiCpid].cpid))
  51. goto ret;
  52. }
  53. // Completed successfully.
  54. //
  55. fSuccess = TRUE;
  56. ret:
  57. return fSuccess;
  58. }
  59. // CLangToCpidCache::FFindCpid() ------------------------------------------
  60. //
  61. // Find the CPID from language string
  62. //
  63. BOOL
  64. CLangToCpidCache::FFindCpid(IN LPCSTR pszLang, OUT UINT * puiCpid)
  65. {
  66. return Instance().m_cacheAcceptLangToCPID.FFetch(CRCSzi(pszLang),
  67. puiCpid);
  68. }