KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cypress > CssCharUtils


1 /*
2 ** Cypress - CSS Parser
3 ** Copyright (c) 2001, 2002, 2003 by Gerald Bauer
4 **
5 ** This program is free software.
6 **
7 ** You may redistribute it and/or modify it under the terms of the GNU
8 ** Lesser General Public License as published by the Free Software Foundation.
9 ** Version 2.1 of the license should be included with this distribution in
10 ** the file LICENSE, as well as License.html. If the license is not
11 ** included with this distribution, you may find a copy at the FSF web
12 ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
13 ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
14 **
15 ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
16 ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
17 ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
18 ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
19 ** REDISTRIBUTION OF THIS SOFTWARE.
20 **
21 */

22
23 package cypress;
24
25 /**
26  * A collection of utility functions for a CSS scanner.
27  */

28
29 public class CssCharUtils
30 {
31
32    /**
33     * The set of the valid hexadecimal characters.
34     */

35    protected final static int[] HEXADECIMAL = {0, 67043328, 126, 126};
36    /**
37     * The set of the valid identifier start characters.
38     */

39    protected final static int[] IDENTIFIER_START = {0, 0, 134217726, 134217726};
40
41    /**
42     * The set of the valid name characters.
43     */

44    protected final static int[] NAME = {0, 67051520, 134217726, 134217726};
45
46    /**
47     * The set of the valid string characters.
48     */

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

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

59    protected CssCharUtils() { }
60
61    /**
62     * Tests whether the given character is a valid hexadecimal character.
63     */

64    public static boolean isHexadecimal( char c )
65    {
66       return c < 128 && ( ( HEXADECIMAL[c / 32] & ( 1 << ( c % 32 ) ) ) != 0 );
67    }
68
69    /**
70     * Tests whether the given character is a valid identifier start character.
71     */

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

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

88    public static boolean isSpace( char c )
89    {
90       return ( c <= 0x0020 ) &&
91             ( ( ( ( ( 1L << '\t' ) |
92             ( 1L << '\n' ) |
93             ( 1L << '\r' ) |
94             ( 1L << '\f' ) |
95             ( 1L << 0x0020 ) ) >> c ) & 1L ) != 0 );
96    }
97
98    /**
99     * Tests whether the given character is a valid string character.
100     */

101    public static boolean isString( char c )
102    {
103       return c >= 128 || ( ( STRING[c / 32] & ( 1 << ( c % 32 ) ) ) != 0 );
104    }
105
106    /**
107     * Tests whether the given character is a valid URI character.
108     */

109    public static boolean isUri( char c )
110    {
111       return c >= 128 || ( ( URI[c / 32] & ( 1 << ( c % 32 ) ) ) != 0 );
112    }
113 }
114
Popular Tags