Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba
- pjl-misc
- Merge into trunk
Proposed by
Paul J. Lucas
Status: | Merged |
---|---|
Approved by: | Matthias Brantner |
Approved revision: | 11029 |
Merged at revision: | 11177 |
Proposed branch: | lp:~paul-lucas/zorba/pjl-misc |
Merge into: | lp:zorba |
Diff against target: |
412 lines (+190/-91) 2 files modified
src/util/string_util.cpp (+63/-56) src/util/string_util.h (+127/-35) |
To merge this branch: | bzr merge lp:~paul-lucas/zorba/pjl-misc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthias Brantner | Approve | ||
Paul J. Lucas | Approve | ||
Review via email: mp+142815@code.launchpad.net |
Commit message
aton() enhancement.
Description of the change
aton() enhancement.
To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : | # |
Revision history for this message
Paul J. Lucas (paul-lucas) : | # |
review:
Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job pjl-misc-
All tests succeeded!
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : | # |
Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve.
Revision history for this message
Matthias Brantner (matthias-brantner) : | # |
review:
Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job pjl-misc-
All tests succeeded!
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/util/string_util.cpp' | |||
2 | --- src/util/string_util.cpp 2013-01-07 14:49:20 +0000 | |||
3 | +++ src/util/string_util.cpp 2013-01-10 23:41:23 +0000 | |||
4 | @@ -21,6 +21,7 @@ | |||
5 | 21 | #include "ascii_util.h" | 21 | #include "ascii_util.h" |
6 | 22 | #include "cxx_util.h" | 22 | #include "cxx_util.h" |
7 | 23 | #include "string_util.h" | 23 | #include "string_util.h" |
8 | 24 | #include "zorbatypes/zstring.h" | ||
9 | 24 | 25 | ||
10 | 25 | #ifdef WIN32 | 26 | #ifdef WIN32 |
11 | 26 | namespace std { | 27 | namespace std { |
12 | @@ -55,67 +56,73 @@ | |||
13 | 55 | 56 | ||
14 | 56 | /////////////////////////////////////////////////////////////////////////////// | 57 | /////////////////////////////////////////////////////////////////////////////// |
15 | 57 | 58 | ||
20 | 58 | #define ENABLE_CLIPPING 0 | 59 | static void check_errno( char const *buf, char const *end ) { |
17 | 59 | |||
18 | 60 | template<typename T> | ||
19 | 61 | static void check_parse_number( char const *s, char *end, T *result ) { | ||
21 | 62 | if ( errno == ERANGE ) { | 60 | if ( errno == ERANGE ) { |
33 | 63 | if ( result ) { | 61 | zstring const s( buf, end ); |
34 | 64 | #if ENABLE_CLIPPING | 62 | throw std::range_error( |
35 | 65 | if ( *ascii::trim_start_whitespace( s ) == '-' ) | 63 | BUILD_STRING( '"', s, "\": number too big/small" ) |
36 | 66 | *result = numeric_limits<T>::min(); | 64 | ); |
26 | 67 | else | ||
27 | 68 | *result = numeric_limits<T>::max(); | ||
28 | 69 | #endif /* ENABLE_CLIPPING */ | ||
29 | 70 | } else | ||
30 | 71 | throw std::range_error( | ||
31 | 72 | BUILD_STRING( '"', s, "\": number too big/small" ) | ||
32 | 73 | ); | ||
37 | 74 | } | 65 | } |
72 | 75 | if ( end == s ) | 66 | } |
73 | 76 | throw std::invalid_argument( BUILD_STRING( '"', s, "\": no digits" ) ); | 67 | |
74 | 77 | for ( ; *end; ++end ) // remaining characters, if any, ... | 68 | static void check_parse_number( char const *buf, char const *end, |
75 | 78 | if ( !ascii::is_space( *end ) ) // ... may only be whitespace | 69 | bool check_trailing_chars ) { |
76 | 79 | throw std::invalid_argument( | 70 | if ( end == buf ) |
77 | 80 | BUILD_STRING( '"', *end, "\": invalid character" ) | 71 | throw std::invalid_argument( BUILD_STRING( '"', buf, "\": no digits" ) ); |
78 | 81 | ); | 72 | if ( check_trailing_chars ) |
79 | 82 | } | 73 | for ( ; *end; ++end ) // remaining characters, if any, ... |
80 | 83 | 74 | if ( !ascii::is_space( *end ) ) // ... may only be whitespace | |
81 | 84 | double atod( char const *s ) { | 75 | throw std::invalid_argument( |
82 | 85 | char *end; | 76 | BUILD_STRING( '"', *end, "\": invalid character" ) |
83 | 86 | errno = 0; | 77 | ); |
84 | 87 | double result = std::strtod( s, &end ); | 78 | } |
85 | 88 | check_parse_number( s, end, &result ); | 79 | |
86 | 89 | return result; | 80 | #define ATON_PREAMBLE() \ |
87 | 90 | } | 81 | bool check_trailing_chars; \ |
88 | 91 | 82 | char const *pc; \ | |
89 | 92 | float atof( char const *s ) { | 83 | if ( end ) { \ |
90 | 93 | char *end; | 84 | check_trailing_chars = false; \ |
91 | 94 | errno = 0; | 85 | } else { \ |
92 | 95 | float result = std::strtof( s, &end ); | 86 | end = &pc; \ |
93 | 96 | check_parse_number( s, end, &result ); | 87 | check_trailing_chars = true; \ |
94 | 97 | return result; | 88 | } \ |
95 | 98 | } | 89 | errno = 0 |
96 | 99 | 90 | ||
97 | 100 | long long atoll( char const *s ) { | 91 | /////////////////////////////////////////////////////////////////////////////// |
98 | 101 | char *end; | 92 | |
99 | 102 | errno = 0; | 93 | double atod( char const *buf, char const **end ) { |
100 | 103 | long long const result = std::strtoll( s, &end, 10 ); | 94 | ATON_PREAMBLE(); |
101 | 104 | check_parse_number( s, end, static_cast<long long*>( nullptr ) ); | 95 | double const result = std::strtod( buf, (char**)end ); |
102 | 105 | return result; | 96 | check_parse_number( buf, *end, check_trailing_chars ); |
103 | 106 | } | 97 | return result; |
104 | 107 | 98 | } | |
105 | 108 | unsigned long long atoull( char const *s ) { | 99 | |
106 | 100 | float atof( char const *buf, char const **end ) { | ||
107 | 101 | ATON_PREAMBLE(); | ||
108 | 102 | float const result = std::strtof( buf, (char**)end ); | ||
109 | 103 | check_parse_number( buf, *end, check_trailing_chars ); | ||
110 | 104 | return result; | ||
111 | 105 | } | ||
112 | 106 | |||
113 | 107 | long long atoll( char const *buf, char const **end ) { | ||
114 | 108 | ATON_PREAMBLE(); | ||
115 | 109 | long long const result = std::strtoll( buf, (char**)end, 10 ); | ||
116 | 110 | check_errno( buf, *end ); | ||
117 | 111 | check_parse_number( buf, *end, check_trailing_chars ); | ||
118 | 112 | return result; | ||
119 | 113 | } | ||
120 | 114 | |||
121 | 115 | unsigned long long atoull( char const *buf, char const **end ) { | ||
122 | 116 | ATON_PREAMBLE(); | ||
123 | 109 | // | 117 | // |
124 | 110 | // We have to check for '-' ourselves since strtoull(3) allows it (oddly). | 118 | // We have to check for '-' ourselves since strtoull(3) allows it (oddly). |
125 | 111 | // | 119 | // |
128 | 112 | s = ascii::trim_start_whitespace( s ); | 120 | buf = ascii::trim_start_whitespace( buf ); |
129 | 113 | bool const minus = *s == '-'; | 121 | bool const minus = *buf == '-'; |
130 | 114 | 122 | ||
135 | 115 | char *end; | 123 | unsigned long long const result = std::strtoull( buf, (char**)end, 10 ); |
136 | 116 | errno = 0; | 124 | check_errno( buf, *end ); |
137 | 117 | unsigned long long const result = std::strtoull( s, &end, 10 ); | 125 | check_parse_number( buf, *end, check_trailing_chars ); |
134 | 118 | check_parse_number( s, end, static_cast<unsigned long long*>( nullptr ) ); | ||
138 | 119 | 126 | ||
139 | 120 | if ( minus && result ) { | 127 | if ( minus && result ) { |
140 | 121 | // | 128 | // |
141 | @@ -123,7 +130,7 @@ | |||
142 | 123 | // Hence, this allows "-0" and treats it as "0". | 130 | // Hence, this allows "-0" and treats it as "0". |
143 | 124 | // | 131 | // |
144 | 125 | throw std::invalid_argument( | 132 | throw std::invalid_argument( |
146 | 126 | "\"-\": invalid character for unsigned integer" | 133 | "'-': invalid character for unsigned integer" |
147 | 127 | ); | 134 | ); |
148 | 128 | } | 135 | } |
149 | 129 | return result; | 136 | return result; |
150 | 130 | 137 | ||
151 | === modified file 'src/util/string_util.h' | |||
152 | --- src/util/string_util.h 2013-01-07 14:49:20 +0000 | |||
153 | +++ src/util/string_util.h 2013-01-10 23:41:23 +0000 | |||
154 | @@ -408,61 +408,76 @@ | |||
155 | 408 | /** | 408 | /** |
156 | 409 | * Parses the given string for a \c double. | 409 | * Parses the given string for a \c double. |
157 | 410 | * | 410 | * |
159 | 411 | * @param s The null-terminated C string to parse. Leading and trailing | 411 | * @param buf The null-terminated C string to parse. Leading and trailing |
160 | 412 | * whitespace is ignored. | 412 | * whitespace is ignored. |
161 | 413 | * @param end If not \c null, this is set to point to the character after the | ||
162 | 414 | * last numeric character parsed; if \c null, characters past the last numeric | ||
163 | 415 | * character may only be whitespace. | ||
164 | 413 | * @return Returns the \c double value. | 416 | * @return Returns the \c double value. |
166 | 414 | * @throws invalid_argument if \a s contains characters other than digits or | 417 | * @throws invalid_argument if \a buf contains characters other than digits or |
167 | 415 | * leading/trailing whitespace, or contains no digits at all. | 418 | * leading/trailing whitespace, or contains no digits at all. |
168 | 416 | * @throws range_error if the number overflows/underflows. | 419 | * @throws range_error if the number overflows/underflows. |
169 | 417 | */ | 420 | */ |
171 | 418 | double atod( char const *s ); | 421 | double atod( char const *buf, char const **end = nullptr ); |
172 | 419 | 422 | ||
173 | 420 | /** | 423 | /** |
174 | 421 | * Parses the given string for a \c float. | 424 | * Parses the given string for a \c float. |
175 | 422 | * | 425 | * |
177 | 423 | * @param s The null-terminated C string to parse. Leading and trailing | 426 | * @param buf The null-terminated C string to parse. Leading and trailing |
178 | 424 | * whitespace is ignored. | 427 | * whitespace is ignored. |
179 | 428 | * @param end If not \c null, this is set to point to the character after the | ||
180 | 429 | * last numeric character parsed; if \c null, characters past the last numeric | ||
181 | 430 | * character may only be whitespace. | ||
182 | 425 | * @return Returns the \c float value. | 431 | * @return Returns the \c float value. |
184 | 426 | * @throws invalid_argument if \a s contains characters other than digits or | 432 | * @throws invalid_argument if \a buf contains characters other than digits or |
185 | 427 | * leading/trailing whitespace, or contains no digits at all. | 433 | * leading/trailing whitespace, or contains no digits at all. |
186 | 428 | * @throws range_error if the number overflows/underflows. | 434 | * @throws range_error if the number overflows/underflows. |
187 | 429 | */ | 435 | */ |
189 | 430 | float atof( char const *s ); | 436 | float atof( char const *buf, char const **end = nullptr ); |
190 | 431 | 437 | ||
191 | 432 | /** | 438 | /** |
192 | 433 | * Parses the given string for a <code>long lomg</code>. | 439 | * Parses the given string for a <code>long lomg</code>. |
193 | 434 | * | 440 | * |
195 | 435 | * @param s The null-terminated C string to parse. Leading and trailing | 441 | * @param buf The null-terminated C string to parse. Leading and trailing |
196 | 436 | * whitespace is ignored. | 442 | * whitespace is ignored. |
197 | 443 | * @param end If not \c null, this is set to point to the character after the | ||
198 | 444 | * last numeric character parsed; if \c null, characters past the last numeric | ||
199 | 445 | * character may only be whitespace. | ||
200 | 437 | * @return Returns the <code>long long</code> value. | 446 | * @return Returns the <code>long long</code> value. |
202 | 438 | * @throws invalid_argument if \a s contains characters other than digits or | 447 | * @throws invalid_argument if \a buf contains characters other than digits or |
203 | 439 | * leading/trailing whitespace, or contains no digits at all. | 448 | * leading/trailing whitespace, or contains no digits at all. |
204 | 440 | * @throws range_error if the number overflows/underflows. | 449 | * @throws range_error if the number overflows/underflows. |
205 | 441 | */ | 450 | */ |
207 | 442 | long long atoll( char const *s ); | 451 | long long atoll( char const *buf, char const **end = nullptr ); |
208 | 443 | 452 | ||
209 | 444 | /** | 453 | /** |
210 | 445 | * Parses the given string for an <code>unsigned long lomg</code>. | 454 | * Parses the given string for an <code>unsigned long lomg</code>. |
211 | 446 | * | 455 | * |
213 | 447 | * @param s The null-terminated C string to parse. Leading and trailing | 456 | * @param buf The null-terminated C string to parse. Leading and trailing |
214 | 448 | * whitespace is ignored. | 457 | * whitespace is ignored. |
215 | 458 | * @param end If not \c null, this is set to point to the character after the | ||
216 | 459 | * last numeric character parsed; if \c null, characters past the last numeric | ||
217 | 460 | * character may only be whitespace. | ||
218 | 449 | * @return Returns the <code>unsigned long long</code> value. | 461 | * @return Returns the <code>unsigned long long</code> value. |
220 | 450 | * @throws invalid_argument if \a s contains characters other than digits or | 462 | * @throws invalid_argument if \a buf contains characters other than digits or |
221 | 451 | * leading/trailing whitespace, or contains no digits at all. | 463 | * leading/trailing whitespace, or contains no digits at all. |
222 | 452 | * @throws range_error if the number overflows/underflows. | 464 | * @throws range_error if the number overflows/underflows. |
223 | 453 | */ | 465 | */ |
225 | 454 | unsigned long long atoull( char const *s ); | 466 | unsigned long long atoull( char const *buf, char const **end = nullptr ); |
226 | 455 | 467 | ||
227 | 456 | /** | 468 | /** |
228 | 457 | * Parses the given string for a C++ signed integral type. | 469 | * Parses the given string for a C++ signed integral type. |
229 | 458 | * | 470 | * |
230 | 459 | * @tparam IntegralType The C++ signed integral type to parse for. | 471 | * @tparam IntegralType The C++ signed integral type to parse for. |
232 | 460 | * @param s The null-terminated C string to parse. Leading and trailing | 472 | * @param buf The null-terminated C string to parse. Leading and trailing |
233 | 461 | * whitespace is ignored. | 473 | * whitespace is ignored. |
234 | 474 | * @param end If not \c null, this is set to point to the character after the | ||
235 | 475 | * last numeric character parsed; if \c null, characters past the last numeric | ||
236 | 476 | * character may only be whitespace. | ||
237 | 462 | * @return Returns the \c IntegralType value. | 477 | * @return Returns the \c IntegralType value. |
241 | 463 | * @throws invalid_argument if \a s contains characters other than digits or | 478 | * @throws invalid_argument if \a buf contains characters other than digits, a |
242 | 464 | * leading/trailing whitespace, or contains no digits at all. | 479 | * sign, or leading/trailing whitespace, or contains no digits at all. |
243 | 465 | * @throws range_error if the number overflows/underflows. | 480 | * @throws range_error if the number is either too small or too big. |
244 | 466 | */ | 481 | */ |
245 | 467 | template<typename IntegralType> inline | 482 | template<typename IntegralType> inline |
246 | 468 | // | 483 | // |
247 | @@ -473,8 +488,8 @@ | |||
248 | 473 | typename std::enable_if<ZORBA_TR1_NS::is_integral<IntegralType>::value | 488 | typename std::enable_if<ZORBA_TR1_NS::is_integral<IntegralType>::value |
249 | 474 | && ZORBA_TR1_NS::is_signed<IntegralType>::value, | 489 | && ZORBA_TR1_NS::is_signed<IntegralType>::value, |
250 | 475 | IntegralType>::type | 490 | IntegralType>::type |
253 | 476 | aton( char const *s ) { | 491 | aton( char const *buf, char const **end = nullptr ) { |
254 | 477 | long long const result = atoll( s ); | 492 | long long const result = atoll( buf, end ); |
255 | 478 | if ( result < std::numeric_limits<IntegralType>::min() || | 493 | if ( result < std::numeric_limits<IntegralType>::min() || |
256 | 479 | result > std::numeric_limits<IntegralType>::max() ) | 494 | result > std::numeric_limits<IntegralType>::max() ) |
257 | 480 | throw std::range_error( | 495 | throw std::range_error( |
258 | @@ -484,60 +499,137 @@ | |||
259 | 484 | } | 499 | } |
260 | 485 | 500 | ||
261 | 486 | /** | 501 | /** |
262 | 502 | * Parses the given string for a C++ signed integral type. | ||
263 | 503 | * | ||
264 | 504 | * @tparam IntegralType The C++ signed integral type to parse for. | ||
265 | 505 | * @param buf The null-terminated C string to parse. Leading and trailing | ||
266 | 506 | * whitespace is ignored. | ||
267 | 507 | * @param low The lower acceptable bound. | ||
268 | 508 | * @param high the higher acceptable bound. | ||
269 | 509 | * @param end If not \c null, this is set to point to the character after the | ||
270 | 510 | * last numeric character parsed; if \c null, characters past the last numeric | ||
271 | 511 | * character may only be whitespace. | ||
272 | 512 | * @return Returns the \c IntegralType value. | ||
273 | 513 | * @throws invalid_argument if \a buf contains characters other than digits, a | ||
274 | 514 | * sign, or leading/trailing whitespace, or contains no digits at all. | ||
275 | 515 | * @throws range_error if the number is either too small or too big. | ||
276 | 516 | */ | ||
277 | 517 | template<typename IntegralType> inline | ||
278 | 518 | // | ||
279 | 519 | // Note that the is_integral shouldn't be needed since is_signed means "is a | ||
280 | 520 | // signed integral type", but Microsoft's implementation is broken and returns | ||
281 | 521 | // true for floating point types as well. | ||
282 | 522 | // | ||
283 | 523 | typename std::enable_if<ZORBA_TR1_NS::is_integral<IntegralType>::value | ||
284 | 524 | && ZORBA_TR1_NS::is_signed<IntegralType>::value, | ||
285 | 525 | IntegralType>::type | ||
286 | 526 | aton( char const *buf, IntegralType low, IntegralType high, | ||
287 | 527 | char const **end = nullptr ) { | ||
288 | 528 | long long const result = atoll( buf, end ); | ||
289 | 529 | if ( result < low || result > high ) | ||
290 | 530 | throw std::range_error( | ||
291 | 531 | BUILD_STRING( | ||
292 | 532 | '"', result, "\": number not in range ", low, '-', high | ||
293 | 533 | ) | ||
294 | 534 | ); | ||
295 | 535 | return static_cast<IntegralType>( result ); | ||
296 | 536 | } | ||
297 | 537 | |||
298 | 538 | /** | ||
299 | 487 | * Parses the given string for a C++ unsigned integral types. | 539 | * Parses the given string for a C++ unsigned integral types. |
300 | 488 | * | 540 | * |
301 | 489 | * @tparam IntegralType The C++ unsigned integral type to parse for. | 541 | * @tparam IntegralType The C++ unsigned integral type to parse for. |
303 | 490 | * @param s The null-terminated C string to parse. Leading and trailing | 542 | * @param buf The null-terminated C string to parse. Leading and trailing |
304 | 491 | * whitespace is ignored. | 543 | * whitespace is ignored. |
305 | 544 | * @param end If not \c null, this is set to point to the character after the | ||
306 | 545 | * last numeric character parsed; if \c null, characters past the last numeric | ||
307 | 546 | * character may only be whitespace. | ||
308 | 492 | * @return Returns the \c IntegralType value. | 547 | * @return Returns the \c IntegralType value. |
312 | 493 | * @throws invalid_argument if \a s contains characters other than digits or | 548 | * @throws invalid_argument if \a buf contains characters other than digits, a |
313 | 494 | * leading/trailing whitespace, or contains no digits at all. | 549 | * sign, or leading/trailing whitespace, or contains no digits at all. |
314 | 495 | * @throws range_error if the number overflows/underflows. | 550 | * @throws range_error if the number is either too small or too big. |
315 | 496 | */ | 551 | */ |
316 | 497 | template<typename IntegralType> inline | 552 | template<typename IntegralType> inline |
317 | 498 | typename std::enable_if<ZORBA_TR1_NS::is_unsigned<IntegralType>::value, | 553 | typename std::enable_if<ZORBA_TR1_NS::is_unsigned<IntegralType>::value, |
318 | 499 | IntegralType>::type | 554 | IntegralType>::type |
321 | 500 | aton( char const *s ) { | 555 | aton( char const *buf, char const **end = nullptr ) { |
322 | 501 | unsigned long long const result = atoull( s ); | 556 | unsigned long long const result = atoull( buf, end ); |
323 | 502 | if ( result > std::numeric_limits<IntegralType>::max() ) | 557 | if ( result > std::numeric_limits<IntegralType>::max() ) |
324 | 503 | throw std::range_error( BUILD_STRING( '"', result, "\": number too big" ) ); | 558 | throw std::range_error( BUILD_STRING( '"', result, "\": number too big" ) ); |
325 | 504 | return static_cast<IntegralType>( result ); | 559 | return static_cast<IntegralType>( result ); |
326 | 505 | } | 560 | } |
327 | 506 | 561 | ||
328 | 507 | /** | 562 | /** |
329 | 563 | * Parses the given string for a C++ unsigned integral types. | ||
330 | 564 | * | ||
331 | 565 | * @tparam IntegralType The C++ unsigned integral type to parse for. | ||
332 | 566 | * @param buf The null-terminated C string to parse. Leading and trailing | ||
333 | 567 | * whitespace is ignored. | ||
334 | 568 | * @param low The lower acceptable bound. | ||
335 | 569 | * @param high the higher acceptable bound. | ||
336 | 570 | * @param end If not \c null, this is set to point to the character after the | ||
337 | 571 | * last numeric character parsed; if \c null, characters past the last numeric | ||
338 | 572 | * character may only be whitespace. | ||
339 | 573 | * @return Returns the \c IntegralType value. | ||
340 | 574 | * @throws invalid_argument if \a buf contains characters other than digits or | ||
341 | 575 | * leading/trailing whitespace, or contains no digits at all. | ||
342 | 576 | * @throws range_error if the number is either too small or too big. | ||
343 | 577 | */ | ||
344 | 578 | template<typename IntegralType> inline | ||
345 | 579 | typename std::enable_if<ZORBA_TR1_NS::is_unsigned<IntegralType>::value, | ||
346 | 580 | IntegralType>::type | ||
347 | 581 | aton( char const *buf, IntegralType low, IntegralType high, | ||
348 | 582 | char const **end = nullptr ) { | ||
349 | 583 | unsigned long long const result = atoull( buf, end ); | ||
350 | 584 | if ( result < low || result > high ) | ||
351 | 585 | throw std::range_error( | ||
352 | 586 | BUILD_STRING( | ||
353 | 587 | '"', result, "\": number not in range ", low, '-', high | ||
354 | 588 | ) | ||
355 | 589 | ); | ||
356 | 590 | return static_cast<IntegralType>( result ); | ||
357 | 591 | } | ||
358 | 592 | |||
359 | 593 | /** | ||
360 | 508 | * Parses the given string for a C++ \c double type. | 594 | * Parses the given string for a C++ \c double type. |
361 | 509 | * | 595 | * |
363 | 510 | * @param s The null-terminated C string to parse. Leading and trailing | 596 | * @param buf The null-terminated C string to parse. Leading and trailing |
364 | 511 | * whitespace is ignored. | 597 | * whitespace is ignored. |
365 | 598 | * @param end If not \c null, this is set to point to the character after the | ||
366 | 599 | * last numeric character parsed; if \c null, characters past the last numeric | ||
367 | 600 | * character may only be whitespace. | ||
368 | 512 | * @return Returns the \c double value. | 601 | * @return Returns the \c double value. |
372 | 513 | * @throws invalid_argument if \a s contains characters other than those for a | 602 | * @throws invalid_argument if \a buf contains characters other than those for |
373 | 514 | * valid \c double value or leading/trailing whitespace, or contains no digits | 603 | * a valid \c double value or leading/trailing whitespace, or contains no |
374 | 515 | * at all. | 604 | * digits at all. |
375 | 516 | * @throws range_error if the number overflows/underflows. | 605 | * @throws range_error if the number overflows/underflows. |
376 | 517 | */ | 606 | */ |
377 | 518 | template<typename NumericType> inline | 607 | template<typename NumericType> inline |
378 | 519 | typename std::enable_if<ZORBA_TR1_NS::is_same<NumericType,double>::value, | 608 | typename std::enable_if<ZORBA_TR1_NS::is_same<NumericType,double>::value, |
379 | 520 | NumericType>::type | 609 | NumericType>::type |
382 | 521 | aton( char const *s ) { | 610 | aton( char const *buf, char const **end = nullptr ) { |
383 | 522 | return atod( s ); | 611 | return atod( buf, end ); |
384 | 523 | } | 612 | } |
385 | 524 | 613 | ||
386 | 525 | /** | 614 | /** |
387 | 526 | * Parses the given string for a C++ \c float type. | 615 | * Parses the given string for a C++ \c float type. |
388 | 527 | * | 616 | * |
390 | 528 | * @param s The null-terminated C string to parse. Leading and trailing | 617 | * @param buf The null-terminated C string to parse. Leading and trailing |
391 | 529 | * whitespace is ignored. | 618 | * whitespace is ignored. |
392 | 619 | * @param end If not \c null, this is set to point to the character after the | ||
393 | 620 | * last numeric character parsed; if \c null, characters past the last numeric | ||
394 | 621 | * character may only be whitespace. | ||
395 | 530 | * @return Returns the \c float value. | 622 | * @return Returns the \c float value. |
398 | 531 | * @throws invalid_argument if \a s contains characters other than those for a | 623 | * @throws invalid_argument if \a buf contains characters other than those for |
399 | 532 | * valid \c float value or leading/trailing whitespace, or contains no digits | 624 | * a valid \c float value or leading/trailing whitespace, or contains no digits |
400 | 533 | * at all. | 625 | * at all. |
401 | 534 | * @throws range_error if the number overflows/underflows. | 626 | * @throws range_error if the number overflows/underflows. |
402 | 535 | */ | 627 | */ |
403 | 536 | template<typename NumericType> inline | 628 | template<typename NumericType> inline |
404 | 537 | typename std::enable_if<ZORBA_TR1_NS::is_same<NumericType,float>::value, | 629 | typename std::enable_if<ZORBA_TR1_NS::is_same<NumericType,float>::value, |
405 | 538 | NumericType>::type | 630 | NumericType>::type |
408 | 539 | aton( char const *s ) { | 631 | aton( char const *buf, char const **end = nullptr ) { |
409 | 540 | return atof( s ); | 632 | return atof( buf, end ); |
410 | 541 | } | 633 | } |
411 | 542 | 634 | ||
412 | 543 | ////////// To-string conversion //////////////////////////////////////////////// | 635 | ////////// To-string conversion //////////////////////////////////////////////// |
Validation queue starting for merge proposal. zorbatest. lambda. nu:8080/ remotequeue/ pjl-misc- 2013-01- 10T23-45- 42.555Z/ log.html
Log at: http://