cmake/Source/cmNewLineStyle.cxx

66 lines
1.6 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2012-02-18 12:40:36 +02:00
#include "cmNewLineStyle.h"
2020-02-01 23:06:01 +01:00
#include <cstddef>
2016-10-30 18:24:19 +01:00
2019-11-11 23:01:05 +01:00
cmNewLineStyle::cmNewLineStyle() = default;
2012-02-18 12:40:36 +02:00
bool cmNewLineStyle::IsValid() const
{
2021-09-14 00:13:48 +02:00
return this->NewLineStyle != Invalid;
2012-02-18 12:40:36 +02:00
}
bool cmNewLineStyle::ReadFromArguments(const std::vector<std::string>& args,
std::string& errorString)
{
2021-09-14 00:13:48 +02:00
this->NewLineStyle = Invalid;
2012-02-18 12:40:36 +02:00
2016-07-09 11:21:54 +02:00
for (size_t i = 0; i < args.size(); i++) {
if (args[i] == "NEWLINE_STYLE") {
2012-02-18 12:40:36 +02:00
size_t const styleIndex = i + 1;
2016-07-09 11:21:54 +02:00
if (args.size() > styleIndex) {
2017-07-20 19:35:53 +02:00
std::string const& eol = args[styleIndex];
2016-07-09 11:21:54 +02:00
if (eol == "LF" || eol == "UNIX") {
2021-09-14 00:13:48 +02:00
this->NewLineStyle = LF;
2012-02-18 12:40:36 +02:00
return true;
2016-10-30 18:24:19 +01:00
}
if (eol == "CRLF" || eol == "WIN32" || eol == "DOS") {
2021-09-14 00:13:48 +02:00
this->NewLineStyle = CRLF;
2012-02-18 12:40:36 +02:00
return true;
}
2016-10-30 18:24:19 +01:00
errorString = "NEWLINE_STYLE sets an unknown style, only LF, "
"CRLF, UNIX, DOS, and WIN32 are supported";
2012-02-18 12:40:36 +02:00
return false;
}
2016-10-30 18:24:19 +01:00
errorString = "NEWLINE_STYLE must set a style: "
"LF, CRLF, UNIX, DOS, or WIN32";
return false;
2012-02-18 12:40:36 +02:00
}
2016-07-09 11:21:54 +02:00
}
2012-02-18 12:40:36 +02:00
return true;
}
2020-02-01 23:06:01 +01:00
std::string cmNewLineStyle::GetCharacters() const
2012-02-18 12:40:36 +02:00
{
2021-09-14 00:13:48 +02:00
switch (this->NewLineStyle) {
2012-02-18 12:40:36 +02:00
case Invalid:
return "";
case LF:
return "\n";
case CRLF:
return "\r\n";
2016-07-09 11:21:54 +02:00
}
2012-02-18 12:40:36 +02:00
return "";
}
void cmNewLineStyle::SetStyle(Style style)
{
2021-09-14 00:13:48 +02:00
this->NewLineStyle = style;
2012-02-18 12:40:36 +02:00
}
cmNewLineStyle::Style cmNewLineStyle::GetStyle() const
{
2021-09-14 00:13:48 +02:00
return this->NewLineStyle;
2012-02-18 12:40:36 +02:00
}