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.

62 lines
1.0 KiB

  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 <oprahcom.h>
  9. #include <cstring.hpp>
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. CUSTRING::CUSTRING(PCWSTR wszText) :
  15. wszData((PWSTR)wszText),
  16. szData(NULL),
  17. bUnicodeNew(FALSE),
  18. bAnsiNew(FALSE)
  19. {
  20. // AssignString;
  21. }
  22. CUSTRING::CUSTRING(PCSTR szText) :
  23. szData((PSTR)szText),
  24. wszData(NULL),
  25. bUnicodeNew(FALSE),
  26. bAnsiNew(FALSE)
  27. {
  28. // AssignString;
  29. }
  30. CUSTRING::~CUSTRING()
  31. {
  32. if (bUnicodeNew) {
  33. delete wszData;
  34. }
  35. if (bAnsiNew) {
  36. delete szData;
  37. }
  38. }
  39. CUSTRING::operator PWSTR()
  40. {
  41. if (szData && !wszData) {
  42. wszData = AnsiToUnicode(szData);
  43. bUnicodeNew = TRUE;
  44. }
  45. return wszData;
  46. }
  47. CUSTRING::operator PSTR()
  48. {
  49. if (wszData && !szData) {
  50. szData = UnicodeToAnsi(wszData);
  51. bAnsiNew = TRUE;
  52. }
  53. return szData;
  54. }