2011-11-20 17:04:11 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2011 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmNewLineStyle.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;
|
|
|
|
}
|