summaryrefslogtreecommitdiffstats
path: root/dom/xslt/xslt/txXSLTNumber.h
blob: e6cdd421009ca1070d8730355cdfd7be2f6e3d38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* -*- 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 "nsError.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 int32_t getSiblingCount(txXPathTreeWalker& aWalker,
                                   txPattern* aCountPattern,
                                   txIMatchContext* aContext);
    
    static bool getPrevInDocumentOrder(txXPathTreeWalker& aWalker);

    static bool isAlphaNumeric(char16_t ch);
};

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

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

#endif //TRANSFRMX_TXXSLTNUMBER_H