content/xslt/src/xslt/txXSLTNumber.h
author David Anderson <danderson@mozilla.com>
Mon, 21 May 2012 14:40:04 -0700
changeset 106274 80e4ab0d24bc64ceaa7693ab5def36faffde7a40
parent 105377 7c70058ad7b7503b674d110cd91209605fa80bfe
parent 94484 f4157e8c410708d76703f19e4dfb61859bfe32d8
child 106735 dc5fc4265990c8ecb269195372959f757af7d00e
permissions -rw-r--r--
Merge from mozilla-central.

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef TRANSFRMX_TXXSLTNUMBER_H
#define TRANSFRMX_TXXSLTNUMBER_H

#include "txError.h"
#include "txList.h"
#include "nsString.h"

class Expr;
class txPattern;
class txIEvalContext;
class txIMatchContext;
class txXPathTreeWalker;

class txXSLTNumber {
public:
    enum LevelType {
        eLevelSingle,
        eLevelMultiple,
        eLevelAny
    };

    static nsresult createNumber(Expr* aValueExpr, txPattern* aCountPattern,
                                 txPattern* aFromPattern, LevelType aLevel,
                                 Expr* aGroupSize, Expr* aGroupSeparator,
                                 Expr* aFormat, txIEvalContext* aContext,
                                 nsAString& aResult);

private:
    static nsresult getValueList(Expr* aValueExpr, txPattern* aCountPattern,
                                 txPattern* aFromPattern, LevelType aLevel,
                                 txIEvalContext* aContext, txList& aValues,
                                 nsAString& aValueString);

    static nsresult getCounters(Expr* aGroupSize, Expr* aGroupSeparator,
                                Expr* aFormat, txIEvalContext* aContext,
                                txList& aCounters, nsAString& aHead,
                                nsAString& aTail);

    /**
     * getSiblingCount uses aWalker to walk the siblings of aWalker's current
     * position.
     *
     */
    static PRInt32 getSiblingCount(txXPathTreeWalker& aWalker,
                                   txPattern* aCountPattern,
                                   txIMatchContext* aContext);
    
    static bool getPrevInDocumentOrder(txXPathTreeWalker& aWalker);

    static bool isAlphaNumeric(PRUnichar ch);
};

class txFormattedCounter {
public:
    virtual ~txFormattedCounter()
    {
    }
    
    virtual void appendNumber(PRInt32 aNumber, nsAString& aDest) = 0;

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

#endif //TRANSFRMX_TXXSLTNUMBER_H