cmNewLineStyle.cxx 1.6 KB

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