001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2014 Oliver Burn 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019package com.puppycrawl.tools.checkstyle.checks; 020 021/** 022 * Represents the options for line separator settings. 023 * 024 * @author lkuehne 025 * @see NewlineAtEndOfFileCheck 026 */ 027public enum LineSeparatorOption 028{ 029 /** Windows-style line separators. **/ 030 CRLF("\r\n"), 031 032 /** Mac-style line separators. **/ 033 CR("\r"), 034 035 /** Unix-style line separators. **/ 036 LF("\n"), 037 038 /** System default line separators. **/ 039 SYSTEM(System.getProperty("line.separator")); 040 041 /** the line separator representation */ 042 private final String lineSeparator; 043 044 /** 045 * Creates a new <code>LineSeparatorOption</code> instance. 046 * @param sep the line separator, e.g. "\r\n" 047 */ 048 private LineSeparatorOption(String sep) 049 { 050 lineSeparator = sep; 051 } 052 053 /** 054 * @param bytes a bytes array to check 055 * @return if bytes is equal to the byte representation 056 * of this line separator 057 */ 058 public boolean matches(byte[] bytes) 059 { 060 final String s = new String(bytes); 061 return s.equals(lineSeparator); 062 } 063 064 /** 065 * @return the length of the file separator, 066 * e.g. 1 for CR, 2 for CRLF, ... 067 */ 068 public int length() 069 { 070 return lineSeparator.length(); 071 } 072}