cmNewLineStyle.cxx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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()
  12. : NewLineStyle(Invalid)
  13. {
  14. }
  15. bool cmNewLineStyle::IsValid() const
  16. {
  17. return NewLineStyle != Invalid;
  18. }
  19. bool cmNewLineStyle::ReadFromArguments(const std::vector<std::string>& args,
  20. std::string& errorString)
  21. {
  22. NewLineStyle = Invalid;
  23. for (size_t i = 0; i < args.size(); i++) {
  24. if (args[i] == "NEWLINE_STYLE") {
  25. size_t const styleIndex = i + 1;
  26. if (args.size() > styleIndex) {
  27. const std::string eol = args[styleIndex];
  28. if (eol == "LF" || eol == "UNIX") {
  29. NewLineStyle = LF;
  30. return true;
  31. }
  32. if (eol == "CRLF" || eol == "WIN32" || eol == "DOS") {
  33. NewLineStyle = CRLF;
  34. return true;
  35. }
  36. errorString = "NEWLINE_STYLE sets an unknown style, only LF, "
  37. "CRLF, UNIX, DOS, and WIN32 are supported";
  38. return false;
  39. }
  40. errorString = "NEWLINE_STYLE must set a style: "
  41. "LF, CRLF, UNIX, DOS, or WIN32";
  42. return false;
  43. }
  44. }
  45. return true;
  46. }
  47. const std::string cmNewLineStyle::GetCharacters() const
  48. {
  49. switch (NewLineStyle) {
  50. case Invalid:
  51. return "";
  52. case LF:
  53. return "\n";
  54. case CRLF:
  55. return "\r\n";
  56. }
  57. return "";
  58. }
  59. void cmNewLineStyle::SetStyle(Style style)
  60. {
  61. NewLineStyle = style;
  62. }
  63. cmNewLineStyle::Style cmNewLineStyle::GetStyle() const
  64. {
  65. return NewLineStyle;
  66. }