1
0

cmNewLineStyle.cxx 1.6 KB

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