Logo Search packages:      
Sourcecode: icu version File versions

int32_t TransliteratorIDParser::instantiateList ( UVector list,
Transliterator insert,
int32_t  insertIndex,
UErrorCode ec 
) [static]

Convert the elements of the 'list' vector, which are SingleID objects, into actual Transliterator objects. In the course of this, some (or all) entries may be removed. If all entries are removed, the Null transliterator will be added.

Delete entries with empty basicIDs; these are generated by elements like "(A)" in the forward direction, or "A()" in the reverse. THIS MAY RESULT IN AN EMPTY VECTOR. Convert SingleID entries to actual transliterators.

Also, optionally, insert the given transliterator at the given position. This effectively happens before anything else.

Parameters:
list vector of SingleID objects. On exit, vector of one or more Transliterators.
insert Transliterator to insert, or null if none.
insertIndex index from 0..list.size()-1, at which to place 'insert', or -1 if none.
Returns:
new value of insertIndex. The index will shift if there are empty items, like "(Lower)", with indices less than insertIndex.
Convert the elements of the 'list' vector, which are SingleID objects, into actual Transliterator objects. In the course of this, some (or all) entries may be removed. If all entries are removed, the NULL transliterator will be added.

Delete entries with empty basicIDs; these are generated by elements like "(A)" in the forward direction, or "A()" in the reverse. THIS MAY RESULT IN AN EMPTY VECTOR. Convert SingleID entries to actual transliterators.

Also, optionally, insert the given transliterator at the given position. This effectively happens before anything else.

Parameters:
list vector of SingleID objects. On exit, vector of one or more Transliterators.
insert Transliterator to insert, or NULL if none. Adopted.
insertIndex index from 0..list.size()-1, at which to place 'insert', or -1 if none.
Returns:
new value of insertIndex. The index will shift if there are empty items, like "(Lower)", with indices less than insertIndex.

Definition at line 447 of file tridpars.cpp.

References UVector::addElement(), TransliteratorIDParser::SingleID::basicID, createBasicInstance(), TransliteratorIDParser::SingleID::createInstance(), UVector::elementAt(), UnicodeString::length(), NULL, UVector::orphanElementAt(), UVector::removeAllElements(), UVector::setDeleter(), UVector::size(), and U_FAILURE.

Referenced by Transliterator::createInstance(), and CompoundTransliterator::init().

                                                                {
    UVector tlist(ec);
    if (U_FAILURE(ec)) {
        goto RETURN;
    }
    tlist.setDeleter(_deleteTransliterator);

    Transliterator* t;
    int32_t i;
    for (i=0; i<=list.size(); ++i) { // [sic]: i<=list.size()
        if (insertIndex == i) {
            insertIndex = tlist.size();
            tlist.addElement(insert, ec);
            if (U_FAILURE(ec)) {
                goto RETURN;
            }
            insert = NULL;
        }

        // We run the loop too long by one, so we can
        // do an insert after the last element
        if (i==list.size()) {
            break;
        }

        SingleID* single = (SingleID*) list.elementAt(i);
        if (single->basicID.length() != 0) {
            t = single->createInstance();
            if (t == NULL) {
                ec = U_INVALID_ID;
                goto RETURN;
            }
            tlist.addElement(t, ec);
            if (U_FAILURE(ec)) {
                goto RETURN;
            }
        }
    }

    // An empty list is equivalent to a NULL transliterator.
    if (tlist.size() == 0) {
        t = createBasicInstance(ANY_NULL, NULL);
        if (t == NULL) {
            // Should never happen
            ec = U_INTERNAL_TRANSLITERATOR_ERROR;
        }
        tlist.addElement(t, ec);
    }

 RETURN:

    UObjectDeleter save = list.setDeleter(_deleteSingleID);
    list.removeAllElements();
    list.setDeleter(_deleteTransliterator);

    while (tlist.size() > 0) {
        t = (Transliterator*) tlist.orphanElementAt(0);
        list.addElement(t, ec);
        if (U_FAILURE(ec)) {
            delete t;
            list.removeAllElements();
            break;
        }
    }

    delete insert; // Clean up in case of failure
    list.setDeleter(save);
    return insertIndex;
}


Generated by  Doxygen 1.6.0   Back to index