Java Code Examples for android.icu.lang.UCharacter#MAX_VALUE

The following examples show how to use android.icu.lang.UCharacter#MAX_VALUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntTrieBuilder.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Get a 32 bit data from the table data
 * @param ch  code point for which data is to be retrieved.
 * @param inBlockZero  Output parameter, inBlockZero[0] returns true if the
 *                      char maps into block zero, otherwise false.
 * @return the 32 bit data value.
 */
public int getValue(int ch, boolean [] inBlockZero) 
{
    // valid, uncompacted trie and valid c?
    if (m_isCompacted_ || ch > UCharacter.MAX_VALUE || ch < 0) {
        if (inBlockZero != null) {
            inBlockZero[0] = true;
        }
        return 0;
    }

    int block = m_index_[ch >> SHIFT_];
    if (inBlockZero != null) {
        inBlockZero[0] = (block == 0);
    }
    return m_data_[Math.abs(block) + (ch & MASK_)];
}
 
Example 2
Source File: IntTrieBuilder.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Sets a 32 bit data in the table data
 * @param ch codepoint which data is to be set
 * @param value to set
 * @return true if the set is successful, otherwise 
 *              if the table has been compacted return false
 */
public boolean setValue(int ch, int value) 
{
    // valid, uncompacted trie and valid c? 
    if (m_isCompacted_ || ch > UCharacter.MAX_VALUE || ch < 0) {
        return false;
    }

    int block = getDataBlock(ch);
    if (block < 0) {
        return false;
    }

    m_data_[block + (ch & MASK_)] = value;
    return true;
}
 
Example 3
Source File: Trie.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
* Internal trie getter from a code point.
* Could be faster(?) but longer with
*   if((c32)<=0xd7ff) { (result)=_TRIE_GET_RAW(trie, data, 0, c32); }
* Gets the offset to data which the codepoint points to
* @param ch codepoint
* @return offset to data
*/
protected final int getCodePointOffset(int ch)
{
    // if ((ch >> 16) == 0) slower
    if (ch < 0) {
        return -1;
    } else if (ch < UTF16.LEAD_SURROGATE_MIN_VALUE) {
        // fastpath for the part of the BMP below surrogates (D800) where getRawOffset() works
        return getRawOffset(0, (char)ch);
    } else if (ch < UTF16.SUPPLEMENTARY_MIN_VALUE) {
        // BMP codepoint
        return getBMPOffset((char)ch);
    } else if (ch <= UCharacter.MAX_VALUE) {
        // look at the construction of supplementary characters
        // trail forms the ends of it.
        return getSurrogateOffset(UTF16.getLeadSurrogate(ch),
                                  (char)(ch & SURROGATE_MASK_));
    } else {
        // return -1 if there is an error, in this case we return
        return -1;
    }
}
 
Example 4
Source File: UCharacterName.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
* Retrieve the name of a Unicode code point.
* Depending on <code>choice</code>, the character name written into the
* buffer is the "modern" name or the name that was defined in Unicode
* version 1.0.
* The name contains only "invariant" characters
* like A-Z, 0-9, space, and '-'.
*
* @param ch the code point for which to get the name.
* @param choice Selector for which name to get.
* @return if code point is above 0x1fff, null is returned
*/
public String getName(int ch, int choice)
{
    if (ch < UCharacter.MIN_VALUE || ch > UCharacter.MAX_VALUE ||
        choice > UCharacterNameChoice.CHAR_NAME_CHOICE_COUNT) {
        return null;
    }

    String result = null;

    result = getAlgName(ch, choice);

    // getting normal character name
    if (result == null || result.length() == 0) {
        if (choice == UCharacterNameChoice.EXTENDED_CHAR_NAME) {
            result = getExtendedName(ch);
        } else {
            result = getGroupName(ch, choice);
        }
    }

    return result;
}
 
Example 5
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestToString(){
    int[] valid_tests = {
            UCharacter.MIN_VALUE, UCharacter.MIN_VALUE+1,
            UCharacter.MAX_VALUE-1, UCharacter.MAX_VALUE};
    int[] invalid_tests = {
            UCharacter.MIN_VALUE-1, UCharacter.MIN_VALUE-2,
            UCharacter.MAX_VALUE+1, UCharacter.MAX_VALUE+2};

    for(int i=0; i< valid_tests.length; i++){
        if(UCharacter.toString(valid_tests[i]) == null){
            errln("UCharacter.toString(int) was not suppose to return " +
            "null because it was given a valid parameter. Value passed: " +
            valid_tests[i] + ". Got null.");
        }
    }

    for(int i=0; i< invalid_tests.length; i++){
        if(UCharacter.toString(invalid_tests[i]) != null){
            errln("UCharacter.toString(int) was suppose to return " +
            "null because it was given an invalid parameter. Value passed: " +
            invalid_tests[i] + ". Got: " + UCharacter.toString(invalid_tests[i]));
        }
    }
}
 
