Exemplo n.º 1
0
 private void _testTrieIteration(IntTrie trie, CheckRange checkRanges[], int countCheckRanges) {
   // write a string
   int countValues = 0;
   StringBuffer s = new StringBuffer();
   int values[] = new int[30];
   for (int i = 0; i < countCheckRanges; ++i) {
     int c = checkRanges[i].limit;
     if (c != 0) {
       --c;
       UTF16.append(s, c);
       values[countValues++] = checkRanges[i].value;
     }
   }
   int limit = s.length();
   // try forward
   int p = 0;
   int i = 0;
   while (p < limit) {
     int c = UTF16.charAt(s, p);
     p += UTF16.getCharCount(c);
     int value = trie.getCodePointValue(c);
     if (value != values[i]) {
       errln(
           "wrong value from UTRIE_NEXT(U+"
               + Integer.toHexString(c)
               + "): 0x"
               + Integer.toHexString(value)
               + " instead of 0x"
               + Integer.toHexString(values[i]));
     }
     // unlike the c version lead is 0 if c is non-supplementary
     char lead = UTF16.getLeadSurrogate(c);
     char trail = UTF16.getTrailSurrogate(c);
     if (lead == 0
         ? trail != s.charAt(p - 1)
         : !UTF16.isLeadSurrogate(lead)
             || !UTF16.isTrailSurrogate(trail)
             || lead != s.charAt(p - 2)
             || trail != s.charAt(p - 1)) {
       errln("wrong (lead, trail) from UTRIE_NEXT(U+" + Integer.toHexString(c));
       continue;
     }
     if (lead != 0) {
       value = trie.getLeadValue(lead);
       value = trie.getTrailValue(value, trail);
       if (value != trie.getSurrogateValue(lead, trail) && value != values[i]) {
         errln(
             "wrong value from getting supplementary "
                 + "values (U+"
                 + Integer.toHexString(c)
                 + "): 0x"
                 + Integer.toHexString(value)
                 + " instead of 0x"
                 + Integer.toHexString(values[i]));
       }
     }
     ++i;
   }
 }