summaryrefslogtreecommitdiff
path: root/Source/cmNewLineStyle.cxx
blob: 08f0b5b092f49dc19a98d40de03f676622b187ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*============================================================================
  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"



cmNewLineStyle::cmNewLineStyle() : NewLineStyle(Invalid)
{
}


bool cmNewLineStyle::IsValid() const
{
  return NewLineStyle != Invalid;
}


bool cmNewLineStyle::ReadFromArguments(const std::vector<std::string>& args,
                                       std::string& errorString)
{
  NewLineStyle = Invalid;

  for (size_t i = 0; i< args.size(); i++)
    {
    if (args[i] == "NEWLINE_STYLE")
      {
      size_t const styleIndex = i + 1;
      if (args.size() > styleIndex)
        {
        const std::string eol = args[styleIndex];
        if (eol == "LF" || eol == "UNIX")
          {
          NewLineStyle = LF;
          return true;
          }
        else if (eol == "CRLF" || eol == "WIN32" || eol == "DOS")
          {
          NewLineStyle = CRLF;
          return true;
          }
        else
          {
          errorString = "NEWLINE_STYLE sets an unknown style, only LF, "
                        "CRLF, UNIX, DOS, and WIN32 are supported";
          return false;
          }
        }
      else
        {
        errorString = "NEWLINE_STYLE must set a style: "
                      "LF, CRLF, UNIX, DOS, or WIN32";
        return false;
        }
      }
    }
  return true;
}


const std::string cmNewLineStyle::GetCharacters() const
{
  switch (NewLineStyle)
    {
    case Invalid:
      return "";
    case LF:
      return "\n";
    case CRLF:
      return "\r\n";
    }
  return "";
}


void cmNewLineStyle::SetStyle(Style style)
{
  NewLineStyle = style;
}


cmNewLineStyle::Style cmNewLineStyle::GetStyle() const
{
  return NewLineStyle;
}