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