ThreadUtils.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: ThreadUtils.cpp //////////////////////////////////////////////////////
  24. // GameSpy thread utils
  25. // Author: Matthew D. Campbell, July 2002
  26. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  27. //-------------------------------------------------------------------------
  28. std::wstring MultiByteToWideCharSingleLine( const char *orig )
  29. {
  30. Int len = strlen(orig);
  31. WideChar *dest = NEW WideChar[len+1];
  32. MultiByteToWideChar(CP_UTF8, 0, orig, -1, dest, len);
  33. WideChar *c = NULL;
  34. do
  35. {
  36. c = wcschr(dest, L'\n');
  37. if (c)
  38. {
  39. *c = L' ';
  40. }
  41. }
  42. while ( c != NULL );
  43. do
  44. {
  45. c = wcschr(dest, L'\r');
  46. if (c)
  47. {
  48. *c = L' ';
  49. }
  50. }
  51. while ( c != NULL );
  52. dest[len] = 0;
  53. std::wstring ret = dest;
  54. delete dest;
  55. return ret;
  56. }
  57. std::string WideCharStringToMultiByte( const WideChar *orig )
  58. {
  59. std::string ret;
  60. Int len = WideCharToMultiByte( CP_UTF8, 0, orig, wcslen(orig), NULL, 0, NULL, NULL ) + 1;
  61. if (len > 0)
  62. {
  63. char *dest = NEW char[len];
  64. WideCharToMultiByte( CP_UTF8, 0, orig, -1, dest, len, NULL, NULL );
  65. dest[len-1] = 0;
  66. ret = dest;
  67. delete dest;
  68. }
  69. return ret;
  70. }
  71. //-------------------------------------------------------------------------