Merge lp:~zorba-coders/zorba/bug-1123164 into lp:zorba
- bug-1123164
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Paul J. Lucas | ||||
Approved revision: | 11295 | ||||
Merged at revision: | 11367 | ||||
Proposed branch: | lp:~zorba-coders/zorba/bug-1123164 | ||||
Merge into: | lp:zorba | ||||
Diff against target: |
2781 lines (+1222/-762) 88 files modified
ChangeLog (+1/-0) include/zorba/pregenerated/diagnostic_list.h (+4/-0) modules/w3c/pregenerated/xqt-errors.xq (+20/-1) src/compiler/parser/jsoniq_parser.cpp (+1/-1) src/compiler/parser/jsoniq_parser.y (+1/-1) src/compiler/parser/xquery_parser.cpp (+1/-1) src/compiler/parser/xquery_parser.y (+1/-1) src/compiler/translator/translator.cpp (+3/-3) src/context/decimal_format.cpp (+110/-54) src/context/decimal_format.h (+28/-36) src/diagnostics/diagnostic_en.xml (+56/-41) src/diagnostics/pregenerated/diagnostic_list.cpp (+6/-0) src/diagnostics/pregenerated/dict_en.cpp (+12/-8) src/diagnostics/pregenerated/dict_zed_keys.h (+9/-7) src/runtime/CMakeLists.txt (+1/-0) src/runtime/numerics/format_integer.cpp (+12/-7) src/runtime/numerics/format_number.cpp (+847/-0) src/runtime/numerics/numerics_impl.cpp (+0/-572) src/util/utf8_util_base.h (+12/-1) src/zorbatypes/floatimpl.h (+6/-0) test/fots/CMakeLists.txt (+13/-24) test/rbkt/ExpQueryResults/zorba/numerics/format-integer/format-integer-1-11.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-01.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-02.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-03.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-04.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-05.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-06.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-07.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-08.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-09.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-10.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-11.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-12.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-13.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-14.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-15.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-01.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-02.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-03.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-empty.xml.res (+1/-0) test/rbkt/ExpQueryResults/zorba/numerics/format-number1.xml.res (+0/-1) test/rbkt/ExpQueryResults/zorba/numerics/format-number2.xml.res (+0/-1) test/rbkt/Queries/zorba/numerics/format-integer/format-integer-1-11.xq (+7/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-01.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-02.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-03.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-04.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-05.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-06.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-07.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-08.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-09.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-10.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-11.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-12.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-13.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-14.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-15.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-1.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-1.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-2.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-2.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-3.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-3.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-4.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-4.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MustHaveOptOrMandatoryDigit.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-MustHaveOptOrMandatoryDigit.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoActivePassiveActive.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoActivePassiveActive.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-1.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-1.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-2.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-2.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoMandatoryDigitAfterOpt.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoMandatoryDigitAfterOpt.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoOptDigitAfterMandatory.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoOptDigitAfterMandatory.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-1.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-1.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-2.spec (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-2.xq (+1/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-01.xq (+5/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-02.xq (+3/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-03.xq (+3/-0) test/rbkt/Queries/zorba/numerics/format-number/format-number-empty.xq (+1/-1) test/rbkt/Queries/zorba/numerics/format-number1.xq (+0/-1) |
||||
To merge this branch: | bzr merge lp:~zorba-coders/zorba/bug-1123164 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthias Brantner | Approve | ||
Nicolae Brinza | Approve | ||
Paul J. Lucas | Approve | ||
Review via email: mp+158254@code.launchpad.net |
Commit message
Rewrote format-number() code because it was simpler than trying to hack fix the old code.
Description of the change
Rewrote format-number() code because it was simpler than trying to hack fix the old code.
Paul J. Lucas (paul-lucas) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/bug-1123164 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1123164-2013-04-
final status was:
3 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~zorba-coders/zorba/bug-1123164 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1123164-2013-04-
final status was:
1 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job bug-1123164-2013-04-
All tests succeeded!
Zorba Build Bot (zorba-buildbot) wrote : | # |
Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve.
Nicolae Brinza (nbrinza) : | # |
Matthias Brantner (matthias-brantner) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Attempt to merge into lp:zorba failed due to conflicts:
text conflict in ChangeLog
- 11295. By Paul J. Lucas
-
Merge from trunk.
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job bug-1123164-2013-04-
All tests succeeded!
Preview Diff
1 | === modified file 'ChangeLog' |
2 | --- ChangeLog 2013-04-11 07:20:03 +0000 |
3 | +++ ChangeLog 2013-04-11 17:02:25 +0000 |
4 | @@ -71,6 +71,7 @@ |
5 | * Fixed bug #1099535 (xml:parse endless loop) |
6 | * Fixed bug in optimizing fn:count over general-index probes |
7 | * Fixed bug #866958 (Parsing error not explicit enough) |
8 | + * Fixed bug #1123164 (fn:format-number failures (at least 19)) |
9 | * Fixed memory leak in temp sequence |
10 | * Fixed bug in computing the static type of a self-axis path step. |
11 | * Fixed bug #867068: (Incorrect usage of XQDY0027) |
12 | |
13 | === modified file 'include/zorba/pregenerated/diagnostic_list.h' |
14 | --- include/zorba/pregenerated/diagnostic_list.h 2013-04-02 21:46:10 +0000 |
15 | +++ include/zorba/pregenerated/diagnostic_list.h 2013-04-11 17:02:25 +0000 |
16 | @@ -148,6 +148,8 @@ |
17 | |
18 | extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0094; |
19 | |
20 | +extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0097; |
21 | + |
22 | extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0098; |
23 | |
24 | extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0099; |
25 | @@ -158,6 +160,8 @@ |
26 | |
27 | extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0111; |
28 | |
29 | +extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0114; |
30 | + |
31 | extern ZORBA_DLL_PUBLIC XQueryErrorCode XQST0123; |
32 | |
33 | extern ZORBA_DLL_PUBLIC XQueryErrorCode XPDY0002; |
34 | |
35 | === modified file 'modules/w3c/pregenerated/xqt-errors.xq' |
36 | --- modules/w3c/pregenerated/xqt-errors.xq 2013-04-02 21:46:10 +0000 |
37 | +++ modules/w3c/pregenerated/xqt-errors.xq 2013-04-11 17:02:25 +0000 |
38 | @@ -626,6 +626,15 @@ |
39 | |
40 | (:~ |
41 | : |
42 | + : It is a static error for a decimal-format to specify a value that is |
43 | + : not valid for a given property. |
44 | + : |
45 | + : @see http://www.w3.org/2005/xqt-errors |
46 | +:) |
47 | +declare variable $err:XQST0097 as xs:QName := fn:QName($err:NS, "err:XQST0097"); |
48 | + |
49 | +(:~ |
50 | + : |
51 | : It is a static error if, for any named or unnamed decimal format, the |
52 | : properties representing characters used in a picture string do not each |
53 | : have distinct values. These properties are decimal-separator-sign, |
54 | @@ -674,7 +683,17 @@ |
55 | |
56 | (:~ |
57 | : |
58 | - : It is a static error if the name of a feature in require-feature is not recognized by the implementation. |
59 | + : It is a static error for a decimal format declaration to define the |
60 | + : same property more than once. |
61 | + : |
62 | + : @see http://www.w3.org/2005/xqt-errors |
63 | +:) |
64 | +declare variable $err:XQST0114 as xs:QName := fn:QName($err:NS, "err:XQST0114"); |
65 | + |
66 | +(:~ |
67 | + : |
68 | + : It is a static error if the name of a feature in require-feature is not |
69 | + : recognized by the implementation. |
70 | : |
71 | : @see http://www.w3.org/2005/xqt-errors |
72 | :) |
73 | |
74 | === modified file 'src/compiler/parser/jsoniq_parser.cpp' |
75 | --- src/compiler/parser/jsoniq_parser.cpp 2013-04-07 19:06:10 +0000 |
76 | +++ src/compiler/parser/jsoniq_parser.cpp 2013-04-11 17:02:25 +0000 |
77 | @@ -3713,7 +3713,7 @@ |
78 | |
79 | /* Line 690 of lalr1.cc */ |
80 | #line 1626 "/home/colea/xquery/new-jsoniq/src/compiler/parser/jsoniq_parser.y" |
81 | - { (yyval.strval) = "infinty"; } |
82 | + { (yyval.strval) = "infinity"; } |
83 | break; |
84 | |
85 | case 98: |
86 | |
87 | === modified file 'src/compiler/parser/jsoniq_parser.y' |
88 | --- src/compiler/parser/jsoniq_parser.y 2013-03-27 17:32:54 +0000 |
89 | +++ src/compiler/parser/jsoniq_parser.y 2013-04-11 17:02:25 +0000 |
90 | @@ -1623,7 +1623,7 @@ |
91 | DECIMAL_SEPARATOR { $$ = "decimal-separator"; } |
92 | | DIGIT { $$ = "digit"; } |
93 | | GROUPING_SEPARATOR { $$ = "grouping-separator"; } |
94 | - | INFINITY_VALUE { $$ = "infinty"; } |
95 | + | INFINITY_VALUE { $$ = "infinity"; } |
96 | | MINUS_SIGN { $$ = "minus-sign"; } |
97 | | NaN { $$ = "NaN"; } |
98 | | PATTERN_SEPARATOR { $$ = "pattern-separator"; } |
99 | |
100 | === modified file 'src/compiler/parser/xquery_parser.cpp' |
101 | --- src/compiler/parser/xquery_parser.cpp 2013-04-07 19:06:10 +0000 |
102 | +++ src/compiler/parser/xquery_parser.cpp 2013-04-11 17:02:25 +0000 |
103 | @@ -3757,7 +3757,7 @@ |
104 | |
105 | /* Line 690 of lalr1.cc */ |
106 | #line 1602 "/home/colea/xquery/new-jsoniq/src/compiler/parser/xquery_parser.y" |
107 | - { (yyval.strval) = "infinty"; } |
108 | + { (yyval.strval) = "infinity"; } |
109 | break; |
110 | |
111 | case 96: |
112 | |
113 | === modified file 'src/compiler/parser/xquery_parser.y' |
114 | --- src/compiler/parser/xquery_parser.y 2013-03-20 23:33:11 +0000 |
115 | +++ src/compiler/parser/xquery_parser.y 2013-04-11 17:02:25 +0000 |
116 | @@ -1599,7 +1599,7 @@ |
117 | DECIMAL_SEPARATOR { $$ = "decimal-separator"; } |
118 | | DIGIT { $$ = "digit"; } |
119 | | GROUPING_SEPARATOR { $$ = "grouping-separator"; } |
120 | - | INFINITY_VALUE { $$ = "infinty"; } |
121 | + | INFINITY_VALUE { $$ = "infinity"; } |
122 | | MINUS_SIGN { $$ = "minus-sign"; } |
123 | | NaN { $$ = "NaN"; } |
124 | | PATTERN_SEPARATOR { $$ = "pattern-separator"; } |
125 | |
126 | === modified file 'src/compiler/translator/translator.cpp' |
127 | --- src/compiler/translator/translator.cpp 2013-04-11 10:18:59 +0000 |
128 | +++ src/compiler/translator/translator.cpp 2013-04-11 17:02:25 +0000 |
129 | @@ -2902,9 +2902,9 @@ |
130 | expand_no_default_qname(qnameItem, v.format_name, loc); |
131 | } |
132 | |
133 | - DecimalFormat_t df = new DecimalFormat(v.is_default, qnameItem, v.param_list); |
134 | - df->validate(loc); |
135 | - theSctx->add_decimal_format(df, loc); |
136 | + theSctx->add_decimal_format( |
137 | + new DecimalFormat( v.is_default, qnameItem, v.param_list, loc ), loc |
138 | + ); |
139 | |
140 | return no_state; |
141 | } |
142 | |
143 | === modified file 'src/context/decimal_format.cpp' |
144 | --- src/context/decimal_format.cpp 2013-02-07 17:24:36 +0000 |
145 | +++ src/context/decimal_format.cpp 2013-04-11 17:02:25 +0000 |
146 | @@ -16,68 +16,124 @@ |
147 | #include "stdafx.h" |
148 | |
149 | #include <zorba/api_shared_types.h> |
150 | +#include "common/shared_types.h" |
151 | #include "context/decimal_format.h" |
152 | -#include "common/shared_types.h" |
153 | - |
154 | +#include "store/api/item.h" |
155 | +#include "util/stl_util.h" |
156 | +#include "util/utf8_util.h" |
157 | +#include "zorbaserialization/serialize_template_types.h" |
158 | #include "zorbaserialization/serialize_zorba_types.h" |
159 | -#include "zorbaserialization/serialize_template_types.h" |
160 | - |
161 | -#include "store/api/item.h" |
162 | |
163 | namespace zorba { |
164 | |
165 | SERIALIZABLE_CLASS_VERSIONS(DecimalFormat) |
166 | |
167 | - |
168 | -DecimalFormat::DecimalFormat( |
169 | - bool isDefault, |
170 | - const store::Item_t& qname, |
171 | - const param_vector_type& params) |
172 | - : |
173 | - theIsDefault(isDefault), |
174 | - theName(qname), |
175 | - theParams(params) |
176 | -{ |
177 | -} |
178 | - |
179 | - |
180 | -void DecimalFormat::serialize(::zorba::serialization::Archiver& ar) |
181 | -{ |
182 | - ar & theIsDefault; |
183 | - ar & theName; |
184 | - ar & theParams; |
185 | -} |
186 | - |
187 | - |
188 | -bool DecimalFormat::isPictureStringProperty(zstring propertyName) |
189 | -{ |
190 | - if (propertyName == "decimal-separator" || |
191 | - propertyName == "grouping-separator" || |
192 | - propertyName == "percent" || |
193 | - propertyName == "per-mille" || |
194 | - propertyName == "zero-digit" || |
195 | - propertyName == "digit" || |
196 | - propertyName == "pattern-separator") |
197 | - return true; |
198 | - else |
199 | - return false; |
200 | -} |
201 | - |
202 | -bool DecimalFormat::validate(const QueryLoc& loc) const |
203 | -{ |
204 | - for (unsigned int i = 0; i<theParams.size()-1; i++) |
205 | - for (unsigned int j = i+1; j<theParams.size(); j++) |
206 | - { |
207 | - if (isPictureStringProperty(theParams[i].first) |
208 | - && |
209 | - isPictureStringProperty(theParams[j].first) |
210 | - && |
211 | - theParams[i].second == theParams[j].second) |
212 | - throw XQUERY_EXCEPTION(err::XQST0098, ERROR_PARAMS(theParams[i].first, theParams[j].first), ERROR_LOC(loc)); |
213 | +/////////////////////////////////////////////////////////////////////////////// |
214 | + |
215 | +DecimalFormat::DecimalFormat( bool is_default, const store::Item_t& qname, |
216 | + ctor_properties_type const &properties, |
217 | + QueryLoc const &loc ) : |
218 | + is_default_( is_default ), |
219 | + qname_( qname ) |
220 | +{ |
221 | + for ( ctor_properties_type::size_type i = 0; i < properties.size() - 1; |
222 | + ++i ) { |
223 | + for ( ctor_properties_type::size_type j = i + 1; j < properties.size(); |
224 | + ++j ) { |
225 | + if ( i == j ) |
226 | + continue; |
227 | + if ( properties[i].first == properties[j].first ) { |
228 | + // |
229 | + // XQuery 3.0 4.10: It is a static error for a decimal format |
230 | + // declaration to define the same property more than once. |
231 | + // |
232 | + throw XQUERY_EXCEPTION( |
233 | + err::XQST0114, |
234 | + ERROR_PARAMS( properties[i].first ), |
235 | + ERROR_LOC( loc ) |
236 | + ); |
237 | + } |
238 | + if ( properties[i].second == properties[j].second ) { |
239 | + // |
240 | + // Ibid: It is a static error if, for any named or unnamed decimal |
241 | + // format, the properties representing characters used in a picture |
242 | + // string do not have distinct values. |
243 | + // |
244 | + throw XQUERY_EXCEPTION( |
245 | + err::XQST0098, |
246 | + ERROR_PARAMS( |
247 | + properties[i].second, properties[i].first, properties[j].first |
248 | + ), |
249 | + ERROR_LOC( loc ) |
250 | + ); |
251 | + } |
252 | + } // for ( ... j ... ) |
253 | + } // for ( ... i ... ) |
254 | + |
255 | + FOR_EACH( ctor_properties_type, property, properties ) |
256 | + properties_[ property->first ] = property->second; |
257 | + |
258 | + struct property_attribute { |
259 | + char const *name; |
260 | + bool is_string; |
261 | + char const *default_value; |
262 | + }; |
263 | + |
264 | + static property_attribute const attributes[] = { |
265 | + { "decimal-separator" , false, "." }, |
266 | + { "digit" , false, "#" }, |
267 | + { "grouping-separator", false, "," }, |
268 | + { "infinity" , true , "Infinity" }, |
269 | + { "minus-sign" , false, "-" }, |
270 | + { "NaN" , true , "Nan" }, |
271 | + { "pattern-separator" , false, ";" }, |
272 | + { "percent" , false, "%" }, |
273 | + { "per-mille" , false, "\xE2\x80\xB0" }, |
274 | + { "zero-digit" , false, "0" }, |
275 | + { 0, false, 0 } |
276 | + }; |
277 | + |
278 | + for ( property_attribute const *attr = attributes; attr->name; ++attr ) { |
279 | + value_type &value = properties_[ attr->name ]; |
280 | + if ( value.empty() ) |
281 | + value = attr->default_value; |
282 | + else if ( !attr->is_string && utf8::length( value ) > 1 ) { |
283 | + // |
284 | + // Ibid: It is a static error for a decimal format declaration to specify |
285 | + // a value that is not valid for a given property. |
286 | + // |
287 | + throw XQUERY_EXCEPTION( |
288 | + err::XQST0097, |
289 | + ERROR_PARAMS( value, attr->name, ZED( XQST0097_MustBeChar ) ), |
290 | + ERROR_LOC( loc ) |
291 | + ); |
292 | } |
293 | - |
294 | - return true; |
295 | -} |
296 | + } |
297 | + |
298 | + // |
299 | + // XQuery 3.0 2.1.1: zero-digit specifies the character used for the zero- |
300 | + // digit-symbol; the default value is the digit zero (0). This character must |
301 | + // be a digit (category Nd in the Unicode property database), and it must |
302 | + // have the numeric value zero. |
303 | + // |
304 | + value_type const &zero_digit = properties_[ "zero-digit" ]; |
305 | + unicode::code_point const zero_digit_cp = utf8::decode( zero_digit.c_str() ); |
306 | + unicode::code_point zero_cp; |
307 | + if ( !unicode::is_Nd( zero_digit_cp, &zero_cp ) || zero_digit_cp != zero_cp ) |
308 | + throw XQUERY_EXCEPTION( |
309 | + err::XQST0097, |
310 | + ERROR_PARAMS( zero_digit, "zero-digit", ZED( XQST0097_MustBeZeroDigit ) ), |
311 | + ERROR_LOC( loc ) |
312 | + ); |
313 | +} |
314 | + |
315 | +void DecimalFormat::serialize( serialization::Archiver &ar ) { |
316 | + ar & is_default_; |
317 | + ar & qname_; |
318 | + ar & properties_; |
319 | +} |
320 | + |
321 | +/////////////////////////////////////////////////////////////////////////////// |
322 | |
323 | } // namespace zorba |
324 | /* vim:set et sw=2 ts=2: */ |
325 | |
326 | === modified file 'src/context/decimal_format.h' |
327 | --- src/context/decimal_format.h 2013-02-07 17:24:36 +0000 |
328 | +++ src/context/decimal_format.h 2013-04-11 17:02:25 +0000 |
329 | @@ -17,60 +17,52 @@ |
330 | #ifndef ZORBA_DECIMAL_FORMAT_H |
331 | #define ZORBA_DECIMAL_FORMAT_H |
332 | |
333 | +#include <utility> /* for pair */ |
334 | +#include <map> |
335 | #include <vector> |
336 | |
337 | #include "common/shared_types.h" |
338 | - |
339 | +#include "store/api/item.h" |
340 | +#include "util/unordered_map.h" |
341 | +#include "zorbaserialization/class_serializer.h" |
342 | #include "zorbatypes/zstring.h" |
343 | |
344 | -#include "zorbaserialization/class_serializer.h" |
345 | - |
346 | -#include "store/api/item.h" |
347 | - |
348 | - |
349 | -namespace zorba |
350 | -{ |
351 | - |
352 | -class DecimalFormat : public SimpleRCObject |
353 | -{ |
354 | +/////////////////////////////////////////////////////////////////////////////// |
355 | + |
356 | +namespace zorba { |
357 | + |
358 | +class DecimalFormat : public SimpleRCObject { |
359 | public: |
360 | - typedef std::vector<std::pair<zstring,zstring> > param_vector_type; |
361 | + typedef zstring name_type; |
362 | + typedef zstring value_type; |
363 | |
364 | -protected: |
365 | - bool theIsDefault; |
366 | - store::Item_t theName; |
367 | - param_vector_type theParams; |
368 | + typedef std::vector< std::pair<name_type,value_type> > ctor_properties_type; |
369 | + typedef std::map<name_type,value_type> properties_type; |
370 | |
371 | public: |
372 | SERIALIZABLE_CLASS(DecimalFormat) |
373 | SERIALIZABLE_CLASS_CONSTRUCTOR2(DecimalFormat, SimpleRCObject) |
374 | - void serialize(::zorba::serialization::Archiver& ar); |
375 | - |
376 | -protected: |
377 | - // Returns true if the given property represents characters used in a |
378 | - // picture string. These properties are decimal-separator-sign, |
379 | - // grouping-separator, percent-sign, per-mille-sign, zero-digit, |
380 | - // digit-sign, and pattern-separator-sign. |
381 | - static bool isPictureStringProperty(zstring propertyName); |
382 | + void serialize( serialization::Archiver& ); |
383 | |
384 | public: |
385 | - DecimalFormat( |
386 | - bool isDefault, |
387 | - const store::Item_t& qname, |
388 | - const param_vector_type& params); |
389 | - |
390 | - bool isDefault() const { return theIsDefault; } |
391 | - |
392 | - const store::Item* getName() const { return theName.getp(); } |
393 | - |
394 | - const param_vector_type* getParamVector() const { return &theParams; } |
395 | - |
396 | - bool validate(const QueryLoc& loc) const; |
397 | + DecimalFormat( bool is_default, store::Item_t const &qname, |
398 | + ctor_properties_type const &properties, QueryLoc const &loc ); |
399 | + |
400 | + store::Item const* getName() const { return qname_.getp(); } |
401 | + properties_type const& getProperties() const { return properties_; } |
402 | + bool isDefault() const { return is_default_; } |
403 | + |
404 | +private: |
405 | + bool is_default_; |
406 | + store::Item_t qname_; |
407 | + properties_type properties_; |
408 | }; |
409 | |
410 | |
411 | typedef rchandle<DecimalFormat> DecimalFormat_t; |
412 | |
413 | +/////////////////////////////////////////////////////////////////////////////// |
414 | + |
415 | } /* namespace zorba */ |
416 | #endif /* ZORBA_DECIMAL_FORMAT_H */ |
417 | |
418 | |
419 | === modified file 'src/diagnostics/diagnostic_en.xml' |
420 | --- src/diagnostics/diagnostic_en.xml 2013-04-08 22:59:58 +0000 |
421 | +++ src/diagnostics/diagnostic_en.xml 2013-04-11 17:02:25 +0000 |
422 | @@ -264,13 +264,12 @@ |
423 | |
424 | <diagnostic code="XPTY0004"> |
425 | <comment> |
426 | - It is a type error if, during the static analysis phase, an expression |
427 | - is found to have a static type that is not appropriate for the context |
428 | - in which the expression occurs, or during the dynamic evaluation phase, |
429 | - the dynamic type of a value does not match a required type as specified |
430 | - by the matching rules in 2.5.4 SequenceType Matching. |
431 | + It is a type error if, during the static analysis phase, an expression |
432 | + is found to have a static type that is not appropriate for the context |
433 | + in which the expression occurs, or during the dynamic evaluation phase, |
434 | + the dynamic type of a value does not match a required type as specified |
435 | + by the matching rules in 2.5.4 SequenceType Matching. |
436 | </comment> |
437 | - |
438 | <value>$1</value> |
439 | |
440 | <entry key="NoReturnTypePromote_234"> |
441 | @@ -293,10 +292,6 @@ |
442 | <value>$2 can not be treated as type $3</value> |
443 | </entry> |
444 | |
445 | - <entry key="FormatNumber_2"> |
446 | - <value>first parameter to format-number() function is type $2 that is not allowed</value> |
447 | - </entry> |
448 | - |
449 | <entry key="JSONIQ_SELECTOR"> |
450 | <value>can not atomize and/or cast value of type $2 to string</value> |
451 | </entry> |
452 | @@ -765,15 +760,29 @@ |
453 | <value>"$1": grouping variable not defined in the same flwor expression as the group-by clause</value> |
454 | </diagnostic> |
455 | |
456 | + <diagnostic code="XQST0097"> |
457 | + <comment> |
458 | + It is a static error for a decimal-format to specify a value that is |
459 | + not valid for a given property. |
460 | + </comment> |
461 | + <value>"$1": illegal value for decimal format property "$2"${: 3}</value> |
462 | + <entry key="MustBeChar"> |
463 | + <value>must be a single character</value> |
464 | + </entry> |
465 | + <entry key="MustBeZeroDigit"> |
466 | + <value>must be a digit (Unicode category Nd) and represent zero</value> |
467 | + </entry> |
468 | + </diagnostic> |
469 | + |
470 | <diagnostic code="XQST0098"> |
471 | <comment> |
472 | - It is a static error if, for any named or unnamed decimal format, the |
473 | - properties representing characters used in a picture string do not each |
474 | - have distinct values. These properties are decimal-separator-sign, |
475 | - grouping-separator, percent-sign, per-mille-sign, zero-digit, |
476 | - digit-sign, and pattern-separator-sign. |
477 | + It is a static error if, for any named or unnamed decimal format, the |
478 | + properties representing characters used in a picture string do not each |
479 | + have distinct values. These properties are decimal-separator-sign, |
480 | + grouping-separator, percent-sign, per-mille-sign, zero-digit, |
481 | + digit-sign, and pattern-separator-sign. |
482 | </comment> |
483 | - <value>properties "$1" and "$2", representing characters used in picture string, do not have distinct values</value> |
484 | + <value>"$1": value of properties "$1" and "$2" for characters used a in picture string is the same but must be distinct</value> |
485 | </diagnostic> |
486 | |
487 | <diagnostic code="XQST0099"> |
488 | @@ -814,9 +823,18 @@ |
489 | <value>$1</value> |
490 | </diagnostic> |
491 | |
492 | + <diagnostic code="XQST0114"> |
493 | + <comment> |
494 | + It is a static error for a decimal format declaration to define the |
495 | + same property more than once. |
496 | + </comment> |
497 | + <value>"$1": duplicate decimal format property</value> |
498 | + </diagnostic> |
499 | + |
500 | <diagnostic code="XQST0123"> |
501 | <comment> |
502 | - It is a static error if the name of a feature in require-feature is not recognized by the implementation. |
503 | + It is a static error if the name of a feature in require-feature is not |
504 | + recognized by the implementation. |
505 | </comment> |
506 | <value>$1</value> |
507 | </diagnostic> |
508 | @@ -1319,6 +1337,12 @@ |
509 | Invalid decimal/integer format picture string. |
510 | </comment> |
511 | <value>"$1": invalid picture string for decimal/integer${: 2}</value> |
512 | + <entry key="NoOptDigitAfterMandatory_3"> |
513 | + <value>'$3': optional-digit-sign in integer part of sub-picture may not follow a member of the decimal-digit-family</value> |
514 | + </entry> |
515 | + <entry key="NoMandatoryDigitAfterOpt_3"> |
516 | + <value>'$3': member of decimal-digit-family in fractional part of a sub-picture may not follow an optional-digit-sign</value> |
517 | + </entry> |
518 | <entry key="BadCharacter_3"> |
519 | <value>'$3': invalid character</value> |
520 | </entry> |
521 | @@ -1337,9 +1361,21 @@ |
522 | <entry key="EmptyFormat"> |
523 | <value>empty primary format</value> |
524 | </entry> |
525 | + <entry key="MultipleSign_3"> |
526 | + <value>"$3": multiple such signs are illegal</value> |
527 | + </entry> |
528 | + <entry key="MustHaveOptOrMandatoryDigit"> |
529 | + <value>sub-picture must contain at least one optional or mandatory digit</value> |
530 | + </entry> |
531 | + <entry key="NoActivePassiveActive"> |
532 | + <value>"$3": active character may not follow passive that follows active</value> |
533 | + </entry> |
534 | <entry key="NoAdjacentGroupSep_3"> |
535 | <value>"$3": grouping separator must not be adjacent to others</value> |
536 | </entry> |
537 | + <entry key="NoDecimalGroupingAdjacent_34"> |
538 | + <value>decimal-separator-sign ('$3') and grouping-separator-sign ('$4') may not be adjacent</value> |
539 | + </entry> |
540 | <entry key="NoGroupSepAtStart_3"> |
541 | <value>"$3": grouping separator illegal at start of decimal-digit-pattern</value> |
542 | </entry> |
543 | @@ -1349,6 +1385,9 @@ |
544 | <entry key="NoOptDigitAfterMandatory"> |
545 | <value>"#": optional-digit-sign must precede all mandatory-digit-signs</value> |
546 | </entry> |
547 | + <entry key="NoPercentPermille"> |
548 | + <value>sub-picture must not contain more than one percent-sign or per-mille-sign or one of each</value> |
549 | + </entry> |
550 | </diagnostic> |
551 | |
552 | <diagnostic code="FODT0001"> |
553 | @@ -4363,30 +4402,6 @@ |
554 | <value>a DOCTYPE declaration must appear before any element or text node, and at most once</value> |
555 | </entry> |
556 | |
557 | - <entry key="FormatNumberDuplicates"> |
558 | - <value>: a sub-picture must not contain more than one of the "$3" sign</value> |
559 | - </entry> |
560 | - |
561 | - <entry key="FormatNumberGroupingAdjacentToDecimal"> |
562 | - <value>: a sub-picture must not contain a grouping-separator-sign adjacent to a decimal-separator-sign</value> |
563 | - </entry> |
564 | - |
565 | - <entry key="FormatNumberIntegerPart"> |
566 | - <value>: the integer part of a sub-picture must not contain a member of the decimal-digit-family that is followed by an optional-digit-sign</value> |
567 | - </entry> |
568 | - |
569 | - <entry key="FormatNumberFractionalPart"> |
570 | - <value>: the fractional part of a sub-picture must not contain an optional-digit-sign that is followed by a member of the decimal-digit-family</value> |
571 | - </entry> |
572 | - |
573 | - <entry key="FormatNumberPercentPermille"> |
574 | - <value>: a sub-picture must not contain more than one percent-sign or per-mille-sign, and it must not contain one of each</value> |
575 | - </entry> |
576 | - |
577 | - <entry key="FormatNumberAtLeastOneOptionalOrDecimal"> |
578 | - <value>: a sub-picture must contain at least one character that is an optional-digit-sign or a member of the decimal-digit-family</value> |
579 | - </entry> |
580 | - |
581 | <entry key="FUNCTION"> |
582 | <value>function</value> |
583 | </entry> |
584 | |
585 | === modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp' |
586 | --- src/diagnostics/pregenerated/diagnostic_list.cpp 2013-04-02 21:46:10 +0000 |
587 | +++ src/diagnostics/pregenerated/diagnostic_list.cpp 2013-04-11 17:02:25 +0000 |
588 | @@ -205,6 +205,9 @@ |
589 | XQueryErrorCode XQST0094( "XQST0094" ); |
590 | |
591 | |
592 | +XQueryErrorCode XQST0097( "XQST0097" ); |
593 | + |
594 | + |
595 | XQueryErrorCode XQST0098( "XQST0098" ); |
596 | |
597 | |
598 | @@ -220,6 +223,9 @@ |
599 | XQueryErrorCode XQST0111( "XQST0111" ); |
600 | |
601 | |
602 | +XQueryErrorCode XQST0114( "XQST0114" ); |
603 | + |
604 | + |
605 | XQueryErrorCode XQST0123( "XQST0123" ); |
606 | |
607 | |
608 | |
609 | === modified file 'src/diagnostics/pregenerated/dict_en.cpp' |
610 | --- src/diagnostics/pregenerated/dict_en.cpp 2013-04-08 22:59:58 +0000 |
611 | +++ src/diagnostics/pregenerated/dict_en.cpp 2013-04-11 17:02:25 +0000 |
612 | @@ -255,11 +255,13 @@ |
613 | { "XQST0090", "\"$1\": invalid character reference in XML $2" }, |
614 | { "XQST0093", "\"$1\": module must not depend on itself" }, |
615 | { "XQST0094", "\"$1\": grouping variable not defined in the same flwor expression as the group-by clause" }, |
616 | - { "XQST0098", "properties \"$1\" and \"$2\", representing characters used in picture string, do not have distinct values" }, |
617 | + { "XQST0097", "\"$1\": illegal value for decimal format property \"$2\"${: 3}" }, |
618 | + { "XQST0098", "\"$1\": value of properties \"$1\" and \"$2\" for characters used a in picture string is the same but must be distinct" }, |
619 | { "XQST0099", "module contains more than one context item declaration" }, |
620 | { "XQST0103", "$1: non-distinct variable in window clause" }, |
621 | { "XQST0106", "$1: multiple annotations with $2 names" }, |
622 | { "XQST0111", "$1" }, |
623 | + { "XQST0114", "\"$1\": duplicate decimal format property" }, |
624 | { "XQST0123", "$1" }, |
625 | { "XQTY0024", "element constructor content sequence must not have an attribute node following a non-attribute node" }, |
626 | { "XQTY0030", "validate argument must be exactly one document or element node" }, |
627 | @@ -623,10 +625,17 @@ |
628 | { "~FODF1310_DigitNotSameFamily_34", "\"$3\": digit not from same digit family as $4" }, |
629 | { "~FODF1310_DupFormatModifier_3", "\"$3\": duplicate format modifier" }, |
630 | { "~FODF1310_EmptyFormat", "empty primary format" }, |
631 | + { "~FODF1310_MultipleSign_3", "\"$3\": multiple such signs are illegal" }, |
632 | + { "~FODF1310_MustHaveOptOrMandatoryDigit", "sub-picture must contain at least one optional or mandatory digit" }, |
633 | + { "~FODF1310_NoActivePassiveActive", "\"$3\": active character may not follow passive that follows active" }, |
634 | { "~FODF1310_NoAdjacentGroupSep_3", "\"$3\": grouping separator must not be adjacent to others" }, |
635 | + { "~FODF1310_NoDecimalGroupingAdjacent_34", "decimal-separator-sign ('$3') and grouping-separator-sign ('$4') may not be adjacent" }, |
636 | { "~FODF1310_NoGroupSepAtEnd_3", "\"$3\": grouping separator illegal at end of decimal-digit-pattern" }, |
637 | { "~FODF1310_NoGroupSepAtStart_3", "\"$3\": grouping separator illegal at start of decimal-digit-pattern" }, |
638 | + { "~FODF1310_NoMandatoryDigitAfterOpt_3", "'$3': member of decimal-digit-family in fractional part of a sub-picture may not follow an optional-digit-sign" }, |
639 | { "~FODF1310_NoOptDigitAfterMandatory", "\"#\": optional-digit-sign must precede all mandatory-digit-signs" }, |
640 | + { "~FODF1310_NoOptDigitAfterMandatory_3", "'$3': optional-digit-sign in integer part of sub-picture may not follow a member of the decimal-digit-family" }, |
641 | + { "~FODF1310_NoPercentPermille", "sub-picture must not contain more than one percent-sign or per-mille-sign or one of each" }, |
642 | { "~FOFD1340_Bad2ndModifierHere_3", "'$3': valid second presentation modifier invalid here" }, |
643 | { "~FOFD1340_Bad2ndModifier_3", "'$3': invalid second presentation modifier" }, |
644 | { "~FOFD1340_BadComponent_3", "'$3': invalid component specifier" }, |
645 | @@ -659,12 +668,6 @@ |
646 | { "~FileNotFoundOrReadable", "file not found or readable" }, |
647 | { "~FnNilledArgNotNode", "fn:nilled() argument not a node" }, |
648 | { "~FnOnlyInXQueryVersion_3", "function only available in XQuery $3" }, |
649 | - { "~FormatNumberAtLeastOneOptionalOrDecimal", ": a sub-picture must contain at least one character that is an optional-digit-sign or a member of the decimal-digit-family" }, |
650 | - { "~FormatNumberDuplicates", ": a sub-picture must not contain more than one of the \"$3\" sign" }, |
651 | - { "~FormatNumberFractionalPart", ": the fractional part of a sub-picture must not contain an optional-digit-sign that is followed by a member of the decimal-digit-family" }, |
652 | - { "~FormatNumberGroupingAdjacentToDecimal", ": a sub-picture must not contain a grouping-separator-sign adjacent to a decimal-separator-sign" }, |
653 | - { "~FormatNumberIntegerPart", ": the integer part of a sub-picture must not contain a member of the decimal-digit-family that is followed by an optional-digit-sign" }, |
654 | - { "~FormatNumberPercentPermille", ": a sub-picture must not contain more than one percent-sign or per-mille-sign, and it must not contain one of each" }, |
655 | { "~FullTextNotEnabled", "full-text was not enabled in this build" }, |
656 | { "~FunctionFailedErrorCodeMessage_234", "$2 failed (error $3): $4" }, |
657 | { "~FunctionFailed_23o", "$2 failed${: 3}" }, |
658 | @@ -952,7 +955,6 @@ |
659 | { "~XPST0008_VariableName_2", "\"$2\": undeclared variable" }, |
660 | { "~XPST0051_Atomic_2", "\"$2\": not defined an atomic type" }, |
661 | { "~XPST0051_GenAtomic_2", "\"$2\": not defined a generalized atomic type" }, |
662 | - { "~XPTY0004_FormatNumber_2", "first parameter to format-number() function is type $2 that is not allowed" }, |
663 | { "~XPTY0004_JSONIQ_SELECTOR", "can not atomize and/or cast value of type $2 to string" }, |
664 | { "~XPTY0004_MultiValuedGroupingKey", "atomization of grouping variable produces more than one item" }, |
665 | { "~XPTY0004_NoMultiSeqTypePromotion_2", "sequence of more than one item can not be promoted to type $2" }, |
666 | @@ -970,6 +972,8 @@ |
667 | { "~XQST0046_BadHexDigit_3", "'$3': invalid hexedecimal digit" }, |
668 | { "~XQST0059_SpecificationMessage", "\"$2\": target namespace not found for schema/module${ \"3\"}${: 4}" }, |
669 | { "~XQST0059_XercesMessage", "$2,$3: error in schema${ with System ID \"4\"}${ with Public ID \"5\"}${: 6}" }, |
670 | + { "~XQST0097_MustBeChar", "must be a single character" }, |
671 | + { "~XQST0097_MustBeZeroDigit", "must be a digit (Unicode category Nd) and represent zero" }, |
672 | { "~XQST0106_CONFLICTING", "conflicting" }, |
673 | { "~XQST0106_THE_SAME", "the same" }, |
674 | { "~XUDY0021_AttributeName", "\"$3\": attribute with the same name already exists" }, |
675 | |
676 | === modified file 'src/diagnostics/pregenerated/dict_zed_keys.h' |
677 | --- src/diagnostics/pregenerated/dict_zed_keys.h 2013-04-08 22:59:58 +0000 |
678 | +++ src/diagnostics/pregenerated/dict_zed_keys.h 2013-04-11 17:02:25 +0000 |
679 | @@ -45,7 +45,6 @@ |
680 | #define ZED_XPTY0004_NoTypePromote_23 "~XPTY0004_NoTypePromote_23" |
681 | #define ZED_XPTY0004_NoMultiSeqTypePromotion_2 "~XPTY0004_NoMultiSeqTypePromotion_2" |
682 | #define ZED_XPTY0004_NoTreatAs_23 "~XPTY0004_NoTreatAs_23" |
683 | -#define ZED_XPTY0004_FormatNumber_2 "~XPTY0004_FormatNumber_2" |
684 | #define ZED_XPTY0004_JSONIQ_SELECTOR "~XPTY0004_JSONIQ_SELECTOR" |
685 | #define ZED_XPTY0004_MultiValuedGroupingKey "~XPTY0004_MultiValuedGroupingKey" |
686 | #define ZED_XPTY0117_NodeCast "~XPTY0117_NodeCast" |
687 | @@ -53,6 +52,8 @@ |
688 | #define ZED_XQST0046_BadHexDigit_3 "~XQST0046_BadHexDigit_3" |
689 | #define ZED_XQST0059_SpecificationMessage "~XQST0059_SpecificationMessage" |
690 | #define ZED_XQST0059_XercesMessage "~XQST0059_XercesMessage" |
691 | +#define ZED_XQST0097_MustBeChar "~XQST0097_MustBeChar" |
692 | +#define ZED_XQST0097_MustBeZeroDigit "~XQST0097_MustBeZeroDigit" |
693 | #define ZED_XQST0106_THE_SAME "~XQST0106_THE_SAME" |
694 | #define ZED_XQST0106_CONFLICTING "~XQST0106_CONFLICTING" |
695 | #define ZED_XPDY0002_VariableHasNoValue_2 "~XPDY0002_VariableHasNoValue_2" |
696 | @@ -83,16 +84,23 @@ |
697 | #define ZED_FOCA0002_BadLexicalQName_2 "~FOCA0002_BadLexicalQName_2" |
698 | #define ZED_FOCA0002_NoURIforPrefix_2 "~FOCA0002_NoURIforPrefix_2" |
699 | #define ZED_FOCA0002_NoCastTo_234 "~FOCA0002_NoCastTo_234" |
700 | +#define ZED_FODF1310_NoOptDigitAfterMandatory_3 "~FODF1310_NoOptDigitAfterMandatory_3" |
701 | +#define ZED_FODF1310_NoMandatoryDigitAfterOpt_3 "~FODF1310_NoMandatoryDigitAfterOpt_3" |
702 | #define ZED_FODF1310_BadCharacter_3 "~FODF1310_BadCharacter_3" |
703 | #define ZED_FODF1310_BadFormatModifier_3 "~FODF1310_BadFormatModifier_3" |
704 | #define ZED_FODF1310_BadFormatModifierHere_3 "~FODF1310_BadFormatModifierHere_3" |
705 | #define ZED_FODF1310_DigitNotSameFamily_34 "~FODF1310_DigitNotSameFamily_34" |
706 | #define ZED_FODF1310_DupFormatModifier_3 "~FODF1310_DupFormatModifier_3" |
707 | #define ZED_FODF1310_EmptyFormat "~FODF1310_EmptyFormat" |
708 | +#define ZED_FODF1310_MultipleSign_3 "~FODF1310_MultipleSign_3" |
709 | +#define ZED_FODF1310_MustHaveOptOrMandatoryDigit "~FODF1310_MustHaveOptOrMandatoryDigit" |
710 | +#define ZED_FODF1310_NoActivePassiveActive "~FODF1310_NoActivePassiveActive" |
711 | #define ZED_FODF1310_NoAdjacentGroupSep_3 "~FODF1310_NoAdjacentGroupSep_3" |
712 | +#define ZED_FODF1310_NoDecimalGroupingAdjacent_34 "~FODF1310_NoDecimalGroupingAdjacent_34" |
713 | #define ZED_FODF1310_NoGroupSepAtStart_3 "~FODF1310_NoGroupSepAtStart_3" |
714 | #define ZED_FODF1310_NoGroupSepAtEnd_3 "~FODF1310_NoGroupSepAtEnd_3" |
715 | #define ZED_FODF1310_NoOptDigitAfterMandatory "~FODF1310_NoOptDigitAfterMandatory" |
716 | +#define ZED_FODF1310_NoPercentPermille "~FODF1310_NoPercentPermille" |
717 | #define ZED_FORG0001_BadHexDigit_2 "~FORG0001_BadHexDigit_2" |
718 | #define ZED_FORG0001_Base64BadChar_2 "~FORG0001_Base64BadChar_2" |
719 | #define ZED_FORG0001_Base64Multiple4 "~FORG0001_Base64Multiple4" |
720 | @@ -363,12 +371,6 @@ |
721 | #define ZED_ParseFragmentInvalidOptions "~ParseFragmentInvalidOptions" |
722 | #define ZED_ParseFragmentDoctypeNotAllowed "~ParseFragmentDoctypeNotAllowed" |
723 | #define ZED_ParseFragmentDoctypeNotAllowedHere "~ParseFragmentDoctypeNotAllowedHere" |
724 | -#define ZED_FormatNumberDuplicates "~FormatNumberDuplicates" |
725 | -#define ZED_FormatNumberGroupingAdjacentToDecimal "~FormatNumberGroupingAdjacentToDecimal" |
726 | -#define ZED_FormatNumberIntegerPart "~FormatNumberIntegerPart" |
727 | -#define ZED_FormatNumberFractionalPart "~FormatNumberFractionalPart" |
728 | -#define ZED_FormatNumberPercentPermille "~FormatNumberPercentPermille" |
729 | -#define ZED_FormatNumberAtLeastOneOptionalOrDecimal "~FormatNumberAtLeastOneOptionalOrDecimal" |
730 | #define ZED_FUNCTION "~FUNCTION" |
731 | #define ZED_ANNOTATION "~ANNOTATION" |
732 | #define ZED_libxml_ERR_1 "~libxml_ERR_1" |
733 | |
734 | === modified file 'src/runtime/CMakeLists.txt' |
735 | --- src/runtime/CMakeLists.txt 2013-03-28 20:00:55 +0000 |
736 | +++ src/runtime/CMakeLists.txt 2013-04-11 17:02:25 +0000 |
737 | @@ -133,6 +133,7 @@ |
738 | json/snelson.cpp |
739 | numerics/NumericsImpl.cpp |
740 | numerics/format_integer.cpp |
741 | + numerics/format_number.cpp |
742 | sequences/SequencesImpl.cpp |
743 | visitors/iterprinter.cpp |
744 | update/update.cpp |
745 | |
746 | === modified file 'src/runtime/numerics/format_integer.cpp' |
747 | --- src/runtime/numerics/format_integer.cpp 2013-04-07 17:56:27 +0000 |
748 | +++ src/runtime/numerics/format_integer.cpp 2013-04-11 17:02:25 +0000 |
749 | @@ -43,6 +43,8 @@ |
750 | |
751 | /////////////////////////////////////////////////////////////////////////////// |
752 | |
753 | +namespace { |
754 | + |
755 | struct picture { |
756 | enum primary_type { |
757 | arabic, // '1' : 0 1 2 ... 10 11 12 ... |
758 | @@ -105,6 +107,8 @@ |
759 | // default picture& operator=(picture const&) is fine |
760 | }; |
761 | |
762 | +} // namespace |
763 | + |
764 | /////////////////////////////////////////////////////////////////////////////// |
765 | |
766 | /** |
767 | @@ -246,7 +250,8 @@ |
768 | } else { // must be a grouping-separator |
769 | grouping_cp = pic_cp; // remember for later |
770 | u_dest.insert( 0, 1, grouping_cp ); |
771 | - --mandatory_grouping_seps; |
772 | + if ( mandatory_grouping_seps ) |
773 | + --mandatory_grouping_seps; |
774 | } |
775 | } else { // have exhausted the picture |
776 | if ( pic.primary.grouping_interval && |
777 | @@ -361,7 +366,7 @@ |
778 | QueryLoc const &loc ) { |
779 | if ( picture_str.empty() ) { |
780 | // |
781 | - // XQuery 3.0 F&O: 4.6.1: The primary format token is always present and |
782 | + // XQuery 3.0 F&O 4.6.1: The primary format token is always present and |
783 | // must not be zero-length. |
784 | // |
785 | empty_format: |
786 | @@ -443,8 +448,8 @@ |
787 | if ( is_decimal_digit_pattern ) { |
788 | if ( cp != '#' && unicode::is_grouping_separator( cp ) ) { |
789 | // |
790 | - // Ibid: 4.6.1: A grouping-separator-sign must not appear at the start |
791 | - // ... of the decimal-digit-pattern .... |
792 | + // Ibid 4.6.1: A grouping-separator-sign must not appear at the start ... |
793 | + // of the decimal-digit-pattern .... |
794 | // |
795 | throw XQUERY_EXCEPTION( |
796 | err::FODF1310, |
797 | @@ -809,9 +814,9 @@ |
798 | |
799 | if ( !lang ) { |
800 | // |
801 | - // XQuery 3.0 F&O: 4.6.1: If the $lang argument is absent, or is set to |
802 | - // an empty sequence, or is invalid, or is not a language supported by |
803 | - // the implementation, then the number is formatted using the default |
804 | + // XQuery 3.0 F&O 4.6.1: If the $lang argument is absent, or is set to an |
805 | + // empty sequence, or is invalid, or is not a language supported by the |
806 | + // implementation, then the number is formatted using the default |
807 | // language from the dynamic context. |
808 | // |
809 | planState.theLocalDynCtx->get_locale( &lang, &country ); |
810 | |
811 | === added file 'src/runtime/numerics/format_number.cpp' |
812 | --- src/runtime/numerics/format_number.cpp 1970-01-01 00:00:00 +0000 |
813 | +++ src/runtime/numerics/format_number.cpp 2013-04-11 17:02:25 +0000 |
814 | @@ -0,0 +1,847 @@ |
815 | +/* |
816 | + * Copyright 2006-2008 The FLWOR Foundation. |
817 | + * |
818 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
819 | + * you may not use this file except in compliance with the License. |
820 | + * You may obtain a copy of the License at |
821 | + * |
822 | + * http://www.apache.org/licenses/LICENSE-2.0 |
823 | + * |
824 | + * Unless required by applicable law or agreed to in writing, software |
825 | + * distributed under the License is distributed on an "AS IS" BASIS, |
826 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
827 | + * See the License for the specific language governing permissions and |
828 | + * limitations under the License. |
829 | + */ |
830 | +#include "stdafx.h" |
831 | + |
832 | +#include <vector> |
833 | + |
834 | +#include "common/shared_types.h" |
835 | +#include "compiler/api/compilercb.h" |
836 | +#include "context/static_context.h" |
837 | +#include "diagnostics/xquery_diagnostics.h" |
838 | +#include "runtime/core/arithmetic_impl.h" |
839 | +#include "runtime/numerics/numerics.h" |
840 | +#include "runtime/visitors/planiter_visitor.h" |
841 | +#include "store/api/item.h" |
842 | +#include "store/api/item_factory.h" |
843 | +#include "system/globalenv.h" |
844 | +#include "types/casting.h" |
845 | +#include "types/typeconstants.h" |
846 | +#include "types/typeops.h" |
847 | +#include "util/xml_util.h" |
848 | +#include "zorbatypes/zorbatypes_decl.h" |
849 | + |
850 | +namespace zorba { |
851 | + |
852 | +/////////////////////////////////////////////////////////////////////////////// |
853 | + |
854 | +namespace { |
855 | + |
856 | +struct picture { |
857 | + |
858 | + struct part { |
859 | + zstring format; |
860 | + int mandatory_grouping_seps; |
861 | + int minimum_size; |
862 | + union { |
863 | + int grouping_interval; // only in integer part |
864 | + int maximum_size; // only in fractional part |
865 | + }; |
866 | + |
867 | + part() { |
868 | + mandatory_grouping_seps = minimum_size = maximum_size = 0; |
869 | + } |
870 | + }; |
871 | + |
872 | + struct sub_picture { |
873 | + zstring format; |
874 | + zstring prefix, suffix; |
875 | + bool has_decimal_separator; |
876 | + bool has_percent; |
877 | + bool has_per_mille; |
878 | + part integer_part, fractional_part; |
879 | + |
880 | + sub_picture() { |
881 | + has_decimal_separator = has_percent = has_per_mille = false; |
882 | + } |
883 | + }; |
884 | + |
885 | + zstring format; // original $picture |
886 | + sub_picture pos_subpicture, neg_subpicture; |
887 | + |
888 | + // See XQuery F&O 3.0 4.7.1. |
889 | + enum var_type { |
890 | + decimal_separator_sign, |
891 | + grouping_separator_sign, |
892 | + infinity, |
893 | + mandatory_digit_sign, |
894 | + minus_sign, |
895 | + NaN, |
896 | + optional_digit_sign, |
897 | + pattern_separator_sign, |
898 | + percent_sign, |
899 | + per_mille_sign, |
900 | + NUM_VARS |
901 | + }; |
902 | + |
903 | + zstring var[ NUM_VARS ]; |
904 | + unicode::code_point var_cp[ NUM_VARS ]; |
905 | + |
906 | + picture() { |
907 | + var[ decimal_separator_sign ] = "."; |
908 | + var[ grouping_separator_sign ] = ","; |
909 | + var[ infinity ] = "Infinity"; |
910 | + var[ mandatory_digit_sign ] = "0"; |
911 | + var[ minus_sign ] = "-"; |
912 | + var[ NaN ] = "NaN"; |
913 | + var[ optional_digit_sign ] = "#"; |
914 | + var[ pattern_separator_sign ] = ";"; |
915 | + var[ percent_sign ] = "%"; |
916 | + var[ per_mille_sign ] = "\xE2\x80\xB0"; |
917 | + set_format_codepoints(); |
918 | + } |
919 | + |
920 | + // default picture(picture const&) is fine |
921 | + // default picture& operator=(picture const&) is fine |
922 | + |
923 | + void set_format_codepoints() { |
924 | + for ( int i = 0; i < NUM_VARS; ++i ) |
925 | + var_cp[i] = utf8::decode( var[i].c_str() ); |
926 | + } |
927 | +}; |
928 | + |
929 | +} // namespace |
930 | + |
931 | +#define VAR(NAME) var[ ::zorba::picture::NAME ] |
932 | +#define VAR_CP(NAME) var_cp[ ::zorba::picture::NAME ] |
933 | + |
934 | +/////////////////////////////////////////////////////////////////////////////// |
935 | + |
936 | +static void check_multiple( zstring const &sub_pic, zstring const &sign, |
937 | + picture const &pic, QueryLoc const &loc ) { |
938 | + zstring::size_type const pos = sub_pic.find( sign ); |
939 | + if ( pos != zstring::npos && |
940 | + sub_pic.find( sign, pos + sign.size() ) != zstring::npos ) { |
941 | + throw XQUERY_EXCEPTION( |
942 | + err::FODF1310, |
943 | + ERROR_PARAMS( pic.format, ZED( FODF1310_MultipleSign_3 ), sign ), |
944 | + ERROR_LOC( loc ) |
945 | + ); |
946 | + } |
947 | +} |
948 | + |
949 | +static void format_integer_part( zstring const &value, |
950 | + picture::sub_picture const &sub_pic, |
951 | + picture const &pic, zstring *dest ) { |
952 | + zstring::const_reverse_iterator n_i( value.rbegin() ); |
953 | + zstring::const_reverse_iterator const n_end( value.rend() ); |
954 | + |
955 | + picture::part const &part = sub_pic.integer_part; |
956 | + |
957 | + utf8_string<zstring const> const u_format( part.format ); |
958 | + utf8_string<zstring const>::const_reverse_iterator |
959 | + format_i( u_format.rbegin() ); |
960 | + utf8_string<zstring const>::const_reverse_iterator const |
961 | + format_end( u_format.rend() ); |
962 | + |
963 | + int digit_pos = 0; |
964 | + bool just_inserted_grouping_separator = false; |
965 | + int minimum_size = part.minimum_size; |
966 | + int mandatory_grouping_seps = part.mandatory_grouping_seps; |
967 | + utf8_string<zstring> u_dest( *dest ); |
968 | + |
969 | + // |
970 | + // Step through both the integer part and sub-picture from right-to-left. |
971 | + // |
972 | + while ( n_i != n_end || format_i != format_end ) { |
973 | + unicode::code_point digit_cp = pic.VAR_CP( mandatory_digit_sign ); |
974 | + if ( n_i != n_end ) |
975 | + digit_cp += *n_i - '0'; |
976 | + if ( format_i != format_end ) { // haven't exhausted the picture |
977 | + if ( !minimum_size && !mandatory_grouping_seps && n_i == n_end ) |
978 | + break; |
979 | + unicode::code_point const format_cp = *format_i++; |
980 | + if ( format_cp == pic.VAR_CP( optional_digit_sign ) || |
981 | + unicode::is_Nd( format_cp ) ) { |
982 | + u_dest.insert( 0, 1, digit_cp ); |
983 | + if ( n_i != n_end ) ++n_i; |
984 | + ++digit_pos; |
985 | + just_inserted_grouping_separator = false; |
986 | + if ( minimum_size ) |
987 | + --minimum_size; |
988 | + } else { // must be a grouping-separator |
989 | + u_dest.insert( 0, 1, pic.VAR_CP( grouping_separator_sign ) ); |
990 | + just_inserted_grouping_separator = true; |
991 | + if ( mandatory_grouping_seps ) |
992 | + --mandatory_grouping_seps; |
993 | + } |
994 | + } else { // have exhausted the picture |
995 | + if ( part.grouping_interval && !(digit_pos % part.grouping_interval) ) { |
996 | + if ( just_inserted_grouping_separator ) |
997 | + just_inserted_grouping_separator = false; |
998 | + else { |
999 | + u_dest.insert( 0, 1, pic.VAR_CP( grouping_separator_sign ) ); |
1000 | + just_inserted_grouping_separator = true; |
1001 | + continue; |
1002 | + } |
1003 | + } |
1004 | + u_dest.insert( 0, 1, digit_cp ); |
1005 | + if ( n_i != n_end ) ++n_i; |
1006 | + ++digit_pos; |
1007 | + } |
1008 | + } // while |
1009 | +} |
1010 | + |
1011 | +static void format_fractional_part( zstring const &value, |
1012 | + picture::sub_picture const &sub_pic, |
1013 | + picture const &pic, zstring *dest ) { |
1014 | + zstring::const_iterator n_i( value.begin() ); |
1015 | + zstring::const_iterator const n_end( value.end() ); |
1016 | + |
1017 | + picture::part const &part = sub_pic.fractional_part; |
1018 | + |
1019 | + utf8_string<zstring const> const u_format( part.format ); |
1020 | + utf8_string<zstring const>::const_iterator format_i( u_format.begin() ); |
1021 | + utf8_string<zstring const>::const_iterator const format_end( u_format.end() ); |
1022 | + |
1023 | + int minumum_size = part.minimum_size; |
1024 | + int mandatory_grouping_seps = part.mandatory_grouping_seps; |
1025 | + utf8_string<zstring> u_dest( *dest ); |
1026 | + |
1027 | + // |
1028 | + // Step through both the fractional part and sub-picture from left-to-right. |
1029 | + // |
1030 | + while ( n_i != n_end || format_i != format_end ) { |
1031 | + unicode::code_point digit_cp = pic.VAR_CP( mandatory_digit_sign ); |
1032 | + if ( n_i != n_end ) |
1033 | + digit_cp += *n_i - '0'; |
1034 | + if ( format_i != format_end ) { // haven't exhausted the picture |
1035 | + if ( !minumum_size && !mandatory_grouping_seps && n_i == n_end ) |
1036 | + break; |
1037 | + unicode::code_point const format_cp = *format_i++; |
1038 | + if ( format_cp == pic.VAR_CP( optional_digit_sign ) || |
1039 | + unicode::is_Nd( format_cp ) ) { |
1040 | + u_dest += digit_cp; |
1041 | + if ( n_i != n_end ) ++n_i; |
1042 | + if ( minumum_size ) |
1043 | + --minumum_size; |
1044 | + } else { // must be a grouping-separator |
1045 | + u_dest += pic.VAR_CP( grouping_separator_sign ); |
1046 | + if ( mandatory_grouping_seps ) |
1047 | + --mandatory_grouping_seps; |
1048 | + } |
1049 | + } else { // have exhausted the picture |
1050 | + u_dest += digit_cp; |
1051 | + if ( n_i != n_end ) ++n_i; |
1052 | + } |
1053 | + } // while |
1054 | +} |
1055 | + |
1056 | +static void format_number( store::Item_t &number_item, picture const &pic, |
1057 | + TypeManager const *tm, QueryLoc const &loc, |
1058 | + zstring *dest ) { |
1059 | + if ( number_item->isNaN() ) { |
1060 | + // |
1061 | + // XQuery F&O 3.0 4.7.5: If the input number is NaN (not a number), the |
1062 | + // result is the specified NaN-symbol (with no prefix or suffix). |
1063 | + // |
1064 | + *dest = pic.VAR( NaN ); |
1065 | + return; |
1066 | + } |
1067 | + |
1068 | + store::Item_t double_item; |
1069 | + GenericCast::castToAtomic( |
1070 | + double_item, number_item, &*GENV_TYPESYSTEM.DOUBLE_TYPE_ONE, tm, nullptr, |
1071 | + loc |
1072 | + ); |
1073 | + |
1074 | + store::Item_t zero; |
1075 | + GENV_ITEMFACTORY->createDouble( zero, xs_double::zero() ); |
1076 | + |
1077 | + // |
1078 | + // Ibid: [T]he positive sub-picture and its associated variables are used if |
1079 | + // the input number is positive, and the negative sub-picture and its |
1080 | + // associated variables are used otherwise. |
1081 | + // |
1082 | + bool const is_negative = double_item->compare( zero ) < 0; |
1083 | + picture::sub_picture const &sub_pic = |
1084 | + is_negative ? pic.neg_subpicture : pic.pos_subpicture; |
1085 | + |
1086 | + if ( double_item->isPosOrNegInf() ) { |
1087 | + // |
1088 | + // Ibid: If the input number is positive or negative infinity, the result |
1089 | + // is the concatenation of the appropriate prefix, the infinity-symbol, and |
1090 | + // the appropriate suffix. |
1091 | + // |
1092 | + *dest = sub_pic.prefix; |
1093 | + *dest += pic.VAR( infinity ); |
1094 | + *dest += sub_pic.suffix; |
1095 | + return; |
1096 | + } |
1097 | + |
1098 | + // |
1099 | + // Ibid: If the sub-picture contains a percent-sign, the number is multiplied |
1100 | + // by 100. If the sub-picture contains a per-mille-sign, the number is |
1101 | + // multiplied by 1000. The resulting number is referred to ... as the |
1102 | + // adjusted number. |
1103 | + // |
1104 | + xs_double adjusted_number( double_item->getDoubleValue().abs() ); |
1105 | + if ( sub_pic.has_percent ) |
1106 | + adjusted_number *= 100; |
1107 | + else if ( sub_pic.has_per_mille ) |
1108 | + adjusted_number *= 1000; |
1109 | + |
1110 | + // |
1111 | + // Ibid: This value is then rounded so that it uses no more than maximum- |
1112 | + // fractional-part-size digits in its fractional part. The rounded number is |
1113 | + // defined to be the result of converting the adjusted number to an |
1114 | + // xs:decimal value, as described above, and then calling the function |
1115 | + // fn:round-half-to-even with this converted number as the first argument and |
1116 | + // the maximum-fractional-part-size as the second argument. |
1117 | + // |
1118 | + adjusted_number = adjusted_number.roundHalfToEven( |
1119 | + xs_integer( sub_pic.fractional_part.maximum_size ) |
1120 | + ); |
1121 | + |
1122 | + // |
1123 | + // Ibid: If the number of digits to the left of the decimal-separator-sign is |
1124 | + // less than minimum-integer-part-size, leading zero-digit-sign characters |
1125 | + // are added to pad out to that size. |
1126 | + // |
1127 | + // Ibid: If the number of digits to the right of the decimal-separator-sign |
1128 | + // is less than minimum-fractional-part-size, trailing zero-digit-sign |
1129 | + // characters are added to pad out to that size. |
1130 | + // |
1131 | + zstring const number_str( adjusted_number.toString( true ) ); |
1132 | + zstring::size_type const decimal_separator_pos = number_str.find( '.' ); |
1133 | + zstring integer_str, fractional_str; |
1134 | + integer_str = number_str.substr( 0, decimal_separator_pos ); |
1135 | + ascii::left_pad( &integer_str, sub_pic.integer_part.minimum_size, '0' ); |
1136 | + if ( decimal_separator_pos != zstring::npos ) |
1137 | + fractional_str = number_str.substr( decimal_separator_pos + 1 ); |
1138 | + ascii::right_pad( |
1139 | + &fractional_str, sub_pic.fractional_part.minimum_size, '0' |
1140 | + ); |
1141 | + |
1142 | + format_integer_part( integer_str, sub_pic, pic, dest ); |
1143 | + // Insert prefix afterwards so as not to complicate format_integer_part(). |
1144 | + dest->insert( 0, sub_pic.prefix ); |
1145 | + |
1146 | + if ( sub_pic.has_decimal_separator && !fractional_str.empty() ) { |
1147 | + *dest += pic.VAR( decimal_separator_sign ); |
1148 | + format_fractional_part( fractional_str, sub_pic, pic, dest ); |
1149 | + } |
1150 | + *dest += sub_pic.suffix; |
1151 | +} |
1152 | + |
1153 | +static bool is_allowed_type( store::Item const *type_qname ) { |
1154 | + RootTypeManager const &rtm = GENV_TYPESYSTEM; |
1155 | + return type_qname->equals( rtm.XS_FLOAT_QNAME ) |
1156 | + || type_qname->equals( rtm.XS_DOUBLE_QNAME ) |
1157 | + || type_qname->equals( rtm.XS_DECIMAL_QNAME ) |
1158 | + || type_qname->equals( rtm.XS_INTEGER_QNAME ) |
1159 | + || type_qname->equals( rtm.XS_INT_QNAME ) |
1160 | + || type_qname->equals( rtm.XS_LONG_QNAME ) |
1161 | + || type_qname->equals( rtm.XS_SHORT_QNAME ) |
1162 | + || type_qname->equals( rtm.XS_BYTE_QNAME ) |
1163 | + || type_qname->equals( rtm.XS_NON_NEGATIVE_INTEGER_QNAME ) |
1164 | + || type_qname->equals( rtm.XS_NON_POSITIVE_INTEGER_QNAME ) |
1165 | + || type_qname->equals( rtm.XS_NEGATIVE_INTEGER_QNAME ) |
1166 | + || type_qname->equals( rtm.XS_POSITIVE_INTEGER_QNAME ) |
1167 | + || type_qname->equals( rtm.XS_UNSIGNED_INT_QNAME ) |
1168 | + || type_qname->equals( rtm.XS_UNSIGNED_LONG_QNAME ) |
1169 | + || type_qname->equals( rtm.XS_UNSIGNED_SHORT_QNAME ) |
1170 | + || type_qname->equals( rtm.XS_UNSIGNED_BYTE_QNAME ); |
1171 | +} |
1172 | + |
1173 | +static void parse_subpicture( picture::sub_picture *sub_pic, |
1174 | + picture const &pic, QueryLoc const &loc ) { |
1175 | + if ( sub_pic->format.empty() ) |
1176 | + return; |
1177 | + |
1178 | + picture::part picture::sub_picture::*cur_part = |
1179 | + &picture::sub_picture::integer_part; |
1180 | + |
1181 | + bool got_active = false; |
1182 | + bool got_grouping_separator = false; // used only for integer part |
1183 | + bool got_mandatory_digit = false; |
1184 | + bool got_optional_digit = false; |
1185 | + bool got_part_mandatory_digit = false; |
1186 | + bool got_part_optional_digit = false; |
1187 | + bool got_passive_after_active = false; |
1188 | + bool grouping_interval_possible = true; // used only for integer part |
1189 | + bool just_got_decimal_separator = false; |
1190 | + bool just_got_grouping_separator = false; |
1191 | + |
1192 | + int grouping_interval = 0; // used only for integer part |
1193 | + int grouping_separators = 0; |
1194 | + |
1195 | + utf8::size_type decimal_separator_pos = utf8::npos; |
1196 | + utf8::size_type leftmost_active_pos = utf8::npos; |
1197 | + utf8::size_type rightmost_active_pos = utf8::npos; |
1198 | + utf8::size_type pos = 0; |
1199 | + utf8::size_type prev_grouping_pos = utf8::npos; |
1200 | + |
1201 | + unicode::code_point cp, zero_cp; |
1202 | + |
1203 | + utf8_string<zstring> u_format( sub_pic->format ); |
1204 | + utf8_string<zstring>::const_iterator u( u_format.begin() ); |
1205 | + utf8_string<zstring>::const_iterator const u_end( u_format.end() ); |
1206 | + |
1207 | + for ( ; u != u_end; ++u, ++pos ) { |
1208 | + cp = *u; |
1209 | + |
1210 | + if ( cp == pic.VAR_CP( decimal_separator_sign ) ) { |
1211 | + if ( decimal_separator_pos != utf8::npos ) { |
1212 | + // |
1213 | + // XQuery F&O 3.0 4.7.3: A sub-picture must not contain more than one |
1214 | + // decimal-separator-sign. |
1215 | + // |
1216 | + goto got_multiple_signs; |
1217 | + } |
1218 | + if ( just_got_grouping_separator ) { |
1219 | + // |
1220 | + // Ibid: A sub-picture must not contain a grouping-separator-sign |
1221 | + // adjacent to a decimal-separator-sign. |
1222 | + // |
1223 | + goto got_decimal_grouping_adjacent; |
1224 | + } |
1225 | + cur_part = &picture::sub_picture::fractional_part; |
1226 | + decimal_separator_pos = pos; |
1227 | + got_part_mandatory_digit = got_part_optional_digit = false; |
1228 | + just_got_decimal_separator = true; |
1229 | + just_got_grouping_separator = false; |
1230 | + sub_pic->has_decimal_separator = true; |
1231 | + goto set_active; |
1232 | + } |
1233 | + |
1234 | + if ( cp == pic.VAR_CP( grouping_separator_sign ) ) { |
1235 | + if ( just_got_decimal_separator ) { |
1236 | + // |
1237 | + // Ibid: A sub-picture must not contain a grouping-separator-sign |
1238 | + // adjacent to a decimal-separator-sign. |
1239 | + // |
1240 | + goto got_decimal_grouping_adjacent; |
1241 | + } |
1242 | + just_got_decimal_separator = false; |
1243 | + just_got_grouping_separator = true; |
1244 | + ++grouping_separators; |
1245 | + |
1246 | + if ( decimal_separator_pos == utf8::npos && |
1247 | + grouping_interval_possible ) { |
1248 | + // |
1249 | + // [I]f these integer-part-grouping-positions are at regular intervals |
1250 | + // (that is, if they form a sequence N, 2N, 3N, ... for some integer |
1251 | + // value N, including the case where there is only one number in the |
1252 | + // list), then the sequence contains all integer multiples of N as far |
1253 | + // as necessary to accommodate the largest possible number. |
1254 | + // |
1255 | + if ( !got_grouping_separator ) |
1256 | + got_grouping_separator = true; |
1257 | + else if ( !grouping_interval ) |
1258 | + grouping_interval = pos - prev_grouping_pos; |
1259 | + else if ( pos - prev_grouping_pos != grouping_interval ) |
1260 | + grouping_interval_possible = false; |
1261 | + prev_grouping_pos = pos + 1; |
1262 | + } |
1263 | + |
1264 | + goto set_active; |
1265 | + } |
1266 | + |
1267 | + just_got_decimal_separator = just_got_grouping_separator = false; |
1268 | + |
1269 | + if ( cp == pic.VAR_CP( optional_digit_sign ) ) { |
1270 | + if ( decimal_separator_pos != utf8::npos ) { |
1271 | + // |
1272 | + // Ibid 4.7.4: The maximum-fractional-part-size is set to the total |
1273 | + // number of optional-digit-sign and decimal-digit-family characters |
1274 | + // found in the fractional part of the sub-picture. |
1275 | + // |
1276 | + ++sub_pic->fractional_part.maximum_size; |
1277 | + } else if ( got_part_mandatory_digit ) { |
1278 | + // |
1279 | + // Ibid 4.7.3: The integer part of a sub-picture must not contain a |
1280 | + // member of the decimal-digit-family that is followed by an optional- |
1281 | + // digit-sign. |
1282 | + // |
1283 | + throw XQUERY_EXCEPTION( |
1284 | + err::FODF1310, |
1285 | + ERROR_PARAMS( |
1286 | + pic.format, |
1287 | + ZED( FODF1310_NoOptDigitAfterMandatory_3 ), |
1288 | + unicode::printable_cp( cp ) |
1289 | + ), |
1290 | + ERROR_LOC( loc ) |
1291 | + ); |
1292 | + } |
1293 | + got_optional_digit = got_part_optional_digit = true; |
1294 | + goto set_active; |
1295 | + } |
1296 | + |
1297 | + if ( cp == pic.VAR_CP( percent_sign ) ) { |
1298 | + // |
1299 | + // Ibid 4.7.3: A sub-picture must not contain more than one percent-sign |
1300 | + // or per-mille-sign, and it must not contain one of each. |
1301 | + // |
1302 | + if ( sub_pic->has_percent ) |
1303 | + goto got_multiple_signs; |
1304 | + if ( sub_pic->has_per_mille ) |
1305 | + goto got_percent_per_mille; |
1306 | + sub_pic->has_percent = true; |
1307 | + } |
1308 | + |
1309 | + else if ( cp == pic.VAR_CP( per_mille_sign ) ) { |
1310 | + // |
1311 | + // Ibid: A sub-picture must not contain more than one percent-sign or |
1312 | + // per-mille-sign, and it must not contain one of each. |
1313 | + // |
1314 | + if ( sub_pic->has_per_mille ) |
1315 | + goto got_multiple_signs; |
1316 | + if ( sub_pic->has_percent ) |
1317 | + goto got_percent_per_mille; |
1318 | + sub_pic->has_per_mille = true; |
1319 | + } |
1320 | + |
1321 | + else if ( unicode::is_Nd( cp, &zero_cp ) && |
1322 | + zero_cp == pic.VAR_CP( mandatory_digit_sign ) ) { |
1323 | + if ( decimal_separator_pos != utf8::npos ) { |
1324 | + if ( got_part_optional_digit ) { |
1325 | + // |
1326 | + // Ibid: The fractional part of a sub-picture must not contain an |
1327 | + // optional-digit-sign that is followed by a member of the decimal- |
1328 | + // digit-family. |
1329 | + // |
1330 | + throw XQUERY_EXCEPTION( |
1331 | + err::FODF1310, |
1332 | + ERROR_PARAMS( |
1333 | + pic.format, |
1334 | + ZED( FODF1310_NoMandatoryDigitAfterOpt_3 ), |
1335 | + unicode::printable_cp( cp ) |
1336 | + ), |
1337 | + ERROR_LOC( loc ) |
1338 | + ); |
1339 | + } |
1340 | + // |
1341 | + // Ibid 4.7.4: The maximum-fractional-part-size is set to the total |
1342 | + // number of optional-digit-sign and decimal-digit-family characters |
1343 | + // found in the fractional part of the sub-picture. |
1344 | + // |
1345 | + ++sub_pic->fractional_part.maximum_size; |
1346 | + } |
1347 | + got_mandatory_digit = got_part_mandatory_digit = true; |
1348 | + |
1349 | + // |
1350 | + // Ibid 4.7.4: The minimum-integer-part-size is an integer indicating the |
1351 | + // minimum number of digits that will appear to the left of the decimal- |
1352 | + // separator-sign. It is normally set to the number of decimal-digit- |
1353 | + // family characters found in the integer part of the sub-picture. |
1354 | + // |
1355 | + // Ibid: The minimum-fractional-part-size is set to the number of |
1356 | + // decimal-digit-family characters found in the fractional part of the |
1357 | + // sub-picture. |
1358 | + // |
1359 | + ++(sub_pic->*cur_part).minimum_size; |
1360 | + |
1361 | + goto set_active; |
1362 | + } |
1363 | + |
1364 | + if ( got_active ) |
1365 | + got_passive_after_active = true; |
1366 | + continue; |
1367 | + |
1368 | +set_active: |
1369 | + // |
1370 | + // XQuery F&O 3.0 4.7.3: The ... variables decimal-separator-sign, |
1371 | + // grouping-sign, decimal-digit-family, optional-digit-sign and pattern- |
1372 | + // separator-sign are classified as active characters, and all other |
1373 | + // characters (including the percent-sign and per-mille-sign) are |
1374 | + // classified as passive characters. |
1375 | + // |
1376 | + if ( got_passive_after_active && got_active ) { |
1377 | + // |
1378 | + // Ibid 4.7.3: A sub-picture must not contain a passive character that is |
1379 | + // preceded by an active character and that is followed by another active |
1380 | + // character. |
1381 | + // |
1382 | + // In other words, you can't have active-passive-active. |
1383 | + // |
1384 | + throw XQUERY_EXCEPTION( |
1385 | + err::FODF1310, |
1386 | + ERROR_PARAMS( |
1387 | + pic.format, |
1388 | + ZED( FODF1310_NoActivePassiveActive ), |
1389 | + unicode::printable_cp( cp ) |
1390 | + ), |
1391 | + ERROR_LOC( loc ) |
1392 | + ); |
1393 | + } |
1394 | + got_active = true; |
1395 | + |
1396 | + if ( leftmost_active_pos == utf8::npos ) |
1397 | + leftmost_active_pos = pos; |
1398 | + rightmost_active_pos = pos; |
1399 | + } // for |
1400 | + |
1401 | + if ( !(got_optional_digit || got_mandatory_digit) ) { |
1402 | + throw XQUERY_EXCEPTION( |
1403 | + // |
1404 | + // Ibid: A sub-picture must contain at least one character that is an |
1405 | + // optional-digit-sign or a member of the decimal-digit-family. |
1406 | + // |
1407 | + err::FODF1310, |
1408 | + ERROR_PARAMS( ZED( FODF1310_MustHaveOptOrMandatoryDigit ) ), |
1409 | + ERROR_LOC( loc ) |
1410 | + ); |
1411 | + } |
1412 | + |
1413 | + if ( grouping_interval_possible ) { |
1414 | + if ( decimal_separator_pos != utf8::npos ) |
1415 | + pos = decimal_separator_pos; |
1416 | + if ( !grouping_interval ) { |
1417 | + if ( got_grouping_separator ) { |
1418 | + // |
1419 | + // There's only a single grouping separator, e.g., "1,000". |
1420 | + // |
1421 | + grouping_interval = pos - prev_grouping_pos; |
1422 | + } |
1423 | + } else if ( pos - prev_grouping_pos != grouping_interval ) { |
1424 | + // |
1425 | + // There are multiple grouping separators, but they're not equally spaced |
1426 | + // from the last digit, e.g., "1,000,00". (This is most likely a mistake |
1427 | + // on the part of the user.) |
1428 | + // |
1429 | + grouping_interval = 0; |
1430 | + } |
1431 | + sub_pic->integer_part.grouping_interval = grouping_interval; |
1432 | + } else |
1433 | + sub_pic->integer_part.mandatory_grouping_seps = grouping_separators; |
1434 | + |
1435 | + // |
1436 | + // Ibid 4.7.4: [I]f the sub-picture contains no decimal-digit-family |
1437 | + // character and no decimal-separator-sign, [the minimum-integer-part-size] |
1438 | + // is set to one. |
1439 | + // |
1440 | + if ( !got_mandatory_digit && decimal_separator_pos == utf8::npos ) |
1441 | + sub_pic->integer_part.minimum_size = 1; |
1442 | + |
1443 | + if ( rightmost_active_pos != utf8::npos && |
1444 | + rightmost_active_pos + 1 < u_format.size() ) { |
1445 | + // |
1446 | + // Ibid: The suffix is set to contain all passive characters to the right |
1447 | + // of the rightmost active character in the fractional part of the |
1448 | + // sub-picture. |
1449 | + // |
1450 | + // Note: must do suffix first so calling erase() won't invalidate |
1451 | + // leftmost_active_pos. |
1452 | + // |
1453 | + sub_pic->suffix = u_format.substr( rightmost_active_pos + 1 ); |
1454 | + u_format.erase( rightmost_active_pos + 1 ); |
1455 | + } |
1456 | + if ( leftmost_active_pos != utf8::npos ) { |
1457 | + // |
1458 | + // Ibid: The prefix is set to contain all passive characters in the |
1459 | + // sub-picture to the left of the leftmost active character. |
1460 | + // |
1461 | + sub_pic->prefix = u_format.substr( 0, leftmost_active_pos ); |
1462 | + u_format.erase( 0, leftmost_active_pos ); |
1463 | + |
1464 | + if ( decimal_separator_pos != utf8::npos ) { |
1465 | + // |
1466 | + // Adjust decimal_separator_pos by number of characters erased above. |
1467 | + // |
1468 | + decimal_separator_pos -= leftmost_active_pos; |
1469 | + } |
1470 | + } |
1471 | + |
1472 | + sub_pic->integer_part.format = u_format.substr( 0, decimal_separator_pos ); |
1473 | + if ( decimal_separator_pos != utf8::npos ) { |
1474 | + sub_pic->fractional_part.format = |
1475 | + u_format.substr( decimal_separator_pos + 1 ); |
1476 | + } |
1477 | + |
1478 | + return; |
1479 | + |
1480 | +got_decimal_grouping_adjacent: |
1481 | + throw XQUERY_EXCEPTION( |
1482 | + err::FODF1310, |
1483 | + ERROR_PARAMS( |
1484 | + pic.format, |
1485 | + ZED( FODF1310_NoDecimalGroupingAdjacent_34 ), |
1486 | + unicode::printable_cp( pic.VAR_CP( decimal_separator_sign ) ), |
1487 | + unicode::printable_cp( pic.VAR_CP( grouping_separator_sign ) ) |
1488 | + ), |
1489 | + ERROR_LOC( loc ) |
1490 | + ); |
1491 | + |
1492 | +got_multiple_signs: |
1493 | + throw XQUERY_EXCEPTION( |
1494 | + err::FODF1310, |
1495 | + ERROR_PARAMS( |
1496 | + pic.format, |
1497 | + ZED( FODF1310_MultipleSign_3 ), |
1498 | + unicode::printable_cp( cp ) |
1499 | + ), |
1500 | + ERROR_LOC( loc ) |
1501 | + ); |
1502 | + |
1503 | +got_percent_per_mille: |
1504 | + throw XQUERY_EXCEPTION( |
1505 | + err::FODF1310, |
1506 | + ERROR_PARAMS( pic.format, ZED( FODF1310_NoPercentPermille ) ), |
1507 | + ERROR_LOC( loc ) |
1508 | + ); |
1509 | +} |
1510 | + |
1511 | +static void parse_picture( picture *pic, QueryLoc const &loc ) { |
1512 | + check_multiple( pic->format, pic->VAR( pattern_separator_sign ), *pic, loc ); |
1513 | + |
1514 | + zstring::size_type const pos = |
1515 | + pic->format.find( pic->VAR( pattern_separator_sign ) ); |
1516 | + |
1517 | + pic->pos_subpicture.format = pic->format.substr( 0, pos ); |
1518 | + if ( pos != zstring::npos ) { |
1519 | + pic->neg_subpicture.format = |
1520 | + pic->format.substr( pos + pic->VAR( pattern_separator_sign ).size() ); |
1521 | + } |
1522 | + |
1523 | + parse_subpicture( &pic->pos_subpicture, *pic, loc ); |
1524 | + if ( pic->neg_subpicture.format.empty() ) { |
1525 | + pic->neg_subpicture = pic->pos_subpicture; |
1526 | + // |
1527 | + // XQuery F&O 3.0 4.7.4: If the picture string contains only one sub- |
1528 | + // picture, the prefix for the negative sub-picture is set by concatenating |
1529 | + // the minus-sign character and the prefix for the positive sub-picture (if |
1530 | + // any), in that order. |
1531 | + // |
1532 | + pic->neg_subpicture.prefix = pic->VAR( minus_sign ); |
1533 | + pic->neg_subpicture.prefix += pic->pos_subpicture.prefix; |
1534 | + } else |
1535 | + parse_subpicture( &pic->neg_subpicture, *pic, loc ); |
1536 | +} |
1537 | + |
1538 | +static void set_format( DecimalFormat_t const &df, picture *pic ) { |
1539 | + // |
1540 | + // See XQuery 3.9 2.1.1 and XQuery F&O 3.0 4.7.1. |
1541 | + // |
1542 | + FOR_EACH( DecimalFormat::properties_type, prop, df->getProperties() ) { |
1543 | + if ( prop->first == "decimal-separator" ) |
1544 | + pic->VAR( decimal_separator_sign ) = prop->second; |
1545 | + else if ( prop->first == "digit" ) |
1546 | + pic->VAR( optional_digit_sign ) = prop->second; |
1547 | + else if ( prop->first == "grouping-separator" ) |
1548 | + pic->VAR( grouping_separator_sign ) = prop->second; |
1549 | + else if ( prop->first == "infinity" ) |
1550 | + pic->VAR( infinity ) = prop->second; |
1551 | + else if ( prop->first == "minus-sign" ) |
1552 | + pic->VAR( minus_sign ) = prop->second; |
1553 | + else if ( prop->first == "NaN" ) |
1554 | + pic->VAR( NaN ) = prop->second; |
1555 | + else if ( prop->first == "pattern-separator" ) |
1556 | + pic->VAR( pattern_separator_sign ) = prop->second; |
1557 | + else if ( prop->first == "percent" ) |
1558 | + pic->VAR( percent_sign ) = prop->second; |
1559 | + else if ( prop->first == "per-mille" ) |
1560 | + pic->VAR( per_mille_sign ) = prop->second; |
1561 | + else if ( prop->first == "zero-digit" ) |
1562 | + pic->VAR( mandatory_digit_sign ) = prop->second; |
1563 | + } |
1564 | + pic->set_format_codepoints(); |
1565 | +} |
1566 | + |
1567 | +bool FormatNumberIterator::nextImpl( store::Item_t &result, |
1568 | + PlanState& planState ) const { |
1569 | + DecimalFormat_t df; |
1570 | + store::Item_t format_name_item; |
1571 | + store::Item_t item, value; |
1572 | + picture pic; |
1573 | + zstring result_str; |
1574 | + PlanIteratorState *state; |
1575 | + |
1576 | + DEFAULT_STACK_INIT( PlanIteratorState, state, planState ); |
1577 | + |
1578 | + if ( !consumeNext( value, theChildren[0].getp(), planState ) || |
1579 | + !is_allowed_type( value->getType() ) ) { |
1580 | + // |
1581 | + // XQuery F&O 3.0 4.7.2: If the supplied value of the $value argument is an |
1582 | + // empty sequence, the function behaves as if the supplied value were the |
1583 | + // xs:double value NaN. |
1584 | + // |
1585 | + // Ibid: The $value argument may be of any numeric data type (xs:double, |
1586 | + // xs:float, xs:decimal, or their subtypes including xs:integer). |
1587 | + // |
1588 | + GENV_ITEMFACTORY->createDouble( value, xs_double::nan() ); |
1589 | + } |
1590 | + |
1591 | + consumeNext( item, theChildren[1].getp(), planState ); |
1592 | + item->getStringValue2( pic.format ); |
1593 | + |
1594 | + if ( theChildren.size() >= 3 ) |
1595 | + consumeNext( format_name_item, theChildren[2].getp(), planState ); |
1596 | + |
1597 | + if ( theChildren.size() < 3 || !format_name_item ) { |
1598 | + df = planState.theCompilerCB->theRootSctx->get_decimal_format( NULL ); |
1599 | + } else { |
1600 | + |
1601 | + zstring format_name( format_name_item->getStringValue() ); |
1602 | + ascii::trim_whitespace( format_name ); |
1603 | + zstring prefix, local; |
1604 | + if ( !xml::split_name( format_name, &prefix, &local ) || |
1605 | + prefix.empty() ) { |
1606 | + GENV_ITEMFACTORY->createQName( format_name_item, "", "", format_name ); |
1607 | + } else { |
1608 | + zstring ns; |
1609 | + if ( theSctx->lookup_ns( ns, prefix, loc, false ) ) { |
1610 | + GENV_ITEMFACTORY->createQName( format_name_item, ns, prefix, local ); |
1611 | + } else { |
1612 | + // |
1613 | + // The prefix is not in the known namespaces so the only posibility |
1614 | + // left is for the function to be invoked from an EnclosedIterator. |
1615 | + // |
1616 | + if ( planState.theNodeConstuctionPath.empty() ) |
1617 | + throw XQUERY_EXCEPTION( |
1618 | + err::FODF1280, |
1619 | + ERROR_PARAMS( format_name ), |
1620 | + ERROR_LOC( loc ) |
1621 | + ); |
1622 | + store::NsBindings bindings; |
1623 | + planState.theNodeConstuctionPath.top()-> |
1624 | + getNamespaceBindings( bindings ); |
1625 | + FOR_EACH( store::NsBindings, binding, bindings ) { |
1626 | + if ( prefix == binding->first ) { |
1627 | + GENV_ITEMFACTORY->createQName( |
1628 | + format_name_item, binding->second, prefix, local |
1629 | + ); |
1630 | + break; |
1631 | + } |
1632 | + } |
1633 | + } |
1634 | + } |
1635 | + |
1636 | + if ( format_name_item.isNull() ) |
1637 | + throw XQUERY_EXCEPTION( |
1638 | + err::FODF1280, ERROR_PARAMS( "<null>" ), ERROR_LOC( loc ) |
1639 | + ); |
1640 | + df = planState.theCompilerCB->theRootSctx-> |
1641 | + get_decimal_format( format_name_item ); |
1642 | + if ( !df ) |
1643 | + throw XQUERY_EXCEPTION( |
1644 | + err::FODF1280, ERROR_PARAMS( format_name_item->getStringValue() ), |
1645 | + ERROR_LOC( loc ) |
1646 | + ); |
1647 | + |
1648 | + } // if ( theChildren.size() < 3 ... ) |
1649 | + |
1650 | + if ( !df.isNull() ) |
1651 | + set_format( df, &pic ); |
1652 | + parse_picture( &pic, loc ); |
1653 | + format_number( value, pic, theSctx->get_typemanager(), loc, &result_str ); |
1654 | + STACK_PUSH( GENV_ITEMFACTORY->createString( result, result_str ), state ); |
1655 | + STACK_END (state); |
1656 | +} |
1657 | + |
1658 | +/////////////////////////////////////////////////////////////////////////////// |
1659 | + |
1660 | +} // namespace zorba |
1661 | +/* vim:set et sw=2 ts=2: */ |
1662 | |
1663 | === modified file 'src/runtime/numerics/numerics_impl.cpp' |
1664 | --- src/runtime/numerics/numerics_impl.cpp 2013-03-04 21:00:58 +0000 |
1665 | +++ src/runtime/numerics/numerics_impl.cpp 2013-04-11 17:02:25 +0000 |
1666 | @@ -27,7 +27,6 @@ |
1667 | #include "system/globalenv.h" |
1668 | |
1669 | #include "util/tracer.h" |
1670 | -#include "util/utf8_string.h" |
1671 | |
1672 | #include "types/casting.h" |
1673 | #include "types/typeconstants.h" |
1674 | @@ -396,576 +395,5 @@ |
1675 | STACK_END (state); |
1676 | } |
1677 | |
1678 | -//XQuery 3.0 functions |
1679 | -/******************************************************************************* |
1680 | - |
1681 | -********************************************************************************/ |
1682 | -static const char* decimal_separator_param = "decimal-separator"; |
1683 | -static const char* grouping_separator_param = "grouping-separator"; |
1684 | -static const char* infinity_param = "infinity"; |
1685 | -static const char* minus_sign_param = "minus-sign"; |
1686 | -static const char* nan_param = "NaN"; |
1687 | -static const char* percent_param = "percent"; |
1688 | -static const char* per_mille_param = "per-mille"; |
1689 | -static const char* zero_digit_param = "zero-digit"; |
1690 | -static const char* digit_param = "digit"; |
1691 | -static const char* pattern_separator_param = "pattern-separator"; |
1692 | - |
1693 | - |
1694 | -class FormatNumberInfo |
1695 | -{ |
1696 | -public: |
1697 | - QueryLoc loc; |
1698 | - // Separators |
1699 | - zstring decimal_separator; |
1700 | - zstring grouping_separator; |
1701 | - zstring percent; |
1702 | - zstring per_mille; |
1703 | - zstring zero_digit; |
1704 | - zstring digit_sign; |
1705 | - zstring pattern_separator; |
1706 | - zstring infinity; |
1707 | - zstring NaN; |
1708 | - zstring minus; |
1709 | - |
1710 | - zstring pictureString; // The original picture string, used for debugging and error reporting |
1711 | - |
1712 | - class PartInfo |
1713 | - { |
1714 | - public: |
1715 | - zstring str; |
1716 | - std::vector<int> grouping_pos; |
1717 | - int N; |
1718 | - int minimum_size; |
1719 | - int maximum_size; |
1720 | - PartInfo() : N(-1), minimum_size(0), maximum_size(0) {}; |
1721 | - }; |
1722 | - |
1723 | - class SubPictureInfo |
1724 | - { |
1725 | - public: |
1726 | - zstring str; |
1727 | - zstring prefix; |
1728 | - zstring suffix; |
1729 | - PartInfo integer_part; |
1730 | - PartInfo fractional_part; |
1731 | - SubPictureInfo() { } |
1732 | - } pos_subpicture, neg_subpicture; |
1733 | - |
1734 | - FormatNumberInfo() : |
1735 | - decimal_separator( "." ), |
1736 | - grouping_separator( "," ), |
1737 | - percent( "%" ), |
1738 | - zero_digit( "0" ), |
1739 | - digit_sign( "#" ), |
1740 | - pattern_separator( ";" ), |
1741 | - infinity( "Infinity" ), |
1742 | - NaN( "NaN" ), |
1743 | - minus( "-" ) |
1744 | - { |
1745 | - utf8_string<zstring> u_per_mille( per_mille ); |
1746 | - u_per_mille = (unicode::code_point)0x2030; |
1747 | - } |
1748 | - |
1749 | - void readFormat(const DecimalFormat_t& df_t) |
1750 | - { |
1751 | - if (df_t.isNull()) |
1752 | - return; |
1753 | - |
1754 | - const DecimalFormat::param_vector_type* params = df_t->getParamVector(); |
1755 | - |
1756 | - for ( DecimalFormat::param_vector_type::const_iterator it = params->begin(); it != params->end(); it++) |
1757 | - { |
1758 | - if (it->first == decimal_separator_param) |
1759 | - decimal_separator = it->second.c_str(); |
1760 | - else if (it->first == grouping_separator_param) |
1761 | - grouping_separator = it->second.c_str(); |
1762 | - else if (it->first == infinity_param) |
1763 | - infinity = it->second.c_str(); |
1764 | - else if (it->first == minus_sign_param) |
1765 | - minus = it->second.c_str(); |
1766 | - else if (it->first == nan_param) |
1767 | - NaN = it->second.c_str(); |
1768 | - else if (it->first == percent_param) |
1769 | - percent = it->second.c_str(); |
1770 | - else if (it->first == per_mille_param) |
1771 | - per_mille = it->second.c_str(); |
1772 | - else if (it->first == zero_digit_param) |
1773 | - zero_digit = it->second.c_str(); |
1774 | - else if (it->first == digit_param) |
1775 | - digit_sign = it->second.c_str(); |
1776 | - else if (it->first == pattern_separator_param) |
1777 | - pattern_separator = it->second.c_str(); |
1778 | - } |
1779 | - } |
1780 | -}; |
1781 | - |
1782 | - |
1783 | -// returns an error if there are two or more instances of the given pattern in the string |
1784 | -static void errorIfTwoOrMore(zstring const& part, const char* sep, FormatNumberInfo& info) |
1785 | -{ |
1786 | - zstring::size_type const pos = part.find(sep); |
1787 | - |
1788 | - if (pos != zstring::npos) |
1789 | - { |
1790 | - if (part.find(sep, strlen(sep), pos+1) != zstring::npos) |
1791 | - throw XQUERY_EXCEPTION(err::FODF1310, ERROR_PARAMS(info.pictureString, ZED(FormatNumberDuplicates), sep), ERROR_LOC(info.loc)); |
1792 | - } |
1793 | -} |
1794 | - |
1795 | - |
1796 | -static void parsePart( |
1797 | - FormatNumberInfo& info, |
1798 | - FormatNumberInfo::PartInfo& part, |
1799 | - bool fractional = false) |
1800 | -{ |
1801 | - zstring& str = part.str; |
1802 | - if (str.empty()) |
1803 | - return; |
1804 | - |
1805 | - errorIfTwoOrMore(str, info.percent.c_str(), info); |
1806 | - errorIfTwoOrMore(str, info.per_mille.c_str(), info); |
1807 | - |
1808 | - if (str.find(info.percent.c_str()) != zstring::npos && |
1809 | - str.find(info.per_mille.c_str()) != zstring::npos) |
1810 | - { |
1811 | - throw XQUERY_EXCEPTION(err::FODF1310, ERROR_PARAMS(info.pictureString, ZED(FormatNumberPercentPermille)), ERROR_LOC(info.loc)); |
1812 | - } |
1813 | - |
1814 | - if (str.find(info.digit_sign.c_str()) == zstring::npos && |
1815 | - str.find(info.zero_digit.c_str()) == zstring::npos) |
1816 | - { |
1817 | - throw XQUERY_EXCEPTION(err::FODF1310, ERROR_PARAMS(info.pictureString, ZED(FormatNumberAtLeastOneOptionalOrDecimal)), ERROR_LOC(info.loc)); |
1818 | - } |
1819 | - |
1820 | - // get grouping separators |
1821 | - int digit_signs = 0; |
1822 | - int zero_signs = 0; |
1823 | - int start = fractional? 0 : (int)str.size()-1; |
1824 | - int end = fractional? (int)str.size() : -1; |
1825 | - int delta = fractional? 1 : -1; |
1826 | - int first_digit_sign = -1; |
1827 | - int last_zero_sign = -1; |
1828 | - while (start != end) |
1829 | - { |
1830 | - zstring::value_type ch = str[start]; |
1831 | - if (info.digit_sign[0] == ch) |
1832 | - { |
1833 | - if (first_digit_sign == -1) |
1834 | - first_digit_sign = start; |
1835 | - digit_signs++; |
1836 | - } |
1837 | - else if (info.zero_digit[0] == ch) |
1838 | - { |
1839 | - last_zero_sign = start; |
1840 | - zero_signs++; |
1841 | - } |
1842 | - else if (info.grouping_separator[0] == ch) |
1843 | - part.grouping_pos.push_back(digit_signs+zero_signs); |
1844 | - start += delta; |
1845 | - } |
1846 | - |
1847 | - if (first_digit_sign != -1 && last_zero_sign != -1) |
1848 | - { |
1849 | - if (!fractional && first_digit_sign > last_zero_sign) |
1850 | - throw XQUERY_EXCEPTION(err::FODF1310, ERROR_PARAMS(info.pictureString, ZED(FormatNumberIntegerPart)), ERROR_LOC(info.loc)); |
1851 | - else if (fractional && first_digit_sign < last_zero_sign) |
1852 | - throw XQUERY_EXCEPTION(err::FODF1310, ERROR_PARAMS(info.pictureString, ZED(FormatNumberFractionalPart)), ERROR_LOC(info.loc)); |
1853 | - } |
1854 | - |
1855 | - if (part.grouping_pos.size() > 0 && part.grouping_pos[0] == 0) |
1856 | - throw XQUERY_EXCEPTION(err::FODF1310, ERROR_PARAMS(info.pictureString, ZED(FormatNumberGroupingAdjacentToDecimal)), ERROR_LOC(info.loc)); |
1857 | - |
1858 | - if (part.grouping_pos.size() > 0) |
1859 | - { |
1860 | - part.N = part.grouping_pos[0]; |
1861 | - for (unsigned int i=1; i<part.grouping_pos.size(); i++) |
1862 | - if ((part.grouping_pos[i] % part.N) != 0) |
1863 | - { |
1864 | - part.N = -1; |
1865 | - break; |
1866 | - } |
1867 | - } |
1868 | - |
1869 | - part.minimum_size = zero_signs; |
1870 | - if (!fractional && |
1871 | - zero_signs == 0 && |
1872 | - str.find(info.decimal_separator.c_str()) == zstring::npos) |
1873 | - { |
1874 | - part.minimum_size = 1; |
1875 | - } |
1876 | - |
1877 | - if (fractional) |
1878 | - part.maximum_size = digit_signs + zero_signs; |
1879 | -} |
1880 | - |
1881 | - |
1882 | -static void parseSubpicture( |
1883 | - FormatNumberInfo::SubPictureInfo& sub_picture, |
1884 | - FormatNumberInfo& info) |
1885 | -{ |
1886 | - int chars; |
1887 | - zstring& str = sub_picture.str; |
1888 | - if (str.empty()) |
1889 | - return; |
1890 | - |
1891 | - errorIfTwoOrMore(str, info.decimal_separator.c_str(), info); |
1892 | - zstring::size_type pos = str.find(info.decimal_separator.c_str()); |
1893 | - if (pos != zstring::npos) |
1894 | - { |
1895 | - sub_picture.integer_part.str = str.substr(0, pos); |
1896 | - sub_picture.fractional_part.str = str.substr(pos+1, str.size()-pos); |
1897 | - } |
1898 | - else |
1899 | - sub_picture.integer_part.str = str; |
1900 | - |
1901 | - parsePart(info, sub_picture.integer_part); |
1902 | - parsePart(info, sub_picture.fractional_part, true); |
1903 | - |
1904 | - // prefix |
1905 | - zstring temp = sub_picture.integer_part.str; |
1906 | - chars = (int)temp.size(); |
1907 | - for (int i = 0; i < chars; i++) |
1908 | - { |
1909 | - zstring::value_type ch = temp[i]; |
1910 | - if (info.decimal_separator[0] == ch || info.grouping_separator[0] == ch || info.zero_digit[0] == ch |
1911 | - || info.digit_sign[0] == ch || info.pattern_separator[0] == ch || i == chars-1) |
1912 | - { |
1913 | - sub_picture.prefix = temp.substr(0, i); |
1914 | - break; |
1915 | - } |
1916 | - } |
1917 | - // suffix |
1918 | - temp = sub_picture.fractional_part.str; |
1919 | - chars = (int)temp.size(); |
1920 | - for (int i=chars-1; i >= 0; i--) |
1921 | - { |
1922 | - zstring::value_type ch = temp[i]; |
1923 | - if (info.decimal_separator[0] == ch || info.grouping_separator[0] == ch || info.zero_digit[0] == ch |
1924 | - || info.digit_sign[0] == ch || info.pattern_separator[0] == ch || i == 0) |
1925 | - { |
1926 | - sub_picture.suffix = temp.substr(i+1, chars-i-1); |
1927 | - break; |
1928 | - } |
1929 | - } |
1930 | -} |
1931 | - |
1932 | - |
1933 | -static void parsePicture(FormatNumberInfo& info) |
1934 | -{ |
1935 | - errorIfTwoOrMore(info.pictureString, info.pattern_separator.c_str(), info); |
1936 | - |
1937 | - zstring::size_type pos = info.pictureString.find(info.pattern_separator.c_str()); |
1938 | - if (pos != zstring::npos) |
1939 | - { |
1940 | - info.pos_subpicture.str = info.pictureString.substr(0, pos); |
1941 | - info.neg_subpicture.str = info.pictureString.substr(pos+1, info.pictureString.size() - pos); |
1942 | - } |
1943 | - else |
1944 | - info.pos_subpicture.str = info.pictureString; |
1945 | - |
1946 | - parseSubpicture(info.pos_subpicture, info); |
1947 | - if (info.neg_subpicture.str.empty()) |
1948 | - { |
1949 | - info.neg_subpicture = info.pos_subpicture; |
1950 | - zstring temp(info.minus); |
1951 | - temp.append(info.pos_subpicture.prefix); |
1952 | - info.neg_subpicture.prefix = temp; |
1953 | - } |
1954 | - else |
1955 | - parseSubpicture(info.neg_subpicture, info); |
1956 | -} |
1957 | - |
1958 | - |
1959 | -static bool isAllowedType(store::Item* type_qname) |
1960 | -{ |
1961 | - const RootTypeManager& rtm = GENV_TYPESYSTEM; |
1962 | - |
1963 | - if (type_qname->equals(rtm.XS_FLOAT_QNAME) |
1964 | - || type_qname->equals(rtm.XS_DOUBLE_QNAME) |
1965 | - || type_qname->equals(rtm.XS_DECIMAL_QNAME) |
1966 | - || type_qname->equals(rtm.XS_INTEGER_QNAME) |
1967 | - || type_qname->equals(rtm.XS_NON_POSITIVE_INTEGER_QNAME) |
1968 | - || type_qname->equals(rtm.XS_NEGATIVE_INTEGER_QNAME) |
1969 | - || type_qname->equals(rtm.XS_LONG_QNAME) |
1970 | - || type_qname->equals(rtm.XS_INT_QNAME) |
1971 | - || type_qname->equals(rtm.XS_SHORT_QNAME) |
1972 | - || type_qname->equals(rtm.XS_BYTE_QNAME) |
1973 | - || type_qname->equals(rtm.XS_NON_NEGATIVE_INTEGER_QNAME) |
1974 | - || type_qname->equals(rtm.XS_UNSIGNED_LONG_QNAME) |
1975 | - || type_qname->equals(rtm.XS_UNSIGNED_INT_QNAME) |
1976 | - || type_qname->equals(rtm.XS_UNSIGNED_SHORT_QNAME) |
1977 | - || type_qname->equals(rtm.XS_UNSIGNED_BYTE_QNAME) |
1978 | - || type_qname->equals(rtm.XS_POSITIVE_INTEGER_QNAME)) |
1979 | - return true; |
1980 | - else |
1981 | - return false; |
1982 | -} |
1983 | - |
1984 | -// returns n zeros "0". n can be <=0 and then the function will return "" |
1985 | -static zstring createZeros(int n) |
1986 | -{ |
1987 | - zstring result; |
1988 | - // bugfix for bug #3134696 |
1989 | - // if called from formatNumber with n = -1 |
1990 | - if (n > 0) { |
1991 | - result.append(n, '0'); |
1992 | - } |
1993 | - return result; |
1994 | -} |
1995 | - |
1996 | - |
1997 | -static void formatGroupings( |
1998 | - zstring& result, |
1999 | - const zstring& str, |
2000 | - FormatNumberInfo::PartInfo& part, |
2001 | - FormatNumberInfo& info) |
2002 | -{ |
2003 | - unsigned int grouping_index = 0; |
2004 | - |
2005 | - result.clear(); |
2006 | - |
2007 | - long len = (long)str.size(); |
2008 | - |
2009 | - for (long i = len-1; i >= 0; i--) |
2010 | - { |
2011 | - char ch = str[i]; |
2012 | - |
2013 | - if (((grouping_index < part.grouping_pos.size() |
2014 | - && |
2015 | - len-i-1 == part.grouping_pos[grouping_index]) |
2016 | - || |
2017 | - (part.N != -1 |
2018 | - && |
2019 | - len-1-i != 0 |
2020 | - && |
2021 | - ((len-1-i) % part.N) == 0)) |
2022 | - && |
2023 | - ch != '-') |
2024 | - { |
2025 | - result.append(info.grouping_separator); |
2026 | - if (grouping_index < part.grouping_pos.size()) |
2027 | - grouping_index++; |
2028 | - while (grouping_index < part.grouping_pos.size() |
2029 | - && |
2030 | - part.grouping_pos[grouping_index] == part.grouping_pos[grouping_index-1]) |
2031 | - { |
2032 | - result.append(info.grouping_separator); |
2033 | - grouping_index++; |
2034 | - } |
2035 | - } |
2036 | - |
2037 | - if (ch == '0') |
2038 | - result.append(info.zero_digit); |
2039 | - else if (ch == '-') |
2040 | - ; // skip the '-' sign |
2041 | - else |
2042 | - result.push_back(ch); |
2043 | - } |
2044 | -} |
2045 | - |
2046 | - |
2047 | -static void formatNumber( |
2048 | - zstring& resultString, |
2049 | - store::Item_t& number, |
2050 | - FormatNumberInfo& info, |
2051 | - const TypeManager* tm, |
2052 | - const QueryLoc& loc) |
2053 | -{ |
2054 | - const RootTypeManager& rtm = GENV_TYPESYSTEM; |
2055 | - |
2056 | - if (number->isNaN()) |
2057 | - { |
2058 | - resultString.append(info.NaN); |
2059 | - return; |
2060 | - } |
2061 | - |
2062 | - store::Item_t zero; |
2063 | - store::Item_t doubleItem; |
2064 | - FormatNumberInfo::SubPictureInfo& sub_picture = info.pos_subpicture; |
2065 | - |
2066 | - GENV_ITEMFACTORY->createDouble(zero, xs_double::zero()); |
2067 | - |
2068 | - GenericCast::castToAtomic(doubleItem, number, &*rtm.DOUBLE_TYPE_ONE, tm, NULL, loc); |
2069 | - |
2070 | - if (doubleItem->compare(zero) == -1) |
2071 | - { |
2072 | - sub_picture = info.neg_subpicture; |
2073 | - } |
2074 | - |
2075 | - if (doubleItem->isPosOrNegInf()) |
2076 | - { |
2077 | - resultString.append(sub_picture.prefix); |
2078 | - resultString.append(info.infinity); |
2079 | - resultString.append(sub_picture.suffix); |
2080 | - return; |
2081 | - } |
2082 | - |
2083 | - xs_double adjusted = doubleItem->getDoubleValue(); |
2084 | - |
2085 | - if (sub_picture.str.find(info.percent) != zstring::npos) |
2086 | - adjusted *= 100; |
2087 | - else if (sub_picture.str.find(info.per_mille) != zstring::npos) |
2088 | - adjusted *= 1000; |
2089 | - |
2090 | - adjusted = adjusted.roundHalfToEven(Integer(sub_picture.fractional_part.maximum_size)); |
2091 | - |
2092 | - zstring converted = adjusted.toString(true); |
2093 | - |
2094 | - // process min sizes |
2095 | - zstring integer_part; |
2096 | - zstring fractional_part; |
2097 | - zstring::size_type pos = converted.find(".", 0, 1); |
2098 | - if (pos == zstring::npos) |
2099 | - { |
2100 | - integer_part = converted; |
2101 | - } |
2102 | - else |
2103 | - { |
2104 | - integer_part = converted.substr(0, pos); |
2105 | - fractional_part = converted.substr(pos+1, converted.size() - pos + 1); |
2106 | - } |
2107 | - |
2108 | - // Add zeros |
2109 | - zstring temp = createZeros((int)(sub_picture.integer_part.minimum_size - integer_part.size())); |
2110 | - temp.append(integer_part); |
2111 | - integer_part = temp; |
2112 | - fractional_part.append(createZeros((int)(sub_picture.fractional_part.minimum_size - fractional_part.size()))); |
2113 | - |
2114 | - // groupings |
2115 | - zstring integer_part_result; |
2116 | - zstring fractional_part_result; |
2117 | - formatGroupings(integer_part_result, integer_part, sub_picture.integer_part, info); |
2118 | - |
2119 | - zstring tmp; |
2120 | - ascii::reverse(integer_part_result, &tmp); |
2121 | - integer_part_result.swap(tmp); |
2122 | - |
2123 | - tmp.clear(); |
2124 | - ascii::reverse(fractional_part, &tmp); |
2125 | - fractional_part.swap(tmp); |
2126 | - |
2127 | - formatGroupings(fractional_part_result, |
2128 | - fractional_part, |
2129 | - sub_picture.fractional_part, |
2130 | - info); |
2131 | - |
2132 | - resultString.append(sub_picture.prefix); |
2133 | - resultString.append(integer_part_result); |
2134 | - if (fractional_part.size() != 0) |
2135 | - { |
2136 | - resultString.append(info.decimal_separator); |
2137 | - resultString.append(fractional_part_result); |
2138 | - } |
2139 | - resultString.append(sub_picture.suffix); |
2140 | -} |
2141 | - |
2142 | - |
2143 | -bool |
2144 | -FormatNumberIterator::nextImpl(store::Item_t& result, PlanState& planState) const |
2145 | -{ |
2146 | - zstring resultString; |
2147 | - store::Item_t numberItem, pictureItem; |
2148 | - store::Item_t formatName = NULL; |
2149 | - FormatNumberInfo info; |
2150 | - DecimalFormat_t df_t; |
2151 | - |
2152 | - PlanIteratorState* state; |
2153 | - DEFAULT_STACK_INIT ( PlanIteratorState, state, planState ); |
2154 | - |
2155 | - if (!consumeNext(result, theChildren[0].getp(), planState )) |
2156 | - { |
2157 | - // Got void, assume NaN, return "NaN" |
2158 | - GENV_ITEMFACTORY->createDouble(result, xs_double::nan()); |
2159 | - } |
2160 | - |
2161 | - { |
2162 | - info.loc = loc; |
2163 | - if (!isAllowedType(result->getType())) |
2164 | - { |
2165 | - RAISE_ERROR(err::XPTY0004, info.loc, |
2166 | - ERROR_PARAMS(ZED(XPTY0004_FormatNumber_2), result->getType()->getStringValue())); |
2167 | - } |
2168 | - |
2169 | - consumeNext(pictureItem, theChildren[1].getp(), planState); |
2170 | - |
2171 | - if (theChildren.size() == 3) |
2172 | - consumeNext(formatName, theChildren[2].getp(), planState); |
2173 | - |
2174 | - if (theChildren.size() < 3 || formatName.getp() == NULL) |
2175 | - { |
2176 | - df_t = planState.theCompilerCB->theRootSctx->get_decimal_format(NULL); |
2177 | - } |
2178 | - else |
2179 | - { |
2180 | - do // use a do/while to avoid a horde of nested if/then/elses |
2181 | - { |
2182 | - // The formatName is a string, which must be interpreted as a QName -> |
2183 | - // must resolve the namespace, if any |
2184 | - zstring tmpFormatName = formatName->getStringValue(); |
2185 | - formatName = NULL; |
2186 | - if (tmpFormatName.find(':') == zstring::npos) |
2187 | - { |
2188 | - GENV_ITEMFACTORY->createQName(formatName, "", "", tmpFormatName); |
2189 | - break; |
2190 | - } |
2191 | - |
2192 | - zstring ns; |
2193 | - zstring prefix = tmpFormatName.substr(0, tmpFormatName.find(':')); |
2194 | - if (theSctx->lookup_ns(ns, prefix, loc, false)) |
2195 | - { |
2196 | - GENV_ITEMFACTORY->createQName(formatName, |
2197 | - ns, |
2198 | - prefix, |
2199 | - tmpFormatName.substr(tmpFormatName.find(':')+1)); |
2200 | - break; |
2201 | - } |
2202 | - |
2203 | - // The prefix is not in the known namespaces, the only posibility left is for the function to be invoked from an EnclosedIterator |
2204 | - if (planState.theNodeConstuctionPath.empty()) |
2205 | - { |
2206 | - RAISE_ERROR(err::FODF1280, loc, ERROR_PARAMS(tmpFormatName)); |
2207 | - } |
2208 | - |
2209 | - store::NsBindings bindings; |
2210 | - planState.theNodeConstuctionPath.top()->getNamespaceBindings(bindings); |
2211 | - for (unsigned int i = 0; i < bindings.size(); i++) |
2212 | - { |
2213 | - if (prefix == bindings[i].first) |
2214 | - { |
2215 | - GENV_ITEMFACTORY->createQName(formatName, |
2216 | - bindings[i].second, |
2217 | - prefix, |
2218 | - tmpFormatName.substr(tmpFormatName.find(':')+1)); |
2219 | - break; |
2220 | - } |
2221 | - } |
2222 | - } while(0); |
2223 | - |
2224 | - if (formatName.isNull()) |
2225 | - throw XQUERY_EXCEPTION( |
2226 | - err::FODF1280, ERROR_PARAMS( "<null>" ), ERROR_LOC( loc ) |
2227 | - ); |
2228 | - |
2229 | - if ( (df_t = planState.theCompilerCB->theRootSctx->get_decimal_format(formatName)).getp() == NULL ) |
2230 | - throw XQUERY_EXCEPTION( |
2231 | - err::FODF1280, ERROR_PARAMS( formatName->getStringValue() ), |
2232 | - ERROR_LOC( loc ) |
2233 | - ); |
2234 | - |
2235 | - } // if (theChildren.size() < 3) |
2236 | - |
2237 | - info.readFormat(df_t); |
2238 | - |
2239 | - info.pictureString = pictureItem->getStringValue(); |
2240 | - parsePicture(info); |
2241 | - formatNumber(resultString, result, info, theSctx->get_typemanager(), loc); |
2242 | - |
2243 | - STACK_PUSH (GENV_ITEMFACTORY->createString(result, resultString), state); |
2244 | - } |
2245 | - |
2246 | - STACK_END (state); |
2247 | -} |
2248 | - |
2249 | } // namespace zorba |
2250 | /* vim:set et sw=2 ts=2: */ |
2251 | |
2252 | === modified file 'src/util/utf8_util_base.h' |
2253 | --- src/util/utf8_util_base.h 2013-02-07 17:24:36 +0000 |
2254 | +++ src/util/utf8_util_base.h 2013-04-11 17:02:25 +0000 |
2255 | @@ -133,7 +133,7 @@ |
2256 | } |
2257 | |
2258 | /** |
2259 | - * Decodes the next Unicode character. |
2260 | + * Decodes the next Unicode character and advances the iterator. |
2261 | * |
2262 | * @tparam OctetIterator The iterator to use to iterate over the underlying |
2263 | * byte sequence. |
2264 | @@ -146,6 +146,17 @@ |
2265 | unicode::code_point next_char( OctetIterator &i ); |
2266 | |
2267 | /** |
2268 | + * Decodes the next Unicode character. |
2269 | + * |
2270 | + * @param p A pointer to the first byte of a UTF-8 byte sequence comprising a |
2271 | + * Unicode character. |
2272 | + * @return Returns the Unicode code-point of the next character. |
2273 | + */ |
2274 | +inline unicode::code_point decode( storage_type const *p ) { |
2275 | + return next_char( p ); |
2276 | +} |
2277 | + |
2278 | +/** |
2279 | * Decodes the previous Unicode character. |
2280 | * |
2281 | * @tparam OctetIterator The iterator to use to iterate over the underlying |
2282 | |
2283 | === modified file 'src/zorbatypes/floatimpl.h' |
2284 | --- src/zorbatypes/floatimpl.h 2013-03-22 19:06:44 +0000 |
2285 | +++ src/zorbatypes/floatimpl.h 2013-04-11 17:02:25 +0000 |
2286 | @@ -216,6 +216,7 @@ |
2287 | |
2288 | ////////// math functions /////////////////////////////////////////////////// |
2289 | |
2290 | + FloatImpl abs() const; |
2291 | FloatImpl acos() const; |
2292 | FloatImpl acosh() const; |
2293 | FloatImpl asin() const; |
2294 | @@ -799,6 +800,11 @@ |
2295 | ////////// math functions ///////////////////////////////////////////////////// |
2296 | |
2297 | template<typename F> |
2298 | +inline FloatImpl<F> FloatImpl<F>::abs() const { |
2299 | + return FloatImpl<F>( std::fabs( value_ ) ); |
2300 | +} |
2301 | + |
2302 | +template<typename F> |
2303 | inline FloatImpl<F> FloatImpl<F>::acosh() const { |
2304 | // formula from www.mathworks.com |
2305 | return FloatImpl<F>( |
2306 | |
2307 | === modified file 'test/fots/CMakeLists.txt' |
2308 | --- test/fots/CMakeLists.txt 2013-04-10 17:05:01 +0000 |
2309 | +++ test/fots/CMakeLists.txt 2013-04-11 17:02:25 +0000 |
2310 | @@ -148,25 +148,19 @@ |
2311 | EXPECTED_FOTS_FAILURE (fn-format-dateTime format-dateTime-011 0) |
2312 | EXPECTED_FOTS_FAILURE (fn-format-dateTime format-dateTime-en152 21558) |
2313 | EXPECTED_FOTS_FAILURE (fn-format-integer format-integer-044 1162631) |
2314 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat14 0) |
2315 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat15 0) |
2316 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat34 0) |
2317 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat38 0) |
2318 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat40 0) |
2319 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat41 0) |
2320 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat42 0) |
2321 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat60a 0) |
2322 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat60m 0) |
2323 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat60o 0) |
2324 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat60q 0) |
2325 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat63 0) |
2326 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat64 0) |
2327 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat70 0) |
2328 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat71 0) |
2329 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat81 0) |
2330 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat83 0) |
2331 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat87 0) |
2332 | -EXPECTED_FOTS_FAILURE (fn-format-number numberformat88 0) |
2333 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat41 1167427) |
2334 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat42 1167427) |
2335 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat60a 1167609) |
2336 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat60m 1167609) |
2337 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat60o 1167609) |
2338 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat60q 1167609) |
2339 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat63 1167609) |
2340 | +IF (ZORBA_WITH_BIG_INTEGER) |
2341 | + EXPECTED_FOTS_FAILURE (fn-format-number numberformat64 1167609) |
2342 | +ENDIF (ZORBA_WITH_BIG_INTEGER) |
2343 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat83 1167643) |
2344 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat87 1167641) |
2345 | +EXPECTED_FOTS_FAILURE (fn-format-number numberformat88 1167641) |
2346 | EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-001 0) |
2347 | EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-002 0) |
2348 | EXPECTED_FOTS_FAILURE (fn-generate-id generate-id-003 0) |
2349 | @@ -326,11 +320,6 @@ |
2350 | EXPECTED_FOTS_FAILURE (prod-ContextItemDecl contextDecl-049 0) |
2351 | EXPECTED_FOTS_FAILURE (prod-CountClause count-007 0) |
2352 | EXPECTED_FOTS_FAILURE (prod-CountClause count-008 0) |
2353 | -EXPECTED_FOTS_FAILURE (prod-DecimalFormatDecl decimal-format-14 0) |
2354 | -EXPECTED_FOTS_FAILURE (prod-DecimalFormatDecl decimal-format-907err 0) |
2355 | -EXPECTED_FOTS_FAILURE (prod-DecimalFormatDecl decimal-format-908err 0) |
2356 | -EXPECTED_FOTS_FAILURE (prod-DecimalFormatDecl decimal-format-910err 0) |
2357 | -EXPECTED_FOTS_FAILURE (prod-DecimalFormatDecl decimal-format-911err 0) |
2358 | EXPECTED_FOTS_FAILURE (prod-DefaultNamespaceDecl defaultnamespacedeclerr-6 0) |
2359 | EXPECTED_FOTS_FAILURE (prod-DefaultNamespaceDecl defaultnamespacedeclerr-8 0) |
2360 | EXPECTED_FOTS_FAILURE (prod-DirElemContent Constr-cont-charref-2 1130998) |
2361 | |
2362 | === renamed directory 'test/rbkt/ExpQueryResults/zorba/math/format_integer' => 'test/rbkt/ExpQueryResults/zorba/numerics/format-integer' |
2363 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-integer/format-integer-1-11.xml.res' |
2364 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-integer/format-integer-1-11.xml.res 1970-01-01 00:00:00 +0000 |
2365 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-integer/format-integer-1-11.xml.res 2013-04-11 17:02:25 +0000 |
2366 | @@ -0,0 +1,1 @@ |
2367 | +true |
2368 | |
2369 | === added directory 'test/rbkt/ExpQueryResults/zorba/numerics/format-number' |
2370 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-01.xml.res' |
2371 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-01.xml.res 1970-01-01 00:00:00 +0000 |
2372 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-01.xml.res 2013-04-11 17:02:25 +0000 |
2373 | @@ -0,0 +1,1 @@ |
2374 | +true |
2375 | |
2376 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-02.xml.res' |
2377 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-02.xml.res 1970-01-01 00:00:00 +0000 |
2378 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-02.xml.res 2013-04-11 17:02:25 +0000 |
2379 | @@ -0,0 +1,1 @@ |
2380 | +true |
2381 | |
2382 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-03.xml.res' |
2383 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-03.xml.res 1970-01-01 00:00:00 +0000 |
2384 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-03.xml.res 2013-04-11 17:02:25 +0000 |
2385 | @@ -0,0 +1,1 @@ |
2386 | +true |
2387 | |
2388 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-04.xml.res' |
2389 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-04.xml.res 1970-01-01 00:00:00 +0000 |
2390 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-04.xml.res 2013-04-11 17:02:25 +0000 |
2391 | @@ -0,0 +1,1 @@ |
2392 | +true |
2393 | |
2394 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-05.xml.res' |
2395 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-05.xml.res 1970-01-01 00:00:00 +0000 |
2396 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-05.xml.res 2013-04-11 17:02:25 +0000 |
2397 | @@ -0,0 +1,1 @@ |
2398 | +true |
2399 | |
2400 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-06.xml.res' |
2401 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-06.xml.res 1970-01-01 00:00:00 +0000 |
2402 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-06.xml.res 2013-04-11 17:02:25 +0000 |
2403 | @@ -0,0 +1,1 @@ |
2404 | +true |
2405 | |
2406 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-07.xml.res' |
2407 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-07.xml.res 1970-01-01 00:00:00 +0000 |
2408 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-07.xml.res 2013-04-11 17:02:25 +0000 |
2409 | @@ -0,0 +1,1 @@ |
2410 | +true |
2411 | |
2412 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-08.xml.res' |
2413 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-08.xml.res 1970-01-01 00:00:00 +0000 |
2414 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-08.xml.res 2013-04-11 17:02:25 +0000 |
2415 | @@ -0,0 +1,1 @@ |
2416 | +true |
2417 | |
2418 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-09.xml.res' |
2419 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-09.xml.res 1970-01-01 00:00:00 +0000 |
2420 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-09.xml.res 2013-04-11 17:02:25 +0000 |
2421 | @@ -0,0 +1,1 @@ |
2422 | +true |
2423 | |
2424 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-10.xml.res' |
2425 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-10.xml.res 1970-01-01 00:00:00 +0000 |
2426 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-10.xml.res 2013-04-11 17:02:25 +0000 |
2427 | @@ -0,0 +1,1 @@ |
2428 | +true |
2429 | |
2430 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-11.xml.res' |
2431 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-11.xml.res 1970-01-01 00:00:00 +0000 |
2432 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-11.xml.res 2013-04-11 17:02:25 +0000 |
2433 | @@ -0,0 +1,1 @@ |
2434 | +true |
2435 | |
2436 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-12.xml.res' |
2437 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-12.xml.res 1970-01-01 00:00:00 +0000 |
2438 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-12.xml.res 2013-04-11 17:02:25 +0000 |
2439 | @@ -0,0 +1,1 @@ |
2440 | +true |
2441 | |
2442 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-13.xml.res' |
2443 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-13.xml.res 1970-01-01 00:00:00 +0000 |
2444 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-13.xml.res 2013-04-11 17:02:25 +0000 |
2445 | @@ -0,0 +1,1 @@ |
2446 | +true |
2447 | |
2448 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-14.xml.res' |
2449 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-14.xml.res 1970-01-01 00:00:00 +0000 |
2450 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-14.xml.res 2013-04-11 17:02:25 +0000 |
2451 | @@ -0,0 +1,1 @@ |
2452 | +true |
2453 | |
2454 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-15.xml.res' |
2455 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-15.xml.res 1970-01-01 00:00:00 +0000 |
2456 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-15.xml.res 2013-04-11 17:02:25 +0000 |
2457 | @@ -0,0 +1,1 @@ |
2458 | +true |
2459 | |
2460 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-01.xml.res' |
2461 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-01.xml.res 1970-01-01 00:00:00 +0000 |
2462 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-01.xml.res 2013-04-11 17:02:25 +0000 |
2463 | @@ -0,0 +1,1 @@ |
2464 | +true |
2465 | |
2466 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-02.xml.res' |
2467 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-02.xml.res 1970-01-01 00:00:00 +0000 |
2468 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-02.xml.res 2013-04-11 17:02:25 +0000 |
2469 | @@ -0,0 +1,1 @@ |
2470 | +true |
2471 | |
2472 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-03.xml.res' |
2473 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-03.xml.res 1970-01-01 00:00:00 +0000 |
2474 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-decimal-format-03.xml.res 2013-04-11 17:02:25 +0000 |
2475 | @@ -0,0 +1,1 @@ |
2476 | +true |
2477 | |
2478 | === added file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-empty.xml.res' |
2479 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-empty.xml.res 1970-01-01 00:00:00 +0000 |
2480 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number/format-number-empty.xml.res 2013-04-11 17:02:25 +0000 |
2481 | @@ -0,0 +1,1 @@ |
2482 | +true |
2483 | |
2484 | === removed file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number1.xml.res' |
2485 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number1.xml.res 2013-02-07 17:24:36 +0000 |
2486 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number1.xml.res 1970-01-01 00:00:00 +0000 |
2487 | @@ -1,1 +0,0 @@ |
2488 | -1 12 |
2489 | |
2490 | === removed file 'test/rbkt/ExpQueryResults/zorba/numerics/format-number2.xml.res' |
2491 | --- test/rbkt/ExpQueryResults/zorba/numerics/format-number2.xml.res 2013-02-07 17:24:36 +0000 |
2492 | +++ test/rbkt/ExpQueryResults/zorba/numerics/format-number2.xml.res 1970-01-01 00:00:00 +0000 |
2493 | @@ -1,1 +0,0 @@ |
2494 | -NaN |
2495 | |
2496 | === renamed directory 'test/rbkt/Queries/zorba/math/format_integer' => 'test/rbkt/Queries/zorba/numerics/format-integer' |
2497 | === added file 'test/rbkt/Queries/zorba/numerics/format-integer/format-integer-1-11.xq' |
2498 | --- test/rbkt/Queries/zorba/numerics/format-integer/format-integer-1-11.xq 1970-01-01 00:00:00 +0000 |
2499 | +++ test/rbkt/Queries/zorba/numerics/format-integer/format-integer-1-11.xq 2013-04-11 17:02:25 +0000 |
2500 | @@ -0,0 +1,7 @@ |
2501 | +(: |
2502 | + : The format is NOT a decimal digit pattern because it does not contain at |
2503 | + : least one Unicode digit. Hence, the format is an unknown format and treated |
2504 | + : as if it were the format "1". |
2505 | + :) |
2506 | + |
2507 | +fn:format-integer( 1234, "#,###" ) eq "1234" |
2508 | |
2509 | === added directory 'test/rbkt/Queries/zorba/numerics/format-number' |
2510 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-01.xq' |
2511 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-01.xq 1970-01-01 00:00:00 +0000 |
2512 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-01.xq 2013-04-11 17:02:25 +0000 |
2513 | @@ -0,0 +1,1 @@ |
2514 | +fn:format-number( 1, "0" ) eq "1" |
2515 | |
2516 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-02.xq' |
2517 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-02.xq 1970-01-01 00:00:00 +0000 |
2518 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-02.xq 2013-04-11 17:02:25 +0000 |
2519 | @@ -0,0 +1,1 @@ |
2520 | +fn:format-number( 1, "#" ) eq "1" |
2521 | |
2522 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-03.xq' |
2523 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-03.xq 1970-01-01 00:00:00 +0000 |
2524 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-03.xq 2013-04-11 17:02:25 +0000 |
2525 | @@ -0,0 +1,1 @@ |
2526 | +fn:format-number( -1, "0" ) eq "-1" |
2527 | |
2528 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-04.xq' |
2529 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-04.xq 1970-01-01 00:00:00 +0000 |
2530 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-04.xq 2013-04-11 17:02:25 +0000 |
2531 | @@ -0,0 +1,1 @@ |
2532 | +fn:format-number( .14, "1%" ) eq "14%" |
2533 | |
2534 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-05.xq' |
2535 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-05.xq 1970-01-01 00:00:00 +0000 |
2536 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-05.xq 2013-04-11 17:02:25 +0000 |
2537 | @@ -0,0 +1,1 @@ |
2538 | +fn:format-number( 12345678.9, "9,999.99" ) eq "12,345,678.90" |
2539 | |
2540 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-06.xq' |
2541 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-06.xq 1970-01-01 00:00:00 +0000 |
2542 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-06.xq 2013-04-11 17:02:25 +0000 |
2543 | @@ -0,0 +1,1 @@ |
2544 | +fn:format-number( 123.9, "9999" ) eq "0124" |
2545 | |
2546 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-07.xq' |
2547 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-07.xq 1970-01-01 00:00:00 +0000 |
2548 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-07.xq 2013-04-11 17:02:25 +0000 |
2549 | @@ -0,0 +1,1 @@ |
2550 | +fn:format-number( -6, "000" ) eq "-006" |
2551 | |
2552 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-08.xq' |
2553 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-08.xq 1970-01-01 00:00:00 +0000 |
2554 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-08.xq 2013-04-11 17:02:25 +0000 |
2555 | @@ -0,0 +1,1 @@ |
2556 | +fn:format-number( 42, "1;-1" ) eq "42" |
2557 | |
2558 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-09.xq' |
2559 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-09.xq 1970-01-01 00:00:00 +0000 |
2560 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-09.xq 2013-04-11 17:02:25 +0000 |
2561 | @@ -0,0 +1,1 @@ |
2562 | +fn:format-number( -42, "1;-1" ) eq "-42" |
2563 | |
2564 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-10.xq' |
2565 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-10.xq 1970-01-01 00:00:00 +0000 |
2566 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-10.xq 2013-04-11 17:02:25 +0000 |
2567 | @@ -0,0 +1,1 @@ |
2568 | +fn:format-number( -42, "1;(1)" ) eq "(42)" |
2569 | |
2570 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-11.xq' |
2571 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-11.xq 1970-01-01 00:00:00 +0000 |
2572 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-11.xq 2013-04-11 17:02:25 +0000 |
2573 | @@ -0,0 +1,1 @@ |
2574 | +fn:format-number( 1.2, "p#.#s" ) eq "p1.2s" |
2575 | |
2576 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-12.xq' |
2577 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-12.xq 1970-01-01 00:00:00 +0000 |
2578 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-12.xq 2013-04-11 17:02:25 +0000 |
2579 | @@ -0,0 +1,1 @@ |
2580 | +fn:format-number( 42, "#,###" ) eq "42" |
2581 | |
2582 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-13.xq' |
2583 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-13.xq 1970-01-01 00:00:00 +0000 |
2584 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-13.xq 2013-04-11 17:02:25 +0000 |
2585 | @@ -0,0 +1,1 @@ |
2586 | +fn:format-number( 1234, "###,###" ) eq "1,234" |
2587 | |
2588 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-14.xq' |
2589 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-14.xq 1970-01-01 00:00:00 +0000 |
2590 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-14.xq 2013-04-11 17:02:25 +0000 |
2591 | @@ -0,0 +1,1 @@ |
2592 | +fn:format-number( 42, "0.00" ) eq "42.00" |
2593 | |
2594 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-15.xq' |
2595 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-15.xq 1970-01-01 00:00:00 +0000 |
2596 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-15.xq 2013-04-11 17:02:25 +0000 |
2597 | @@ -0,0 +1,1 @@ |
2598 | +fn:format-number( 1234567890.123456, ",000.000" ) eq "1,234,567,890.123" |
2599 | |
2600 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-1.spec' |
2601 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-1.spec 1970-01-01 00:00:00 +0000 |
2602 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-1.spec 2013-04-11 17:02:25 +0000 |
2603 | @@ -0,0 +1,1 @@ |
2604 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2605 | |
2606 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-1.xq' |
2607 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-1.xq 1970-01-01 00:00:00 +0000 |
2608 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-1.xq 2013-04-11 17:02:25 +0000 |
2609 | @@ -0,0 +1,1 @@ |
2610 | +fn:format-number( 1, "1;1;" ) |
2611 | |
2612 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-2.spec' |
2613 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-2.spec 1970-01-01 00:00:00 +0000 |
2614 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-2.spec 2013-04-11 17:02:25 +0000 |
2615 | @@ -0,0 +1,1 @@ |
2616 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2617 | |
2618 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-2.xq' |
2619 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-2.xq 1970-01-01 00:00:00 +0000 |
2620 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-2.xq 2013-04-11 17:02:25 +0000 |
2621 | @@ -0,0 +1,1 @@ |
2622 | +fn:format-number( 1, "1.1." ) |
2623 | |
2624 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-3.spec' |
2625 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-3.spec 1970-01-01 00:00:00 +0000 |
2626 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-3.spec 2013-04-11 17:02:25 +0000 |
2627 | @@ -0,0 +1,1 @@ |
2628 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2629 | |
2630 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-3.xq' |
2631 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-3.xq 1970-01-01 00:00:00 +0000 |
2632 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-3.xq 2013-04-11 17:02:25 +0000 |
2633 | @@ -0,0 +1,1 @@ |
2634 | +fn:format-number( .14, "1%%" ) |
2635 | |
2636 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-4.spec' |
2637 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-4.spec 1970-01-01 00:00:00 +0000 |
2638 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-4.spec 2013-04-11 17:02:25 +0000 |
2639 | @@ -0,0 +1,1 @@ |
2640 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2641 | |
2642 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-4.xq' |
2643 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-4.xq 1970-01-01 00:00:00 +0000 |
2644 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MultipleSign-4.xq 2013-04-11 17:02:25 +0000 |
2645 | @@ -0,0 +1,1 @@ |
2646 | +fn:format-number( .014, "1‰‰" ) |
2647 | |
2648 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MustHaveOptOrMandatoryDigit.spec' |
2649 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MustHaveOptOrMandatoryDigit.spec 1970-01-01 00:00:00 +0000 |
2650 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MustHaveOptOrMandatoryDigit.spec 2013-04-11 17:02:25 +0000 |
2651 | @@ -0,0 +1,1 @@ |
2652 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2653 | |
2654 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-MustHaveOptOrMandatoryDigit.xq' |
2655 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-MustHaveOptOrMandatoryDigit.xq 1970-01-01 00:00:00 +0000 |
2656 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-MustHaveOptOrMandatoryDigit.xq 2013-04-11 17:02:25 +0000 |
2657 | @@ -0,0 +1,1 @@ |
2658 | +fn:format-number( 1, "." ) |
2659 | |
2660 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoActivePassiveActive.spec' |
2661 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoActivePassiveActive.spec 1970-01-01 00:00:00 +0000 |
2662 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoActivePassiveActive.spec 2013-04-11 17:02:25 +0000 |
2663 | @@ -0,0 +1,1 @@ |
2664 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2665 | |
2666 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoActivePassiveActive.xq' |
2667 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoActivePassiveActive.xq 1970-01-01 00:00:00 +0000 |
2668 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoActivePassiveActive.xq 2013-04-11 17:02:25 +0000 |
2669 | @@ -0,0 +1,1 @@ |
2670 | +fn:format-number( .14, "1%1" ) |
2671 | |
2672 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-1.spec' |
2673 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-1.spec 1970-01-01 00:00:00 +0000 |
2674 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-1.spec 2013-04-11 17:02:25 +0000 |
2675 | @@ -0,0 +1,1 @@ |
2676 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2677 | |
2678 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-1.xq' |
2679 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-1.xq 1970-01-01 00:00:00 +0000 |
2680 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-1.xq 2013-04-11 17:02:25 +0000 |
2681 | @@ -0,0 +1,1 @@ |
2682 | +fn:format-number( 1, "1,." ) |
2683 | |
2684 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-2.spec' |
2685 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-2.spec 1970-01-01 00:00:00 +0000 |
2686 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-2.spec 2013-04-11 17:02:25 +0000 |
2687 | @@ -0,0 +1,1 @@ |
2688 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2689 | |
2690 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-2.xq' |
2691 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-2.xq 1970-01-01 00:00:00 +0000 |
2692 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoDecimalGroupingAdjacent-2.xq 2013-04-11 17:02:25 +0000 |
2693 | @@ -0,0 +1,1 @@ |
2694 | +fn:format-number( 1, "1.," ) |
2695 | |
2696 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoMandatoryDigitAfterOpt.spec' |
2697 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoMandatoryDigitAfterOpt.spec 1970-01-01 00:00:00 +0000 |
2698 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoMandatoryDigitAfterOpt.spec 2013-04-11 17:02:25 +0000 |
2699 | @@ -0,0 +1,1 @@ |
2700 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2701 | |
2702 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoMandatoryDigitAfterOpt.xq' |
2703 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoMandatoryDigitAfterOpt.xq 1970-01-01 00:00:00 +0000 |
2704 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoMandatoryDigitAfterOpt.xq 2013-04-11 17:02:25 +0000 |
2705 | @@ -0,0 +1,1 @@ |
2706 | +fn:format-number( 1, "0.#0" ) |
2707 | |
2708 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoOptDigitAfterMandatory.spec' |
2709 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoOptDigitAfterMandatory.spec 1970-01-01 00:00:00 +0000 |
2710 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoOptDigitAfterMandatory.spec 2013-04-11 17:02:25 +0000 |
2711 | @@ -0,0 +1,1 @@ |
2712 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2713 | |
2714 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoOptDigitAfterMandatory.xq' |
2715 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoOptDigitAfterMandatory.xq 1970-01-01 00:00:00 +0000 |
2716 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoOptDigitAfterMandatory.xq 2013-04-11 17:02:25 +0000 |
2717 | @@ -0,0 +1,1 @@ |
2718 | +fn:format-number( 1, "0#" ) |
2719 | |
2720 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-1.spec' |
2721 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-1.spec 1970-01-01 00:00:00 +0000 |
2722 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-1.spec 2013-04-11 17:02:25 +0000 |
2723 | @@ -0,0 +1,1 @@ |
2724 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2725 | |
2726 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-1.xq' |
2727 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-1.xq 1970-01-01 00:00:00 +0000 |
2728 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-1.xq 2013-04-11 17:02:25 +0000 |
2729 | @@ -0,0 +1,1 @@ |
2730 | +fn:format-number( .014, "1%‰" ) |
2731 | |
2732 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-2.spec' |
2733 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-2.spec 1970-01-01 00:00:00 +0000 |
2734 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-2.spec 2013-04-11 17:02:25 +0000 |
2735 | @@ -0,0 +1,1 @@ |
2736 | +Error: http://www.w3.org/2005/xqt-errors:FODF1310 |
2737 | |
2738 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-2.xq' |
2739 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-2.xq 1970-01-01 00:00:00 +0000 |
2740 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-NoPercentPermille-2.xq 2013-04-11 17:02:25 +0000 |
2741 | @@ -0,0 +1,1 @@ |
2742 | +fn:format-number( .014, "1‰%" ) |
2743 | |
2744 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-01.xq' |
2745 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-01.xq 1970-01-01 00:00:00 +0000 |
2746 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-01.xq 2013-04-11 17:02:25 +0000 |
2747 | @@ -0,0 +1,5 @@ |
2748 | +declare decimal-format local:de |
2749 | + decimal-separator = "," |
2750 | + grouping-separator = "."; |
2751 | + |
2752 | +fn:format-number( 1234.567, "#.###,##", "local:de" ) eq "1.234,57" |
2753 | |
2754 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-02.xq' |
2755 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-02.xq 1970-01-01 00:00:00 +0000 |
2756 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-02.xq 2013-04-11 17:02:25 +0000 |
2757 | @@ -0,0 +1,3 @@ |
2758 | +declare decimal-format local:th zero-digit = "๐"; |
2759 | + |
2760 | +fn:format-number( 1234.567, "#,###.##", "local:th" ) eq "๑,๒๓๔.๕๗" |
2761 | |
2762 | === added file 'test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-03.xq' |
2763 | --- test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-03.xq 1970-01-01 00:00:00 +0000 |
2764 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-decimal-format-03.xq 2013-04-11 17:02:25 +0000 |
2765 | @@ -0,0 +1,3 @@ |
2766 | +declare default decimal-format infinity = "off-the-scale"; |
2767 | + |
2768 | +fn:format-number( 1 div 0e0, "###############################" ) eq "off-the-scale" |
2769 | |
2770 | === renamed file 'test/rbkt/Queries/zorba/numerics/format-number2.xq' => 'test/rbkt/Queries/zorba/numerics/format-number/format-number-empty.xq' |
2771 | --- test/rbkt/Queries/zorba/numerics/format-number2.xq 2013-02-07 17:24:36 +0000 |
2772 | +++ test/rbkt/Queries/zorba/numerics/format-number/format-number-empty.xq 2013-04-11 17:02:25 +0000 |
2773 | @@ -1,1 +1,1 @@ |
2774 | -fn:format-number((), "0") |
2775 | +fn:format-number( (), "0" ) eq "NaN" |
2776 | |
2777 | === removed file 'test/rbkt/Queries/zorba/numerics/format-number1.xq' |
2778 | --- test/rbkt/Queries/zorba/numerics/format-number1.xq 2013-02-07 17:24:36 +0000 |
2779 | +++ test/rbkt/Queries/zorba/numerics/format-number1.xq 1970-01-01 00:00:00 +0000 |
2780 | @@ -1,1 +0,0 @@ |
2781 | -fn:format-number(1, ""), fn:format-number(12, "0") |
Validation queue starting for merge proposal. zorbatest. lambda. nu:8080/ remotequeue/ bug-1123164- 2013-04- 11T00-44- 07.14Z/ log.html
Log at: http://