2016-09-27 19:01:08 +00: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 13:04:11 +00:00
|
|
|
#include "cmNewLineStyle.h"
|
|
|
|
|
2016-08-23 22:29:15 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmNewLineStyle::cmNewLineStyle()
|
|
|
|
: NewLineStyle(Invalid)
|
2011-11-20 13:04:11 +00: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 14:34:04 +00:00
|
|
|
for (size_t i = 0; i < args.size(); i++) {
|
|
|
|
if (args[i] == "NEWLINE_STYLE") {
|
2011-11-20 13:04:11 +00:00
|
|
|
size_t const styleIndex = i + 1;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() > styleIndex) {
|
2011-11-20 13:04:11 +00:00
|
|
|
const std::string eol = args[styleIndex];
|
2016-05-16 14:34:04 +00:00
|
|
|
if (eol == "LF" || eol == "UNIX") {
|
2011-11-20 13:04:11 +00:00
|
|
|
NewLineStyle = LF;
|
|
|
|
return true;
|
2016-08-18 18:36:29 +00:00
|
|
|
}
|
|
|
|
if (eol == "CRLF" || eol == "WIN32" || eol == "DOS") {
|
2011-11-20 13:04:11 +00:00
|
|
|
NewLineStyle = CRLF;
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-18 18:36:29 +00:00
|
|
|
errorString = "NEWLINE_STYLE sets an unknown style, only LF, "
|
|
|
|
"CRLF, UNIX, DOS, and WIN32 are supported";
|
2011-11-20 13:04:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-08-18 18:36:29 +00:00
|
|
|
errorString = "NEWLINE_STYLE must set a style: "
|
|
|
|
"LF, CRLF, UNIX, DOS, or WIN32";
|
|
|
|
return false;
|
2011-11-20 13:04:11 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-20 13:04:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string cmNewLineStyle::GetCharacters() const
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
switch (NewLineStyle) {
|
2011-11-20 13:04:11 +00:00
|
|
|
case Invalid:
|
|
|
|
return "";
|
|
|
|
case LF:
|
|
|
|
return "\n";
|
|
|
|
case CRLF:
|
|
|
|
return "\r\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-20 13:04:11 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmNewLineStyle::SetStyle(Style style)
|
|
|
|
{
|
|
|
|
NewLineStyle = style;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmNewLineStyle::Style cmNewLineStyle::GetStyle() const
|
|
|
|
{
|
|
|
|
return NewLineStyle;
|
|
|
|
}
|