]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*\r |
2 | *\r | |
3 | * Copyright 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 | |
17 | package 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).\r | |
22 | *\r | |
23 | * @author Curt Arnold\r | |
24 | */\r | |
25 | public final class CaseInsensitiveLetterState\r | |
26 | extends AbstractParserState {\r | |
27 | /**\r | |
28 | * Next state if a match is found.\r | |
29 | */\r | |
30 | private final AbstractParserState nextState;\r | |
31 | \r | |
32 | /**\r | |
33 | * Next state if not match is found.\r | |
34 | */\r | |
35 | private final AbstractParserState noMatchState;\r | |
36 | \r | |
37 | /**\r | |
38 | * Lower case version of character to match.\r | |
39 | */\r | |
40 | private final char lowerLetter;\r | |
41 | \r | |
42 | /**\r | |
43 | * Lower case version of character to match.\r | |
44 | */\r | |
45 | private final char upperLetter;\r | |
46 | \r | |
47 | /**\r | |
48 | * Constructor.\r | |
49 | *\r | |
50 | * @param parser\r | |
51 | * parser\r | |
52 | * @param matchLetter\r | |
53 | * letter to match\r | |
54 | * @param nextStateArg\r | |
55 | * next state if a match on the letter\r | |
56 | * @param noMatchStateArg\r | |
57 | * state if no match on letter\r | |
58 | */\r | |
59 | public CaseInsensitiveLetterState(final AbstractParser parser,\r | |
60 | final char matchLetter,\r | |
61 | final AbstractParserState nextStateArg,\r | |
62 | final AbstractParserState noMatchStateArg) {\r | |
63 | super(parser);\r | |
64 | this.lowerLetter = Character.toLowerCase(matchLetter);\r | |
65 | this.upperLetter = Character.toUpperCase(matchLetter);\r | |
66 | this.nextState = nextStateArg;\r | |
67 | this.noMatchState = noMatchStateArg;\r | |
68 | }\r | |
69 | \r | |
70 | /**\r | |
71 | * Consumes a character and returns the next state for the parser.\r | |
72 | *\r | |
73 | * @param ch\r | |
74 | * next character\r | |
75 | * @return the configured nextState if ch is the expected character or the\r | |
76 | * configure noMatchState otherwise.\r | |
77 | */\r | |
78 | public AbstractParserState consume(final char ch) {\r | |
79 | if (ch == lowerLetter || ch == upperLetter) {\r | |
80 | return nextState;\r | |
81 | }\r | |
82 | if (ch == '\n') {\r | |
83 | getParser().getNewLineState();\r | |
84 | }\r | |
85 | return noMatchState;\r | |
86 | }\r | |
87 | }\r |