1 /*
2 * CSVeed (https://github.com/42BV/CSVeed)
3 *
4 * Copyright 2013-2023 CSVeed.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of The Apache Software License,
8 * Version 2.0 which accompanies this distribution, and is available at
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 */
11 package org.csveed.token;
12
13 /**
14 * The Enum ParseState.
15 */
16 public enum ParseState {
17
18 /** The skip line. */
19 SKIP_LINE(false, false, false, false, true),
20
21 /** The skip line finished. */
22 SKIP_LINE_FINISHED(false, true, false, false, true),
23
24 /** The comment line. */
25 COMMENT_LINE(false, false, false, false, true),
26
27 /** The comment line finished. */
28 COMMENT_LINE_FINISHED(false, true, false, false, true),
29
30 /** The start of line. */
31 START_OF_LINE(false, false, false, false, false),
32
33 /** The outside before field. */
34 OUTSIDE_BEFORE_FIELD(false, false, false, false, false),
35
36 /** The outside after field. */
37 OUTSIDE_AFTER_FIELD(false, false, false, false, false),
38
39 /** The inside field. */
40 INSIDE_FIELD(true, false, false, false, false),
41
42 /** The first char inside quoted field. */
43 FIRST_CHAR_INSIDE_QUOTED_FIELD(false, false, false, true, false),
44
45 /** The inside quoted field. */
46 INSIDE_QUOTED_FIELD(true, false, false, true, false),
47
48 /** The escaping. */
49 ESCAPING(false, false, false, false, false),
50
51 /** The separator. */
52 SEPARATOR(false, false, true, false, false),
53
54 /** The line finished. */
55 LINE_FINISHED(false, true, true, false, false),
56
57 /** The finished. */
58 FINISHED(false, true, true, false, false);
59
60 /** When in this state, encountered symbols must be made part of the token. */
61 private final boolean tokenize;
62
63 /** When in this state, reading of the line is done. */
64 private final boolean lineFinished;
65
66 /** When in this state, the token may be popped. */
67 private final boolean popToken;
68
69 /** When a quote character is encountered here, this state MAY trigger an upgrade of the encountered symbol. */
70 private final boolean upgradeQuoteToEscape;
71
72 /** When in this state, ignore the entire line. */
73 private final boolean ignore;
74
75 /**
76 * Instantiates a new parses the state.
77 *
78 * @param tokenize
79 * the tokenize
80 * @param lineFinished
81 * the line finished
82 * @param popToken
83 * the pop token
84 * @param upgradeQuoteToEscape
85 * the upgrade quote to escape
86 * @param ignore
87 * the ignore
88 */
89 ParseState(final boolean tokenize, final boolean lineFinished, final boolean popToken,
90 final boolean upgradeQuoteToEscape, final boolean ignore) {
91 this.tokenize = tokenize;
92 this.lineFinished = lineFinished;
93 this.popToken = popToken;
94 this.upgradeQuoteToEscape = upgradeQuoteToEscape;
95 this.ignore = ignore;
96 }
97
98 /**
99 * Checks if is tokenize.
100 *
101 * @return true, if is tokenize
102 */
103 public boolean isTokenize() {
104 return this.tokenize;
105 }
106
107 /**
108 * Checks if is line finished.
109 *
110 * @return true, if is line finished
111 */
112 public boolean isLineFinished() {
113 return this.lineFinished;
114 }
115
116 /**
117 * Checks if is pop token.
118 *
119 * @return true, if is pop token
120 */
121 public boolean isPopToken() {
122 return this.popToken;
123 }
124
125 /**
126 * Checks if is upgrade quote to escape.
127 *
128 * @return true, if is upgrade quote to escape
129 */
130 public boolean isUpgradeQuoteToEscape() {
131 return this.upgradeQuoteToEscape;
132 }
133
134 /**
135 * Checks if is ignore.
136 *
137 * @return true, if is ignore
138 */
139 public boolean isIgnore() {
140 return this.ignore;
141 }
142
143 /**
144 * Trim.
145 *
146 * @return true, if successful
147 */
148 public boolean trim() {
149 return this == INSIDE_FIELD;
150 }
151 }