1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ */
18+
19+ package org .apache .commons .csv ;
20+
21+ import static org .apache .commons .csv .Token .Type .*;
22+
23+ /**
24+ * Token is an internal token representation.
25+ * <p/>
26+ * It is used as contract between the lexer and the parser.
27+ */
28+ class Token {
29+
30+ /** length of the initial token (content-)buffer */
31+ private static final int INITIAL_TOKEN_LENGTH = 50 ;
32+
33+ enum Type {
34+ /** Token has no valid content, i.e. is in its initialized state. */
35+ INVALID ,
36+
37+ /** Token with content, at beginning or in the middle of a line. */
38+ TOKEN ,
39+
40+ /** Token (which can have content) when end of file is reached. */
41+ EOF ,
42+
43+ /** Token with content when end of a line is reached. */
44+ EORECORD
45+ }
46+
47+ /** Token type */
48+ Token .Type type = INVALID ;
49+
50+ /** The content buffer. */
51+ StringBuilder content = new StringBuilder (INITIAL_TOKEN_LENGTH );
52+
53+ /** Token ready flag: indicates a valid token with content (ready for the parser). */
54+ boolean isReady ;
55+
56+ Token reset () {
57+ content .setLength (0 );
58+ type = INVALID ;
59+ isReady = false ;
60+ return this ;
61+ }
62+ }
0 commit comments