• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Jeff Ichnowski
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions
6 // are met:
7 //
8 //     * Redistributions of source code must retain the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer.
11 //
12 //     * Redistributions in binary form must reproduce the above
13 //       copyright notice, this list of conditions and the following
14 //       disclaimer in the documentation and/or other materials
15 //       provided with the distribution.
16 //
17 //     * Neither the name of the OWASP nor the names of its
18 //       contributors may be used to endorse or promote products
19 //       derived from this software without specific prior written
20 //       permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 // OF THE POSSIBILITY OF SUCH DAMAGE.
34 package org.owasp.encoder;
35 
36 /**
37  * ASCII and Unicode constants.
38  *
39  * @author jeffi
40  */
41 final class Unicode {
42 
43     /**
44      * Highest ASCII (usually) valid ASCII char.
45      */
46     static final char MAX_ASCII = '~';
47 
48     /**
49      * ASCII "DEL" character.
50      */
51     static final char DEL = 0x7f;
52 
53     /**
54      * "Next Line" C1 control character.
55      */
56     static final char NEL = 0x85;
57 
58     /**
59      * Highest C1 control character.
60      */
61     static final char MAX_C1_CTRL_CHAR = 0x9f;
62 
63     /**
64      * Unicode line separator character, must be encoded in some contexts.
65      */
66     static final char LINE_SEPARATOR = '\u2028';
67 
68     /**
69      * Unicode paragraph separator character, must be encoded in some contexts.
70      */
71     static final char PARAGRAPH_SEPARATOR = '\u2029';
72 
73     /**
74      * Bit-mask for Unicode non-characaters (XXfffe and XXffff).
75      */
76     static final int NON_CHAR_MASK = 0xfffe;
77 
78     /**
79      * Returns true if the argument is not a character according to the Unicode
80      * standard. Non-characters have the format XXfffe and XXffff, where XX is
81      * any code plane, and "fffe/ffff" is the low 16-bits in hex.
82      *
83      * @param cp the unicode code-point to check
84      * @return true if {@code cp} is not a character.
85      */
isNonCharacter(int cp)86     static boolean isNonCharacter(int cp) {
87         return (cp & NON_CHAR_MASK) == NON_CHAR_MASK;
88     }
89 
90     /**
91      * No instances.
92      */
Unicode()93     private Unicode() {
94     }
95 }
96