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.

79 lines
1.9 KiB

  1. // =================================================================================
  2. // Internet Character Set Conversion: Base Class
  3. // =================================================================================
  4. #include "pch.hxx"
  5. #include "ConvBase.h"
  6. CINetCodeConverter::CINetCodeConverter()
  7. {
  8. nNumOverflowBytes = 0;
  9. }
  10. HRESULT CINetCodeConverter::GetStringSizeA(BYTE const* pbySource, long lSourceSize, long* plDestSize)
  11. {
  12. fOutputMode = FALSE;
  13. return WalkString(pbySource, lSourceSize, plDestSize);
  14. }
  15. HRESULT CINetCodeConverter::ConvertStringA(BYTE const* pbySource, long lSourceSize, BYTE* pbyDest, long lDestSize, long* lConvertedSize)
  16. {
  17. HRESULT hr;
  18. fOutputMode = TRUE;
  19. pbyOutput = pbyDest;
  20. lOutputLimit = lDestSize;
  21. // Output those bytes which could not be output at previous time.
  22. if (FAILED(hr = OutputOverflowBuffer()))
  23. return hr;
  24. return WalkString(pbySource, lSourceSize, lConvertedSize);
  25. }
  26. HRESULT CINetCodeConverter::WalkString(BYTE const* pbySource, long lSourceSize, long* lConvertedSize)
  27. {
  28. HRESULT hr = S_OK;
  29. lNumOutputBytes = 0;
  30. if (pbySource) {
  31. while (lSourceSize-- > 0) {
  32. if (FAILED(hr = ConvertByte(*pbySource++)))
  33. break;
  34. }
  35. } else {
  36. hr = CleanUp();
  37. }
  38. if (lConvertedSize)
  39. *lConvertedSize = lNumOutputBytes;
  40. return hr;
  41. }
  42. HRESULT CINetCodeConverter::EndOfDest(BYTE by)
  43. {
  44. if (nNumOverflowBytes < MAXOVERFLOWBYTES)
  45. OverflowBuffer[nNumOverflowBytes++] = by;
  46. return E_FAIL;
  47. }
  48. HRESULT CINetCodeConverter::OutputOverflowBuffer()
  49. {
  50. for (int n = 0; n < nNumOverflowBytes; n++) {
  51. if (lNumOutputBytes < lOutputLimit) {
  52. *pbyOutput++ = OverflowBuffer[n];
  53. lNumOutputBytes++;
  54. } else {
  55. // Overflow again
  56. for (int n2 = 0; n < nNumOverflowBytes; n++, n2++)
  57. OverflowBuffer[n2] = OverflowBuffer[n];
  58. nNumOverflowBytes = n2;
  59. return E_FAIL;
  60. }
  61. }
  62. return S_OK;
  63. }