001package jmri.jmrit.logixng.util;
002
003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
004
005import java.util.ArrayList;
006import java.util.List;
007
008/**
009 * Enum for line endings
010 *
011 * @author Daniel Bergqvist (C) 2023
012 */
013@SuppressFBWarnings("VA_FORMAT_STRING_USES_NEWLINE")  // This class lets the user select the line ending
014
015public enum LineEnding {
016
017    WindowsCrLf(Bundle.getMessage("LineEnding_WindowsCrLf"), String.format("\r\n"), true),
018    MacLinuxLf(Bundle.getMessage("LineEnding_MacLinuxLf"), String.format("\n"), true),
019    System(Bundle.getMessage("LineEnding_System"), String.format("%n"), true),
020    Space(Bundle.getMessage("LineEnding_Space"), " ", false),
021    HtmlBreak(Bundle.getMessage("LineEnding_HtmlBreak"), "<br>", false),
022    None(Bundle.getMessage("LineEnding_None"), "", false);
023
024    private final String _text;
025    private final String _lineEnding;
026    private final boolean _isTrueLineEnding;
027
028    private LineEnding(String text, String lineEnding, boolean isTrueLineEnding) {
029        this._text = text;
030        this._lineEnding = lineEnding;
031        this._isTrueLineEnding = isTrueLineEnding;
032    }
033
034    public String getLineEnding() {
035        return _lineEnding;
036    }
037
038    public boolean isTrueLineEnding() {
039        return _isTrueLineEnding;
040    }
041
042    public static LineEnding[] trueValues() {
043        List<LineEnding> list = new ArrayList<>();
044        for (LineEnding le : LineEnding.values()) {
045            if (le._isTrueLineEnding) list.add(le);
046        }
047        return list.toArray(new LineEnding[0]);
048    }
049
050    @Override
051    public String toString() {
052        return _text;
053    }
054
055}