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.

121 lines
3.9 KiB

  1. // ============================================================================
  2. // Internet Character Set Conversion: Base Class
  3. // ============================================================================
  4. #include "private.h"
  5. #include "convbase.h"
  6. #include "fechrcnv.h"
  7. #include "codepage.h"
  8. /******************************************************************************
  9. ************************** C O N S T R U C T O R **************************
  10. ******************************************************************************/
  11. CINetCodeConverter::CINetCodeConverter()
  12. {
  13. m_uCodePage = 0;
  14. m_nCodeSet = CP_UNDEFINED;
  15. m_cchOverflow = 0;
  16. }
  17. CINetCodeConverter::CINetCodeConverter(UINT uCodePage, int nCodeSet)
  18. {
  19. m_uCodePage = uCodePage;
  20. m_nCodeSet = nCodeSet;
  21. m_cchOverflow = 0;
  22. }
  23. /******************************************************************************
  24. ******************** G E T S T R I N G S I Z E A ********************
  25. ******************************************************************************/
  26. HRESULT CINetCodeConverter::GetStringSizeA(LPCSTR lpSrcStr, int cchSrc, LPINT lpnSize)
  27. {
  28. m_fOutput = FALSE;
  29. return WalkString(lpSrcStr, cchSrc, lpnSize);
  30. }
  31. /******************************************************************************
  32. ********************* C O N V E R T S T R I N G A *********************
  33. ******************************************************************************/
  34. HRESULT CINetCodeConverter::ConvertStringA(LPCSTR lpSrcStr, int cchSrc, LPSTR lpDestStr, int cchDest, LPINT lpnSize)
  35. {
  36. m_fOutput = TRUE;
  37. m_lpDestStr = lpDestStr;
  38. m_cchDest = cchDest;
  39. if ( !OutputOverflowBuffer() ) // Output those chars which could not be output at previous time.
  40. return FALSE;
  41. return WalkString(lpSrcStr, cchSrc, lpnSize);
  42. }
  43. /******************************************************************************
  44. ************************** W A L K S T R I N G **************************
  45. ******************************************************************************/
  46. HRESULT CINetCodeConverter::WalkString(LPCSTR lpSrcStr, int cchSrc, LPINT lpnSize)
  47. {
  48. HRESULT hr = S_OK;
  49. m_cchOutput = 0;
  50. if (lpSrcStr) {
  51. while (cchSrc-- > 0) {
  52. HRESULT _hr = ConvertChar(*lpSrcStr++, cchSrc);
  53. if (!SUCCEEDED(_hr))
  54. {
  55. hr = _hr;
  56. break;
  57. }
  58. else
  59. if (hr == S_OK && _hr == S_FALSE)
  60. hr = S_FALSE;
  61. }
  62. } else {
  63. if (!CleanUp())
  64. hr = E_FAIL;
  65. }
  66. if (lpnSize)
  67. *lpnSize = m_cchOutput;
  68. return hr;
  69. }
  70. /******************************************************************************
  71. ************************** E N D O F D E S T **************************
  72. ******************************************************************************/
  73. BOOL CINetCodeConverter::EndOfDest(UCHAR tc)
  74. {
  75. if (m_cchOverflow < MAXOVERFLOWCHARS) {
  76. m_OverflowBuffer[m_cchOverflow++] = tc;
  77. return TRUE;
  78. } else {
  79. return FALSE; // Overflow on Overflow buffer, No way
  80. }
  81. }
  82. /******************************************************************************
  83. *************** O U T P U T O V E R F L O W B U F F E R ***************
  84. ******************************************************************************/
  85. BOOL CINetCodeConverter::OutputOverflowBuffer()
  86. {
  87. for (int n = 0; n < m_cchOverflow; n++) {
  88. if (m_cchOutput < m_cchDest) {
  89. *m_lpDestStr++ = m_OverflowBuffer[n];
  90. m_cchOutput++;
  91. } else {
  92. // Overflow again
  93. for (int n2 = 0; n < m_cchOverflow; n++, n2++)
  94. m_OverflowBuffer[n2] = m_OverflowBuffer[n];
  95. m_cchOverflow = n2;
  96. return FALSE;
  97. }
  98. }
  99. return TRUE;
  100. }