示例#1
0
  /**
   * Create a new entry in the expansion table that contains the orderings for the given characers.
   * If anOrder is valid, it is added to the beginning of the expanded list of orders.
   */
  private int addExpansion(int anOrder, String expandChars) {
    if (expandTable == null) {
      expandTable = new Vector(INITIALTABLESIZE);
    }

    // If anOrder is valid, we want to add it at the beginning of the list
    int offset = (anOrder == RBCollationTables.UNMAPPED) ? 0 : 1;

    int[] valueList = new int[expandChars.length() + offset];
    if (offset == 1) {
      valueList[0] = anOrder;
    }

    int j = offset;
    for (int i = 0; i < expandChars.length(); i++) {
      char ch0 = expandChars.charAt(i);
      char ch1;
      int ch;
      if (Character.isHighSurrogate(ch0)) {
        if (++i == expandChars.length() || !Character.isLowSurrogate(ch1 = expandChars.charAt(i))) {
          // ether we are missing the low surrogate or the next char
          // is not a legal low surrogate, so stop loop
          break;
        }
        ch = Character.toCodePoint(ch0, ch1);

      } else {
        ch = ch0;
      }

      int mapValue = getCharOrder(ch);

      if (mapValue != RBCollationTables.UNMAPPED) {
        valueList[j++] = mapValue;
      } else {
        // can't find it in the table, will be filled in by commit().
        valueList[j++] = CHARINDEX + ch;
      }
    }
    if (j < valueList.length) {
      // we had at least one supplementary character, the size of valueList
      // is bigger than it really needs...
      int[] tmpBuf = new int[j];
      while (--j >= 0) {
        tmpBuf[j] = valueList[j];
      }
      valueList = tmpBuf;
    }
    // Add the expanding char list into the expansion table.
    int tableIndex = RBCollationTables.EXPANDCHARINDEX + expandTable.size();
    expandTable.addElement(valueList);

    return tableIndex;
  }
示例#2
0
  /** Adds the expanding string into the collation table. */
  private final void addExpandOrder(String contractChars, String expandChars, int anOrder)
      throws ParseException {
    // Create an expansion table entry
    int tableIndex = addExpansion(anOrder, expandChars);

    // And add its index into the main mapping table
    if (contractChars.length() > 1) {
      char ch = contractChars.charAt(0);
      if (Character.isHighSurrogate(ch) && contractChars.length() == 2) {
        char ch2 = contractChars.charAt(1);
        if (Character.isLowSurrogate(ch2)) {
          // only add into table when it is a legal surrogate
          addOrder(Character.toCodePoint(ch, ch2), tableIndex);
        }
      } else {
        addContractOrder(contractChars, tableIndex);
      }
    } else {
      addOrder(contractChars.charAt(0), tableIndex);
    }
  }