cmNewLineStyle.cxx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2011 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmNewLineStyle.h"
  11. cmNewLineStyle::cmNewLineStyle() : NewLineStyle(Invalid)
  12. {
  13. }
  14. bool cmNewLineStyle::IsValid() const
  15. {
  16. return NewLineStyle != Invalid;
  17. }
  18. bool cmNewLineStyle::ReadFromArguments(const std::vector<std::string>& args,
  19. std::string& errorString)
  20. {
  21. NewLineStyle = Invalid;
  22. for (size_t i = 0; i< args.size(); i++)
  23. {
  24. if (args[i] == "NEWLINE_STYLE")
  25. {
  26. size_t const styleIndex = i + 1;
  27. if (args.size() > styleIndex)
  28. {
  29. const std::string eol = args[styleIndex];
  30. if (eol == "LF" || eol == "UNIX")
  31. {
  32. NewLineStyle = LF;
  33. return true;
  34. }
  35. else if (eol == "CRLF" || eol == "WIN32" || eol == "DOS")
  36. {
  37. NewLineStyle = CRLF;
  38. return true;
  39. }
  40. else
  41. {
  42. errorString = "NEWLINE_STYLE sets an unknown style, only LF, "
  43. "CRLF, UNIX, DOS, and WIN32 are supported";
  44. return false;
  45. }
  46. }
  47. else
  48. {
  49. errorString = "NEWLINE_STYLE must set a style: "
  50. "LF, CRLF, UNIX, DOS, or WIN32";
  51. return false;
  52. }
  53. }
  54. }
  55. return true;
  56. }
  57. const std::string cmNewLineStyle::GetCharacters() const
  58. {
  59. switch (NewLineStyle)
  60. {
  61. case Invalid:
  62. return "";
  63. case LF:
  64. return "\n";
  65. case CRLF:
  66. return "\r\n";
  67. }
  68. return "";
  69. }
  70. void cmNewLineStyle::SetStyle(Style style)
  71. {
  72. NewLineStyle = style;
  73. }
  74. cmNewLineStyle::Style cmNewLineStyle::GetStyle() const
  75. {
  76. return NewLineStyle;
  77. }