1 /*
2  * $Id: LineBreak.java,v 1.3 2005/09/12 08:40:02 znerd Exp $
3  */
4 package org.znerd.xmlenc;
5 
6 /**
7  * Enumeration type for line breaks.
8  *
9  * @version $Revision: 1.3 $ $Date: 2005/09/12 08:40:02 $
10  * @author Jochen Schwoerer (j.schwoerer [at] web.de)
11  * @author Ernst de Haan (<a href="mailto:wfe.dehaan@gmail.com">wfe.dehaan@gmail.com</a>)
12  *
13  * @since xmlenc 0.35
14  */
15 public final class LineBreak {
16 
17    //-------------------------------------------------------------------------
18    // Class fields
19    //-------------------------------------------------------------------------
20 
21    //-------------------------------------------------------------------------
22    // Class functions
23    //-------------------------------------------------------------------------
24 
25    //-------------------------------------------------------------------------
26    // Constructors
27    //-------------------------------------------------------------------------
28 
29    /**
30     * Constructs a new <code>LineBreak</code> that consists of the specified
31     * characters.
32     *
33     * @param lineBreak
34     *    the characters the line break consists of.
35     */
LineBreak(String lineBreak)36    private LineBreak(String lineBreak) {
37       _lineBreak      = lineBreak;
38       _lineBreakChars = lineBreak.toCharArray();
39    }
40 
41 
42    //-------------------------------------------------------------------------
43    // Fields
44    //-------------------------------------------------------------------------
45 
46    /**
47     * The characters this line break consists of. This field is initialized by
48     * the constructor.
49     */
50    private final String _lineBreak;
51 
52    /**
53     * A character array containing the characters this line break consists of.
54     * This field is initialized by the constructor.
55     */
56    final char[] _lineBreakChars;
57 
58 
59    //-------------------------------------------------------------------------
60    // Methods
61    //-------------------------------------------------------------------------
62 
63    /**
64     * Empty line break. This is equivalent to using no line breaks.
65     */
66    public static final LineBreak NONE = new LineBreak("");
67 
68    /**
69     * Unix and MacOS/X line break. This represents the string <code>"\n"</code>.
70     */
71    public static final LineBreak UNIX = new LineBreak("\n");
72 
73    /**
74     * DOS and Windows line break. This represents the string <code>"\r\n"</code>.
75     */
76    public static final LineBreak DOS = new LineBreak("\r\n");
77 
78    /**
79     * MacOS line break. This represents the string <code>"\r"</code>.
80     *
81     * <p>This applies to all MacOS versions before MacOS/X. Use
82     * {@link #UNIX} as the MacOS/X line break.
83     */
84    public static final LineBreak MACOS = new LineBreak("\r");
85 
toString()86    public String toString() {
87       return _lineBreak;
88    }
89 };
90