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