src/third_party/icu/source/i18n/measunit_extra.cpp
/**
 * Generate the identifier string for a single unit in place.
 *
 * Does not support the dimensionless SingleUnitImpl: calling serializeSingle
 * with the dimensionless unit results in an U_INTERNAL_PROGRAM_ERROR.
 *
 * @param first If singleUnit is part of a compound unit, and not its first
 * single unit, set this to false. Otherwise: set to true.
 */
Generate the identifier string for a single unit in place.
Does not support the dimensionless SingleUnitImpl: calling serializeSingle
with the dimensionless unit results in an U_INTERNAL_PROGRAM_ERROR.

@param first If singleUnit is part of a compound unit, and not its first
single unit, set this to false. Otherwise: set to true.
Generate the identifier string for a single unit in place . Does not support the dimensionless SingleUnitImpl : calling serializeSingle with the dimensionless unit results in an U_INTERNAL_PROGRAM_ERROR . @param first If singleUnit is part of a compound unit and not its first single unit set this to false . Otherwise : set to true .
void serializeSingle(const SingleUnitImpl& singleUnit, bool first, CharString& output, UErrorCode& status) {
    if (first && singleUnit.dimensionality < 0) {
        output.append("per-", status);
    }
    if (singleUnit.isDimensionless()) {
        status = U_INTERNAL_PROGRAM_ERROR;
        return;
    }
    int8_t posPower = std::abs(singleUnit.dimensionality);
    if (posPower == 0) {
        status = U_INTERNAL_PROGRAM_ERROR;
    } else if (posPower == 1) {
    } else if (posPower == 2) {
        output.append("square-", status);
    } else if (posPower == 3) {
        output.append("cubic-", status);
    } else if (posPower < 10) {
        output.append("pow", status);
        output.append(posPower + '0', status);
        output.append('-', status);
    } else if (posPower <= 15) {
        output.append("pow1", status);
        output.append('0' + (posPower % 10), status);
        output.append('-', status);
    } else {
        status = kUnitIdentifierSyntaxError;
    }
    if (U_FAILURE(status)) {
        return;
    }
    if (singleUnit.siPrefix != UMEASURE_SI_PREFIX_ONE) {
        for (const auto& siPrefixInfo : gSIPrefixStrings) {
            if (siPrefixInfo.value == singleUnit.siPrefix) {
                output.append(siPrefixInfo.string, status);
                break;
            }
        }
    }
    if (U_FAILURE(status)) {
        return;
    }
    output.append(singleUnit.getSimpleUnitID(), status);
}
void serializeSingle ( const SingleUnitImpl & singleUnit , bool first , CharString & output , UErrorCode & status ) { if ( first && singleUnit . dimensionality < 0 ) { output . append ( " " , status ) ; } if ( singleUnit . isDimensionless ( ) ) { status = U_INTERNAL_PROGRAM_ERROR ; return ; } int8_t posPower = std :: abs ( singleUnit . dimensionality ) ; if ( posPower == 0 ) { status = U_INTERNAL_PROGRAM_ERROR ; } else if ( posPower == 1 ) { } else if ( posPower == 2 ) { output . append ( " " , status ) ; } else if ( posPower == 3 ) { output . append ( " " , status ) ; } else if ( posPower < 10 ) { output . append ( " " , status ) ; output . append ( posPower + ' ' , status ) ; output . append ( ' ' , status ) ; } else if ( posPower <= 15 ) { output . append ( " " , status ) ; output . append ( ' ' + ( posPower % 10 ) , status ) ; output . append ( ' ' , status ) ; } else { status = kUnitIdentifierSyntaxError ; } if ( U_FAILURE ( status ) ) { return ; } if ( singleUnit . siPrefix != UMEASURE_SI_PREFIX_ONE ) { for ( const auto & siPrefixInfo : gSIPrefixStrings ) { if ( siPrefixInfo . value == singleUnit . siPrefix ) { output . append ( siPrefixInfo . string , status ) ; break ; } } } if ( U_FAILURE ( status ) ) { return ; } output . append ( singleUnit . getSimpleUnitID ( ) , status ) ; }
Generate the identifier string for a single unit in place.
Generate the identifier string for a single unit in place .
// Essentially the "unary per". For compound units with a numerator, the // caller takes care of the "binary per". // no-op