01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.diff.tag;
17:
18: /**
19: * A TextAtom with an identifier from a limited set of delimiter strings.
20: */
21: public class DelimiterAtom extends TextAtom {
22:
23: public DelimiterAtom(char c) {
24: super ("" + c);
25: }
26:
27: public static boolean isValidDelimiter(String s) {
28: if (s.length() == 1)
29: return isValidDelimiter(s.charAt(0));
30: return false;
31: }
32:
33: public static boolean isValidDelimiter(char c) {
34: switch (c) {
35: // Basic Delimiters
36: case '/':
37: case '.':
38: case '!':
39: case ',':
40: case ';':
41: case '?':
42: case ' ':
43: case '=':
44: case '\'':
45: case '"':
46: case '\t':
47: case '\r':
48: case '\n':
49: // Extra Delimiters
50: case '[':
51: case ']':
52: case '{':
53: case '}':
54: case '(':
55: case ')':
56: case '&':
57: case '|':
58: case '\\':
59: case '-':
60: case '_':
61: case '+':
62: case '*':
63: case ':':
64: return true;
65: default:
66: return false;
67: }
68: }
69:
70: @Override
71: public boolean isValidAtom(String s) {
72: return super .isValidAtom(s) && isValidDelimiterAtom(s);
73: }
74:
75: private boolean isValidDelimiterAtom(String s) {
76: return isValidDelimiter(s);
77: }
78:
79: @Override
80: public String toString() {
81: return "DelimiterAtom: "
82: + getFullText().replaceAll("\n", "\\\\n").replaceAll(
83: "\r", "\\\\r").replaceAll("\t", "\\\\t");
84: }
85:
86: @Override
87: public boolean equalsIdentifier(Atom a) {
88: return super .equalsIdentifier(a)
89: // Handling for automatically inserted newlines
90: || ((a.getIdentifier().equals(" ") || a.getIdentifier()
91: .equals("\n")) && (getIdentifier().equals(" ") || getIdentifier()
92: .equals("\n")));
93: }
94:
95: }
|