third-party/icu/source/i18n/measunit_extra.cpp
/**
 * Normalize a MeasureUnitImpl and generate the identifier string in place.
 */
Normalize a MeasureUnitImpl and generate the identifier string in place.
Normalize a MeasureUnitImpl and generate the identifier string in place .
void serialize(MeasureUnitImpl& impl, UErrorCode& status) {
    if (U_FAILURE(status)) {
        return;
    }
    U_ASSERT(impl.identifier.isEmpty());
    if (impl.units.length() == 0) {
        return;
    }
    if (impl.complexity == UMEASURE_UNIT_COMPOUND) {
        uprv_sortArray(
            impl.units.getAlias(),
            impl.units.length(),
            sizeof(impl.units[0]),
            compareSingleUnits,
            nullptr,
            false,
            &status);
        if (U_FAILURE(status)) {
            return;
        }
    }
    serializeSingle(*impl.units[0], true, impl.identifier, status);
    if (impl.units.length() == 1) {
        return;
    }
    for (int32_t i = 1; i < impl.units.length(); i++) {
        const SingleUnitImpl& prev = *impl.units[i-1];
        const SingleUnitImpl& curr = *impl.units[i];
        if (impl.complexity == UMEASURE_UNIT_MIXED) {
            impl.identifier.append("-and-", status);
            serializeSingle(curr, true, impl.identifier, status);
        } else {
            if (prev.dimensionality > 0 && curr.dimensionality < 0) {
                impl.identifier.append("-per-", status);
            } else {
                impl.identifier.append('-', status);
            }
            serializeSingle(curr, false, impl.identifier, status);
        }
    }
}
void serialize ( MeasureUnitImpl & impl , UErrorCode & status ) { if ( U_FAILURE ( status ) ) { return ; } U_ASSERT ( impl . identifier . isEmpty ( ) ) ; if ( impl . units . length ( ) == 0 ) { return ; } if ( impl . complexity == UMEASURE_UNIT_COMPOUND ) { uprv_sortArray ( impl . units . getAlias ( ) , impl . units . length ( ) , sizeof ( impl . units [ 0 ] ) , compareSingleUnits , nullptr , false , & status ) ; if ( U_FAILURE ( status ) ) { return ; } } serializeSingle ( * impl . units [ 0 ] , true , impl . identifier , status ) ; if ( impl . units . length ( ) == 1 ) { return ; } for ( int32_t i = 1 ; i < impl . units . length ( ) ; i ++ ) { const SingleUnitImpl & prev = * impl . units [ i - 1 ] ; const SingleUnitImpl & curr = * impl . units [ i ] ; if ( impl . complexity == UMEASURE_UNIT_MIXED ) { impl . identifier . append ( " " , status ) ; serializeSingle ( curr , true , impl . identifier , status ) ; } else { if ( prev . dimensionality > 0 && curr . dimensionality < 0 ) { impl . identifier . append ( " " , status ) ; } else { impl . identifier . append ( ' ' , status ) ; } serializeSingle ( curr , false , impl . identifier , status ) ; } } }
Normalize a MeasureUnitImpl and generate the identifier string in place.
Normalize a MeasureUnitImpl and generate the identifier string in place .
// Dimensionless, constructed by the default constructor: no appending // to impl.identifier, we wish it to contain the zero-length string. // Note: don't sort a MIXED unit