KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > parser > ScannerUtilities


1 /*
2
3    Copyright 1999-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    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.batik.css.parser;
20
21 /**
22  * A collection of utility functions for a CSS scanner.
23  *
24  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
25  * @version $Id: ScannerUtilities.java,v 1.3 2004/10/30 18:38:04 deweese Exp $
26  */

27 public class ScannerUtilities {
28
29     /**
30      * The set of the valid identifier start characters.
31      */

32     protected final static int[] IDENTIFIER_START = { 0, 0, 134217726, 134217726 };
33
34     /**
35      * The set of the valid name characters.
36      */

37     protected final static int[] NAME = { 0, 67051520, 134217726, 134217726 };
38
39     /**
40      * The set of the valid hexadecimal characters.
41      */

42     protected final static int[] HEXADECIMAL = { 0, 67043328, 126, 126 };
43
44     /**
45      * The set of the valid string characters.
46      */

47     protected final static int[] STRING = { 512, -133, -1, 2147483647 };
48
49     /**
50      * The set of the valid uri characters.
51      */

52     protected final static int[] URI = { 0, -902, -1, 2147483647 };
53
54     /**
55      * This class does not need to be instantiated.
56      */

57     protected ScannerUtilities() {
58     }
59
60     /**
61      * Tests whether the given character is a valid space.
62      */

63     public static boolean isCSSSpace(char c) {
64       return (c <= 0x0020) &&
65              (((((1L << '\t') |
66                  (1L << '\n') |
67                  (1L << '\r') |
68                  (1L << '\f') |
69                  (1L << 0x0020)) >> c) & 1L) != 0);
70     }
71
72     /**
73      * Tests whether the given character is a valid identifier start character.
74      */

75     public static boolean isCSSIdentifierStartCharacter(char c) {
76     return c >= 128 || ((IDENTIFIER_START[c / 32] & (1 << (c % 32))) != 0);
77     }
78
79     /**
80      * Tests whether the given character is a valid name character.
81      */

82     public static boolean isCSSNameCharacter(char c) {
83     return c >= 128 || ((NAME[c / 32] & (1 << (c % 32))) != 0);
84     }
85
86     /**
87      * Tests whether the given character is a valid hexadecimal character.
88      */

89     public static boolean isCSSHexadecimalCharacter(char c) {
90     return c < 128 && ((HEXADECIMAL[c / 32] & (1 << (c % 32))) != 0);
91     }
92
93     /**
94      * Tests whether the given character is a valid string character.
95      */

96     public static boolean isCSSStringCharacter(char c) {
97     return c >= 128 || ((STRING[c / 32] & (1 << (c % 32))) != 0);
98     }
99
100     /**
101      * Tests whether the given character is a valid URI character.
102      */

103     public static boolean isCSSURICharacter(char c) {
104     return c >= 128 || ((URI[c / 32] & (1 << (c % 32))) != 0);
105     }
106 }
107
Popular Tags