2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2011-11-20 17:04:11 +04:00
|
|
|
#include "cmNewLineStyle.h"
|
|
|
|
|
2016-08-24 01:29:15 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmNewLineStyle::cmNewLineStyle()
|
|
|
|
: NewLineStyle(Invalid)
|
2011-11-20 17:04:11 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmNewLineStyle::IsValid() const
|
|
|
|
{
|
|
|
|
return NewLineStyle != Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmNewLineStyle::ReadFromArguments(const std::vector<std::string>& args,
|
|
|
|
std::string& errorString)
|
|
|
|
{
|
|
|
|
NewLineStyle = Invalid;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 0; i < args.size(); i++) {
|
|
|
|
if (args[i] == "NEWLINE_STYLE") {
|
2011-11-20 17:04:11 +04:00
|
|
|
size_t const styleIndex = i + 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() > styleIndex) {
|
2011-11-20 17:04:11 +04:00
|
|
|
const std::string eol = args[styleIndex];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (eol == "LF" || eol == "UNIX") {
|
2011-11-20 17:04:11 +04:00
|
|
|
NewLineStyle = LF;
|
|
|
|
return true;
|
2016-08-18 21:36:29 +03:00
|
|
|
}
|
|
|
|
if (eol == "CRLF" || eol == "WIN32" || eol == "DOS") {
|
2011-11-20 17:04:11 +04:00
|
|
|
NewLineStyle = CRLF;
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-18 21:36:29 +03:00
|
|
|
errorString = "NEWLINE_STYLE sets an unknown style, only LF, "
|
|
|
|
"CRLF, UNIX, DOS, and WIN32 are supported";
|
2011-11-20 17:04:11 +04:00
|
|
|
return false;
|
|
|
|
}
|
2016-08-18 21:36:29 +03:00
|
|
|
errorString = "NEWLINE_STYLE must set a style: "
|
|
|
|
"LF, CRLF, UNIX, DOS, or WIN32";
|
|
|
|
return false;
|
2011-11-20 17:04:11 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-20 17:04:11 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string cmNewLineStyle::GetCharacters() const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (NewLineStyle) {
|
2011-11-20 17:04:11 +04:00
|
|
|
case Invalid:
|
|
|
|
return "";
|
|
|
|
case LF:
|
|
|
|
return "\n";
|
|
|
|
case CRLF:
|
|
|
|
return "\r\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-20 17:04:11 +04:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmNewLineStyle::SetStyle(Style style)
|
|
|
|
{
|
|
|
|
NewLineStyle = style;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmNewLineStyle::Style cmNewLineStyle::GetStyle() const
|
|
|
|
{
|
|
|
|
return NewLineStyle;
|
|
|
|
}
|