1 /*
   2  * Permission is hereby granted, free of charge, to any person obtaining a copy of
   3  * this software and associated documentation files (the "Software"), to deal in
   4  * the Software without restriction, including without limitation the rights to
   5  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
   6  * of the Software, and to permit persons to whom the Software is furnished to do
   7  * so, subject to the following conditions:
   8  *
   9  * The above copyright notice and this permission notice shall be included in all
  10  * copies or substantial portions of the Software.
  11  *
  12  * THE SOFTWARE IS PROVIDED "AS IS".toCharArray(), WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18  * SOFTWARE.
  19  */
  20 package jdk.nashorn.internal.joni.encoding;
  21 
  22 import jdk.nashorn.internal.joni.exception.ErrorMessages;
  23 import jdk.nashorn.internal.joni.exception.JOniException;
  24 
  25 import java.util.HashMap;
  26 
  27 public class PosixBracket {
  28 
  29     public static final char[][] PBSNamesLower = {
  30             "alnum".toCharArray(),
  31             "alpha".toCharArray(),
  32             "blank".toCharArray(),
  33             "cntrl".toCharArray(),
  34             "digit".toCharArray(),
  35             "graph".toCharArray(),
  36             "lower".toCharArray(),
  37             "print".toCharArray(),
  38             "punct".toCharArray(),
  39             "space".toCharArray(),
  40             "upper".toCharArray(),
  41             "xdigit".toCharArray(),
  42             "ascii".toCharArray(),
  43             "word".toCharArray()
  44     };
  45 
  46     public static final int PBSValues[] = {
  47             CharacterType.ALNUM,
  48             CharacterType.ALPHA,
  49             CharacterType.BLANK,
  50             CharacterType.CNTRL,
  51             CharacterType.DIGIT,
  52             CharacterType.GRAPH,
  53             CharacterType.LOWER,
  54             CharacterType.PRINT,
  55             CharacterType.PUNCT,
  56             CharacterType.SPACE,
  57             CharacterType.UPPER,
  58             CharacterType.XDIGIT,
  59             CharacterType.ASCII,
  60             CharacterType.WORD,
  61     };
  62 
  63     public static int propertyNameToCType(String name) {
  64         name = name.toLowerCase();
  65         if (!PBSTableUpper.containsKey(name)) {
  66             throw new JOniException(ErrorMessages.ERR_INVALID_CHAR_PROPERTY_NAME.replaceAll("%n", name));
  67         }
  68         return PBSTableUpper.get(name);
  69     }
  70 
  71     private static final HashMap<String,Integer> PBSTableUpper = new HashMap<String,Integer>();
  72 
  73     static {
  74         for (int i=0; i<PBSValues.length; i++) PBSTableUpper.put(new String(PBSNamesLower[i]), PBSValues[i]);
  75     }
  76 
  77 }