Initial revision
[TestXSLT.git] / libsablot / src / engine / decimal.h
1 /* 
2  * The contents of this file are subject to the Mozilla Public
3  * License Version 1.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.mozilla.org/MPL/
6  * 
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  * 
12  * The Original Code is the Sablotron XSLT Processor.
13  * 
14  * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15  * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16  * Ginger Alliance Ltd. All Rights Reserved.
17  * 
18  * Contributor(s):
19  * 
20  * Alternatively, the contents of this file may be used under the
21  * terms of the GNU General Public License Version 2 or later (the
22  * "GPL"), in which case the provisions of the GPL are applicable 
23  * instead of those above.  If you wish to allow use of your 
24  * version of this file only under the terms of the GPL and not to
25  * allow others to use your version of this file under the MPL,
26  * indicate your decision by deleting the provisions above and
27  * replace them with the notice and other provisions required by
28  * the GPL.  If you do not delete the provisions above, a recipient
29  * may use your version of this file under either the MPL or the
30  * GPL.
31  */
32
33 #ifndef DecimalHIncl
34 #define DecimalHIncl
35
36 #include "base.h"
37 #include "datastr.h"
38
39 class DefaultedStr;
40 class Number;
41
42 class DefaultedStr
43 {
44 public:
45     DefaultedStr(const char* defaultValue_, Bool singleChar_, XSL_ATT id_);
46     ~DefaultedStr();
47     eFlag set(Sit S, const Str& value);
48     const Str& get();
49     void report(Sit S, MsgType type, MsgCode code, 
50                 const Str &arg1, const Str &arg2) const;
51 private:
52     char* ownName();
53     Str defaultValue,
54         specifiedValue;
55     Bool specified,
56         singleChar;
57     XSL_ATT id;
58 };
59
60 // the DecimalFormat class made after java.text.DecimalFormat
61 // it's rather a 'format format' or meta-format
62
63 class DecimalFormat
64 {
65 public:
66     DecimalFormat(const EQName& name);
67     ~DecimalFormat();
68     eFlag setItem(Sit S, XSL_ATT itemId, const Str& value);
69     const Str& getItem(XSL_ATT itemId);
70     eFlag format(Sit S, Number& num, const Str& fmt, Str& result);
71     const EQName& getname();
72     void report(Sit S, MsgType type, MsgCode code, 
73                 const Str &arg1, const Str &arg2) const;
74 private:
75     EQName name;
76     DefaultedStr
77         decimalSeparator,
78         groupingSeparator,
79         infinity,
80         minusSign,
81         NaN,
82         percent,
83         perMille,
84         zeroDigit,
85         digit,
86         patternSeparator;
87     DefaultedStr* findItem(XSL_ATT itemId);
88     XSL_ATT whichToken(const char* ptr, int len);
89     eFlag parseSubpattern(
90         Sit S, const char *&ptr, Bool negative, 
91         Str& prefix, Str& suffix, int& factor,
92         int& iDigitsMin, int& fDigits, int& fDigitsMin, int& gSize);
93     eFlag parse(
94         Sit S, const Str &src, Bool negative,
95         Str& prefix, Str& suffix, int& factor,
96         int& iDigitsMin, int& fDigits, int& fDigitsMin, int& gSize);
97 };
98
99 class DecimalFormatList: public PList<DecimalFormat*>
100 {
101 public:
102     DecimalFormatList();
103     void initialize();
104     ~DecimalFormatList();
105     eFlag add(Sit S, const EQName& name, DecimalFormat*& result);
106     eFlag format(Sit S, const EQName& name, Number& num, const Str& fmt, Str& result);
107     void report(Sit S, MsgType type, MsgCode code, 
108                 const Str &arg1, const Str &arg2) const;
109 private:
110     int findNdx(const EQName& name);
111 };
112
113 #endif // DecimalHIncl
114
115
116