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.

61 lines
951 B

  1. // CUSTRING.CPP
  2. //
  3. // Implementation of the CUSTRING class, a lightweight class used to convert
  4. // strings seamlessly between ANSI and Unicode.
  5. //
  6. // Derived from STRCORE.CPP.
  7. #include "precomp.h"
  8. #include <cstring.hpp>
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. CUSTRING::CUSTRING(PCWSTR wszText) :
  14. wszData((PWSTR)wszText),
  15. szData(NULL),
  16. bUnicodeNew(FALSE),
  17. bAnsiNew(FALSE)
  18. {
  19. // AssignString;
  20. }
  21. CUSTRING::CUSTRING(PCSTR szText) :
  22. szData((PSTR)szText),
  23. wszData(NULL),
  24. bUnicodeNew(FALSE),
  25. bAnsiNew(FALSE)
  26. {
  27. // AssignString;
  28. }
  29. CUSTRING::~CUSTRING()
  30. {
  31. if (bUnicodeNew) {
  32. delete wszData;
  33. }
  34. if (bAnsiNew) {
  35. delete szData;
  36. }
  37. }
  38. CUSTRING::operator PWSTR()
  39. {
  40. if (szData && !wszData) {
  41. wszData = AnsiToUnicode(szData);
  42. bUnicodeNew = TRUE;
  43. }
  44. return wszData;
  45. }
  46. CUSTRING::operator PSTR()
  47. {
  48. if (wszData && !szData) {
  49. szData = UnicodeToAnsi(wszData);
  50. bAnsiNew = TRUE;
  51. }
  52. return szData;
  53. }