Encoding.hxx.in 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
  3. #ifndef @KWSYS_NAMESPACE@_Encoding_hxx
  4. #define @KWSYS_NAMESPACE@_Encoding_hxx
  5. #include <@KWSYS_NAMESPACE@/Configure.hxx>
  6. #include <string>
  7. #include <vector>
  8. namespace @KWSYS_NAMESPACE@ {
  9. class @KWSYS_NAMESPACE@_EXPORT Encoding
  10. {
  11. public:
  12. // Container class for argc/argv.
  13. class @KWSYS_NAMESPACE@_EXPORT CommandLineArguments
  14. {
  15. public:
  16. // On Windows, get the program command line arguments
  17. // in this Encoding module's 8 bit encoding.
  18. // On other platforms the given argc/argv is used, and
  19. // to be consistent, should be the argc/argv from main().
  20. static CommandLineArguments Main(int argc, char const* const* argv);
  21. // Construct CommandLineArguments with the given
  22. // argc/argv. It is assumed that the string is already
  23. // in the encoding used by this module.
  24. CommandLineArguments(int argc, char const* const* argv);
  25. // Construct CommandLineArguments with the given
  26. // argc and wide argv. This is useful if wmain() is used.
  27. CommandLineArguments(int argc, wchar_t const* const* argv);
  28. ~CommandLineArguments();
  29. CommandLineArguments(const CommandLineArguments&);
  30. CommandLineArguments& operator=(const CommandLineArguments&);
  31. int argc() const;
  32. char const* const* argv() const;
  33. protected:
  34. std::vector<char*> argv_;
  35. };
  36. /**
  37. * Convert between char and wchar_t
  38. */
  39. #if @KWSYS_NAMESPACE@_STL_HAS_WSTRING
  40. // Convert a narrow string to a wide string.
  41. // On Windows, UTF-8 is assumed, and on other platforms,
  42. // the current locale is assumed.
  43. static std::wstring ToWide(const std::string& str);
  44. static std::wstring ToWide(const char* str);
  45. // Convert a wide string to a narrow string.
  46. // On Windows, UTF-8 is assumed, and on other platforms,
  47. // the current locale is assumed.
  48. static std::string ToNarrow(const std::wstring& str);
  49. static std::string ToNarrow(const wchar_t* str);
  50. #if defined(_WIN32)
  51. /**
  52. * Convert the path to an extended length path to avoid MAX_PATH length
  53. * limitations on Windows. If the input is a local path the result will be
  54. * prefixed with \\?\; if the input is instead a network path, the result
  55. * will be prefixed with \\?\UNC\. All output will also be converted to
  56. * absolute paths with Windows-style backslashes.
  57. **/
  58. static std::wstring ToWindowsExtendedPath(std::string const&);
  59. #endif
  60. #endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING
  61. }; // class Encoding
  62. } // namespace @KWSYS_NAMESPACE@
  63. #endif