Source code of Windows XP (NT5)
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.

59 lines
1.2 KiB

  1. #ifndef CONVBASE_H_
  2. #define CONVBASE_H_
  3. #define MAXOVERFLOWCHARS 16
  4. class CINetCodeConverter
  5. {
  6. private:
  7. UINT m_uCodePage;
  8. int m_nCodeSet;
  9. BOOL m_fOutput;
  10. LPSTR m_lpDestStr;
  11. int m_cchDest;
  12. int m_cchOutput;
  13. int m_cchOverflow;
  14. UCHAR m_OverflowBuffer[MAXOVERFLOWCHARS];
  15. public:
  16. CINetCodeConverter();
  17. CINetCodeConverter(UINT uCodePage, int nCodeSet);
  18. virtual ~CINetCodeConverter() {}
  19. int GetCodeSet() {return m_nCodeSet;}
  20. HRESULT GetStringSizeA(LPCSTR lpSrcStr, int cchSrc, LPINT lpnSize = NULL);
  21. HRESULT ConvertStringA(LPCSTR lpSrcStr, int cchSrc, LPSTR lpDestStr, int cchDest, LPINT lpnSize = NULL);
  22. virtual int GetUnconvertBytes() = 0 ;
  23. virtual DWORD GetConvertMode() = 0 ;
  24. virtual void SetConvertMode(DWORD mode) = 0 ;
  25. private:
  26. HRESULT WalkString(LPCSTR lpSrcStr, int cchSrc, LPINT lpnSize);
  27. BOOL EndOfDest(UCHAR tc);
  28. BOOL OutputOverflowBuffer();
  29. protected:
  30. virtual HRESULT ConvertChar(UCHAR tc, int cchSrc=-1) = 0;
  31. virtual BOOL CleanUp() = 0;
  32. protected:
  33. inline BOOL Output(UCHAR tc)
  34. {
  35. BOOL fDone = TRUE;
  36. if (m_fOutput) {
  37. if (m_cchOutput < m_cchDest) {
  38. *m_lpDestStr++ = tc;
  39. } else {
  40. (void)EndOfDest(tc);
  41. fDone = FALSE;
  42. }
  43. }
  44. m_cchOutput++;
  45. return fDone;
  46. }
  47. };
  48. #endif /* CONVBASE_H_ */