Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Private Attributes
txRomanCounter Class Reference
Inheritance diagram for txRomanCounter:
Inheritance graph
[legend]
Collaboration diagram for txRomanCounter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 txRomanCounter (MBool aUpper)
void appendNumber (PRInt32 aNumber, nsAString &aDest)

Static Public Member Functions

static nsresult getCounterFor (const nsAFlatString &aToken, int aGroupSize, const nsAString &aGroupSeparator, txFormattedCounter *&aCounter)

Public Attributes

nsString mSeparator

Private Attributes

PRInt32 mTableOffset

Detailed Description

Definition at line 72 of file txXSLTNumberCounters.cpp.


Constructor & Destructor Documentation

txRomanCounter::txRomanCounter ( MBool  aUpper) [inline]

Definition at line 74 of file txXSLTNumberCounters.cpp.

                                 : mTableOffset(aUpper ? 30 : 0)
    {
    }

Member Function Documentation

void txRomanCounter::appendNumber ( PRInt32  aNumber,
nsAString &  aDest 
) [virtual]

Implements txFormattedCounter.

Definition at line 221 of file txXSLTNumberCounters.cpp.

{
    // Numbers bigger then 3999 can't be done in roman
    if (aNumber >= 4000) {
        txDecimalCounter().appendNumber(aNumber, aDest);
        return;
    }

    while (aNumber >= 1000) {
        aDest.Append(!mTableOffset ? PRUnichar('m') : PRUnichar('M'));
        aNumber -= 1000;
    }

    PRInt32 posValue;
    
    // Hundreds
    posValue = aNumber / 100;
    aNumber %= 100;
    AppendASCIItoUTF16(kTxRomanNumbers[posValue + mTableOffset], aDest);
    // Tens
    posValue = aNumber / 10;
    aNumber %= 10;
    AppendASCIItoUTF16(kTxRomanNumbers[10 + posValue + mTableOffset], aDest);
    // Ones
    AppendASCIItoUTF16(kTxRomanNumbers[20 + aNumber + mTableOffset], aDest);
}

Here is the call graph for this function:

nsresult txFormattedCounter::getCounterFor ( const nsAFlatString aToken,
int  aGroupSize,
const nsAString &  aGroupSeparator,
txFormattedCounter *&  aCounter 
) [static, inherited]

Definition at line 86 of file txXSLTNumberCounters.cpp.

{
    PRInt32 length = aToken.Length();
    NS_ASSERTION(length, "getting counter for empty token");
    aCounter = 0;
    
    if (length == 1) {
        PRUnichar ch = aToken.CharAt(0);
        switch (ch) {

            case 'i':
            case 'I':
                aCounter = new txRomanCounter(ch == 'I');
                break;
            
            case 'a':
            case 'A':
                aCounter = new txAlphaCounter(ch);
                break;
            
            case '1':
            default:
                // if we don't recognize the token then use "1"
                aCounter = new txDecimalCounter(1, aGroupSize,
                                                aGroupSeparator);
                break;
        }
        return aCounter ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
    }
    
    // for now, the only multi-char token we support are decimals
    PRInt32 i;
    for (i = 0; i < length-1; ++i) {
        if (aToken.CharAt(i) != '0')
            break;
    }
    if (i == length-1 && aToken.CharAt(i) == '1') {
        aCounter = new txDecimalCounter(length, aGroupSize, aGroupSeparator);
    }
    else {
        // if we don't recognize the token then use '1'
        aCounter = new txDecimalCounter(1, aGroupSize, aGroupSeparator);
    }

    return aCounter ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 103 of file txXSLTNumber.h.

Definition at line 81 of file txXSLTNumberCounters.cpp.


The documentation for this class was generated from the following file: