cmNewLineStyle.cxx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmNewLineStyle.h"
  4. #include <cstddef>
  5. cmNewLineStyle::cmNewLineStyle() = default;
  6. bool cmNewLineStyle::IsValid() const
  7. {
  8. return this->NewLineStyle != Invalid;
  9. }
  10. bool cmNewLineStyle::ReadFromArguments(const std::vector<std::string>& args,
  11. std::string& errorString)
  12. {
  13. this->NewLineStyle = Invalid;
  14. for (size_t i = 0; i < args.size(); i++) {
  15. if (args[i] == "NEWLINE_STYLE") {
  16. size_t const styleIndex = i + 1;
  17. if (args.size() > styleIndex) {
  18. std::string const& eol = args[styleIndex];
  19. if (eol == "LF" || eol == "UNIX") {
  20. this->NewLineStyle = LF;
  21. return true;
  22. }
  23. if (eol == "CRLF" || eol == "WIN32" || eol == "DOS") {
  24. this->NewLineStyle = CRLF;
  25. return true;
  26. }
  27. errorString = "NEWLINE_STYLE sets an unknown style, only LF, "
  28. "CRLF, UNIX, DOS, and WIN32 are supported";
  29. return false;
  30. }
  31. errorString = "NEWLINE_STYLE must set a style: "
  32. "LF, CRLF, UNIX, DOS, or WIN32";
  33. return false;
  34. }
  35. }
  36. return true;
  37. }
  38. std::string cmNewLineStyle::GetCharacters() const
  39. {
  40. switch (this->NewLineStyle) {
  41. case Invalid:
  42. return "";
  43. case LF:
  44. return "\n";
  45. case CRLF:
  46. return "\r\n";
  47. }
  48. return "";
  49. }
  50. void cmNewLineStyle::SetStyle(Style style)
  51. {
  52. this->NewLineStyle = style;
  53. }
  54. cmNewLineStyle::Style cmNewLineStyle::GetStyle() const
  55. {
  56. return this->NewLineStyle;
  57. }