]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/parser/WhitespaceOrCaseInsensitiveLetterState.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / parser / WhitespaceOrCaseInsensitiveLetterState.java
CommitLineData
878ddf1f 1/*\r
2 *\r
3 * Copyright 2002-2004 The Ant-Contrib project\r
4 *\r
5 * Licensed under the Apache License, Version 2.0 (the "License");\r
6 * you may not use this file except in compliance with the License.\r
7 * You may obtain a copy of the License at\r
8 *\r
9 * http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 * Unless required by applicable law or agreed to in writing, software\r
12 * distributed under the License is distributed on an "AS IS" BASIS,\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 * See the License for the specific language governing permissions and\r
15 * limitations under the License.\r
16 */\r
17package net.sf.antcontrib.cpptasks.parser;\r
18\r
19/**\r
20 * This parser state checks consumed characters against a specific character\r
21 * (case insensitive) or whitespace.\r
22 *\r
23 * @author Curt Arnold\r
24 */\r
25public final class WhitespaceOrCaseInsensitiveLetterState\r
26 extends\r
27 AbstractParserState {\r
28 /**\r
29 * Next state if the character is found.\r
30 */\r
31 private final AbstractParserState nextState;\r
32\r
33 /**\r
34 * Character to match (lower case).\r
35 */\r
36 private final char lowerLetter;\r
37\r
38 /**\r
39 * Character to match (upper case).\r
40 */\r
41 private final char upperLetter;\r
42\r
43 /**\r
44 * Constructor.\r
45 *\r
46 * @param parser\r
47 * parser\r
48 * @param matchLetter\r
49 * letter to match\r
50 * @param nextStateArg\r
51 * next state if a match on the letter\r
52 */\r
53 public WhitespaceOrCaseInsensitiveLetterState(final AbstractParser parser,\r
54 final char matchLetter,\r
55 final AbstractParserState\r
56 nextStateArg) {\r
57 super(parser);\r
58 this.lowerLetter = Character.toLowerCase(matchLetter);\r
59 this.upperLetter = Character.toUpperCase(matchLetter);\r
60 this.nextState = nextStateArg;\r
61 }\r
62\r
63 /**\r
64 * Consumes a character and returns the next state for the parser.\r
65 *\r
66 * @param ch\r
67 * next character\r
68 * @return the configured nextState if ch is the expected character or the\r
69 * configure noMatchState otherwise.\r
70 */\r
71 public AbstractParserState consume(final char ch) {\r
72 if (ch == lowerLetter || ch == upperLetter) {\r
73 return nextState;\r
74 }\r
75 if (ch == ' ' || ch == '\t') {\r
76 return this;\r
77 }\r
78 if (ch == '\n') {\r
79 getParser().getNewLineState();\r
80 }\r
81 return null;\r
82 }\r
83}\r