Example 6
Source File: TrieBuilder.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the character belongs to a zero block in the trie
 * @param ch codepoint which data is to be retrieved
 * @return true if ch is in the zero block
 */
public boolean isInZeroBlock(int ch) 
{
    // valid, uncompacted trie and valid c?
    if (m_isCompacted_ || ch > UCharacter.MAX_VALUE 
        || ch < UCharacter.MIN_VALUE) {
        return true;
    }

    return m_index_[ch >> SHIFT_] == 0;
}
 
Example 7
Source File: IntTrieBuilder.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a 32 bit data from the table data
 * @param ch codepoint which data is to be retrieved
 * @return the 32 bit data
 */
public int getValue(int ch) 
{
    // valid, uncompacted trie and valid c?
    if (m_isCompacted_ || ch > UCharacter.MAX_VALUE || ch < 0) {
        return 0;
    }

    int block = m_index_[ch >> SHIFT_];
    return m_data_[Math.abs(block) + (ch & MASK_)];
}
 
Example 8
Source File: TrieIterator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
* <p>Returns true if we are not at the end of the iteration, false
* otherwise.</p>
* <p>The next set of codepoints with the same value type will be
* calculated during this call and returned in the arguement element.</p>
* @param element return result
* @return true if we are not at the end of the iteration, false otherwise.
* @exception NoSuchElementException - if no more elements exist.
* @see android.icu.util.RangeValueIterator.Element
*/
@Override
public final boolean next(Element element)
{
    if (m_nextCodepoint_ > UCharacter.MAX_VALUE) {
        return false;
    }
    if (m_nextCodepoint_ < UCharacter.SUPPLEMENTARY_MIN_VALUE &&
        calculateNextBMPElement(element)) {
        return true;
    }
    calculateNextSupplementaryElement(element);
    return true;
}
 
Example 9
Source File: UCharacterName.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
* Sets the information for accessing the algorithmic names
* @param rangestart starting code point that lies within this name group
* @param rangeend end code point that lies within this name group
* @param type algorithm type. There's 2 kinds of algorithmic type. First
*        which uses code point as part of its name and the other uses
*        variant postfix strings
* @param variant algorithmic variant
* @return true if values are valid
*/
boolean setInfo(int rangestart, int rangeend, byte type, byte variant)
{
    if (rangestart >= UCharacter.MIN_VALUE && rangestart <= rangeend
        && rangeend <= UCharacter.MAX_VALUE &&
        (type == TYPE_0_ || type == TYPE_1_)) {
        m_rangestart_ = rangestart;
        m_rangeend_ = rangeend;
        m_type_ = type;
        m_variant_ = variant;
        return true;
    }
    return false;
}
 
Example 10
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestGetISOComment(){
    int[] invalid_tests = {
            UCharacter.MIN_VALUE-1, UCharacter.MIN_VALUE-2,
            UCharacter.MAX_VALUE+1, UCharacter.MAX_VALUE+2};

    for(int i=0; i< invalid_tests.length; i++){
        if(UCharacter.getISOComment(invalid_tests[i]) != null){
            errln("UCharacter.getISOComment(int) was suppose to return " +
            "null because it was given an invalid parameter. Value passed: " +
            invalid_tests[i] + ". Got: " + UCharacter.getISOComment(invalid_tests[i]));
        }
    }
}
 
Example 11
Source File: UTF16Test.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Testing UTF16 class methods append
 */
@Test
public void TestAppend()
{
      StringBuffer strbuff = new StringBuffer("this is a string ");
      char array[] = new char[UCharacter.MAX_VALUE >> 2];
      int strsize = strbuff.length();
      int arraysize = strsize;

      if (0 != strsize) {
        strbuff.getChars(0, strsize, array, 0);
    }
      for (int i = 1; i < UCharacter.MAX_VALUE; i += 100) {
    UTF16.append(strbuff, i);
    arraysize = UTF16.append(array, arraysize, i);

    String arraystr = new String(array, 0, arraysize);
    if (!arraystr.equals(strbuff.toString())) {
    errln("FAIL Comparing char array append and string append " +
          "with 0x" + Integer.toHexString(i));
    }

    // this is to cater for the combination of 0xDBXX 0xDC50 which
    // forms a supplementary character
    if (i == 0xDC51) {
    strsize --;
    }

    if (UTF16.countCodePoint(strbuff) != strsize + (i / 100) + 1) {
    errln("FAIL Counting code points in string appended with " +
          " 0x" + Integer.toHexString(i));
    break;
    }
}

// coverage for new 1.5 - cover only so no real test
strbuff = new StringBuffer();
UTF16.appendCodePoint(strbuff, 0x10000);
if (strbuff.length() != 2) {
    errln("fail appendCodePoint");
}
}