< prev index next >

make/data/characterdata/CharacterDataLatin1.java.template

Print this page
rev 48663 : [mq]: charlatin1digit


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 


  28 /** The CharacterData class encapsulates the large tables found in
  29     Java.lang.Character. */
  30 
  31 class CharacterDataLatin1 extends CharacterData {
  32 
  33     /* The character properties are currently encoded into 32 bits in the following manner:
  34         1 bit   mirrored property
  35         4 bits  directionality property
  36         9 bits  signed offset used for converting case
  37         1 bit   if 1, adding the signed offset converts the character to lowercase
  38         1 bit   if 1, subtracting the signed offset converts the character to uppercase
  39         1 bit   if 1, this character has a titlecase equivalent (possibly itself)
  40         3 bits  0  may not be part of an identifier
  41                 1  ignorable control; may continue a Unicode identifier or Java identifier
  42                 2  may continue a Java identifier but not a Unicode identifier (unused)
  43                 3  may continue a Unicode identifier or Java identifier
  44                 4  is a Java whitespace character
  45                 5  may start or continue a Java identifier;
  46                    may continue but not start a Unicode identifier (underscores)
  47                 6  may start or continue a Java identifier but not a Unicode identifier ($)


 142 
 143     int toUpperCase(int ch) {
 144         int mapChar = ch;
 145         int val = getProperties(ch);
 146 
 147         if ((val & $$maskUpperCase) != 0) {
 148             if ((val & $$maskCaseOffset) != $$maskCaseOffset) {
 149                 int offset = val  << $$shiftCaseOffsetSign >> ($$shiftCaseOffsetSign+$$shiftCaseOffset);
 150                 mapChar =  ch - offset;
 151             } else if (ch == 0x00B5) {
 152                 mapChar = 0x039C;
 153             }
 154         }
 155         return mapChar;
 156     }
 157 
 158     int toTitleCase(int ch) {
 159         return toUpperCase(ch);
 160     }
 161 
 162     int digit(int ch, int radix) {
 163         int value = -1;
 164         if (radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX) {
 165             int val = getProperties(ch);
 166             int kind = val & $$maskType;
 167             if (kind == Character.DECIMAL_DIGIT_NUMBER) {
 168                 value = ch + ((val & $$maskDigitOffset) >> $$shiftDigitOffset) & $$maskDigit;


 169             }
 170             else if ((val & $$maskNumericType) == $$valueJavaSupradecimal) {
 171                 // Java supradecimal digit
 172                 value = (ch + ((val & $$maskDigitOffset) >> $$shiftDigitOffset) & $$maskDigit) + 10;
 173             }







 174         }
 175         return (value < radix) ? value : -1;
 176     }
 177 
 178     int getNumericValue(int ch) {
 179         int val = getProperties(ch);
 180         int retval = -1;
 181 
 182         switch (val & $$maskNumericType) {
 183             default: // cannot occur
 184             case ($$valueNotNumeric):         // not numeric
 185                 retval = -1;
 186                 break;
 187             case ($$valueDigit):              // simple numeric
 188                 retval = ch + ((val & $$maskDigitOffset) >> $$shiftDigitOffset) & $$maskDigit;
 189                 break;
 190             case ($$valueStrangeNumeric)      :       // "strange" numeric
 191                  retval = -2; 
 192                  break;
 193             case ($$valueJavaSupradecimal):           // Java supradecimal
 194                 retval = (ch + ((val & $$maskDigitOffset) >> $$shiftDigitOffset) & $$maskDigit) + 10;
 195                 break;




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.util.Arrays;
  29 
  30 /** The CharacterData class encapsulates the large tables found in
  31     Java.lang.Character. */
  32 
  33 class CharacterDataLatin1 extends CharacterData {
  34 
  35     /* The character properties are currently encoded into 32 bits in the following manner:
  36         1 bit   mirrored property
  37         4 bits  directionality property
  38         9 bits  signed offset used for converting case
  39         1 bit   if 1, adding the signed offset converts the character to lowercase
  40         1 bit   if 1, subtracting the signed offset converts the character to uppercase
  41         1 bit   if 1, this character has a titlecase equivalent (possibly itself)
  42         3 bits  0  may not be part of an identifier
  43                 1  ignorable control; may continue a Unicode identifier or Java identifier
  44                 2  may continue a Java identifier but not a Unicode identifier (unused)
  45                 3  may continue a Unicode identifier or Java identifier
  46                 4  is a Java whitespace character
  47                 5  may start or continue a Java identifier;
  48                    may continue but not start a Unicode identifier (underscores)
  49                 6  may start or continue a Java identifier but not a Unicode identifier ($)


 144 
 145     int toUpperCase(int ch) {
 146         int mapChar = ch;
 147         int val = getProperties(ch);
 148 
 149         if ((val & $$maskUpperCase) != 0) {
 150             if ((val & $$maskCaseOffset) != $$maskCaseOffset) {
 151                 int offset = val  << $$shiftCaseOffsetSign >> ($$shiftCaseOffsetSign+$$shiftCaseOffset);
 152                 mapChar =  ch - offset;
 153             } else if (ch == 0x00B5) {
 154                 mapChar = 0x039C;
 155             }
 156         }
 157         return mapChar;
 158     }
 159 
 160     int toTitleCase(int ch) {
 161         return toUpperCase(ch);
 162     }
 163 
 164     private static final byte[] DIGITS;
 165     static {
 166         byte[] digitValues = new byte[256];
 167         Arrays.fill(digitValues, (byte)-1);
 168         for (char c = '0'; c <= '9'; c++) {
 169             digitValues[c] = (byte)(c - '0');
 170         }
 171         for (char c = 'A'; c <= 'Z'; c++) {
 172             digitValues[c] = (byte)(c - 'A' + 10);
 173         }
 174         for (char c = 'a'; c <= 'z'; c++) {
 175             digitValues[c] = (byte)(c - 'a' + 10);

 176         }
 177         DIGITS = digitValues;
 178     }
 179 
 180     int digit(int ch, int radix) {
 181         int value = DIGITS[ch];
 182         if (value >= 0 && radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX) {
 183             value = (value < radix) ? value : -1;
 184         }
 185         return value;
 186     }
 187 
 188     int getNumericValue(int ch) {
 189         int val = getProperties(ch);
 190         int retval = -1;
 191 
 192         switch (val & $$maskNumericType) {
 193             default: // cannot occur
 194             case ($$valueNotNumeric):         // not numeric
 195                 retval = -1;
 196                 break;
 197             case ($$valueDigit):              // simple numeric
 198                 retval = ch + ((val & $$maskDigitOffset) >> $$shiftDigitOffset) & $$maskDigit;
 199                 break;
 200             case ($$valueStrangeNumeric)      :       // "strange" numeric
 201                  retval = -2; 
 202                  break;
 203             case ($$valueJavaSupradecimal):           // Java supradecimal
 204                 retval = (ch + ((val & $$maskDigitOffset) >> $$shiftDigitOffset) & $$maskDigit) + 10;
 205                 break;


< prev index next >