summaryrefslogtreecommitdiffstats
path: root/dom/xslt/xslt/txXSLTFunctions.h
blob: 4b7401eb8369467418b0aa10801d36b0237797dd (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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_XSLT_FUNCTIONS_H
#define TRANSFRMX_XSLT_FUNCTIONS_H

#include "mozilla/UniquePtr.h"
#include "txExpr.h"
#include "txXMLUtils.h"
#include "txNamespaceMap.h"

class txStylesheet;

/**
 * The definition for the XSLT document() function
 **/
class DocumentFunctionCall : public FunctionCall {
 public:
  /**
   * Creates a new document() function call
   **/
  explicit DocumentFunctionCall(const nsAString& aBaseURI);

  TX_DECL_FUNCTION

 private:
  nsString mBaseURI;
};

/*
 * The definition for the XSLT key() function
 */
class txKeyFunctionCall : public FunctionCall {
 public:
  /*
   * Creates a new key() function call
   */
  explicit txKeyFunctionCall(txNamespaceMap* aMappings);

  TX_DECL_FUNCTION

 private:
  RefPtr<txNamespaceMap> mMappings;
};

/**
 * The definition for the XSLT format-number() function
 **/
class txFormatNumberFunctionCall : public FunctionCall {
 public:
  /**
   * Creates a new format-number() function call
   **/
  txFormatNumberFunctionCall(txStylesheet* aStylesheet,
                             txNamespaceMap* aMappings);

  TX_DECL_FUNCTION

 private:
  static const char16_t FORMAT_QUOTE;

  enum FormatParseState {
    Prefix,
    IntDigit,
    IntZero,
    FracZero,
    FracDigit,
    Suffix,
    Finished
  };

  // Helper that reports and invalid arg to the provided context.
  void ReportInvalidArg(txIEvalContext* aContext);

  txStylesheet* mStylesheet;
  RefPtr<txNamespaceMap> mMappings;
};

/**
 * DecimalFormat
 * A representation of the XSLT element <xsl:decimal-format>
 */
class txDecimalFormat {
 public:
  /*
   * Creates a new decimal format and initilizes all properties with
   * default values
   */
  txDecimalFormat();
  bool isEqual(txDecimalFormat* other);

  char16_t mDecimalSeparator;
  char16_t mGroupingSeparator;
  nsString mInfinity;
  char16_t mMinusSign;
  nsString mNaN;
  char16_t mPercent;
  char16_t mPerMille;
  char16_t mZeroDigit;
  char16_t mDigit;
  char16_t mPatternSeparator;
};

/**
 * The definition for the XSLT current() function
 **/
class CurrentFunctionCall : public FunctionCall {
 public:
  /**
   * Creates a new current() function call
   **/
  CurrentFunctionCall();

  TX_DECL_FUNCTION
};

/**
 * The definition for the XSLT generate-id() function
 **/
class GenerateIdFunctionCall : public FunctionCall {
 public:
  /**
   * Creates a new generate-id() function call
   **/
  GenerateIdFunctionCall();

  TX_DECL_FUNCTION
};

/**
 * A system-property(), element-available() or function-available() function.
 */
class txXSLTEnvironmentFunctionCall : public FunctionCall {
 public:
  enum eType { SYSTEM_PROPERTY, ELEMENT_AVAILABLE, FUNCTION_AVAILABLE };

  txXSLTEnvironmentFunctionCall(eType aType, txNamespaceMap* aMappings)
      : mType(aType), mMappings(aMappings) {}

  TX_DECL_FUNCTION

 private:
  eType mType;
  RefPtr<txNamespaceMap> mMappings;  // Used to resolve prefixes
};

#endif