BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlb_numericparseutil.h
Go to the documentation of this file.
1/// @file bdlb_numericparseutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlb_numericparseutil.h -*-C++-*-
8#ifndef INCLUDED_BDLB_NUMERICPARSEUTIL
9#define INCLUDED_BDLB_NUMERICPARSEUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlb_numericparseutil bdlb_numericparseutil
15/// @brief Provide conversions from text into fundamental numeric types.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlb
19/// @{
20/// @addtogroup bdlb_numericparseutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlb_numericparseutil-purpose"> Purpose</a>
25/// * <a href="#bdlb_numericparseutil-classes"> Classes </a>
26/// * <a href="#bdlb_numericparseutil-description"> Description </a>
27/// * <a href="#bdlb_numericparseutil-definition-of-symbols-used-in-production-rules"> Definition of Symbols Used in Production Rules </a>
28/// * <a href="#bdlb_numericparseutil-grammar-production-rules"> Grammar Production Rules </a>
29/// * <a href="#bdlb_numericparseutil-remainder-output-parameter"> Remainder Output Parameter </a>
30/// * <a href="#bdlb_numericparseutil-floating-point-values"> Floating Point Values </a>
31/// * <a href="#bdlb_numericparseutil-special-floating-point-values"> Special Floating Point Values </a>
32/// * <a href="#bdlb_numericparseutil-usage-example"> Usage Example </a>
33/// * <a href="#bdlb_numericparseutil-example-1-parsing-an-integer-value-from-a-string_view"> Example 1: Parsing an Integer Value from a string_view </a>
34///
35/// # Purpose {#bdlb_numericparseutil-purpose}
36/// Provide conversions from text into fundamental numeric types.
37///
38/// # Classes {#bdlb_numericparseutil-classes}
39///
40/// - bdlb::NumericParseUtil: namespace for parsing functions
41///
42/// # Description {#bdlb_numericparseutil-description}
43/// This component provides a namespace, `bdlb::NumericParseUtil`,
44/// containing utility functions for parsing ascii text representations of
45/// numeric values into the corresponding value of a fundamental C++ type (like
46/// `int` or `double`).
47///
48/// None of the parsing functions in this component consume leading whitespace.
49/// For parsing to succeed, the sought item must be found at the beginning of
50/// the input string.
51///
52/// The following two subsections describe the grammar defining the parsing
53/// rules.
54///
55/// ## Definition of Symbols Used in Production Rules {#bdlb_numericparseutil-definition-of-symbols-used-in-production-rules}
56///
57///
58///
59/// The following grammar is used to specify regular expressions:
60/// @code
61/// - Within brackets the minus means through. For example, [a-z] is
62/// equivalent to [abcd...xyz]. The - can appear as itself only if used
63/// as the first or last character. For example, the character class
64/// expression []-] matches the characters ] and -.
65///
66/// | Logical OR between two expressions means one must be present.
67///
68/// ( ... ) Parentheses are used for grouping. An operator, for example, *,
69/// +, {}, can work on a single character or on a regular expression
70/// enclosed in parentheses. For example, (a*(cb+)*)$.
71/// @endcode
72///
73/// ## Grammar Production Rules {#bdlb_numericparseutil-grammar-production-rules}
74///
75///
76/// @code
77/// <NUMBER> ::= <OPTIONAL_SIGN><DIGIT>+
78///
79/// <DECIMAL_NUMBER> ::= <OPTIONAL_SIGN><DECIMAL_DIGIT>+
80///
81/// <POSITIVE_NUMBER> ::= <DIGIT>+
82///
83/// <OPTIONAL_SIGN> ::= (+|-)?
84///
85/// <DIGIT> ::= depending on base can include characters 0-9 and case-
86/// insensitive letters. For example, octal digit is in the range
87/// [0 .. 7].
88///
89/// <DECIMAL_DIGIT> ::= [0123456789]
90/// <OCTAL_DIGIT> ::= [01234567]
91/// <HEX_DIGIT> ::= [0123456789abcdefABCDEF]
92///
93/// <SHORT> ::= <NUMBER>
94/// <SHORT> must be in range [SHRT_MIN .. SHRT_MAX].
95/// <USHORT> ::= <NUMBER>
96/// <USHORT> must be in range [0 .. USHRT_MAX].
97///
98/// <INT> ::= <NUMBER>
99/// <INT> must be in range [INT_MIN .. INT_MAX].
100///
101/// <INT64> ::= <NUMBER>
102/// <INT64> must be in range
103/// [-0x8000000000000000uLL .. 0x7FFFFFFFFFFFFFFFuLL].
104///
105/// <UNSIGNED> ::= <NUMBER>
106/// <UNSIGNED> must be in range [0 .. UINT_MAX].
107///
108/// <UNSIGNED64> ::= <NUMBER>
109/// <UNSIGNED64> must be in range
110/// [0 .. 0xFFFFFFFFFFFFFFFFuLL].
111///
112/// <DECIMAL_EXPONENT> ::= <DECIMAL_NUMBER>
113///
114/// <REAL> ::= (<DECIMAL_DIGIT>+ (. <DECIMAL_DIGIT>*)? | . <DECIMAL_DIGIT>+)
115/// (e|E <DECIMAL_EXPONENT>)
116///
117/// <INF> ::= infinity | inf
118/// all case insensitive
119///
120/// <NAN-SEQUENCE> ::= [abcdefghijklmnopqrstuvwxyz0123456789_]*
121/// case insensitive
122///
123/// <NAN> ::= nan(<NAN-SEQUENCE>) | nan
124/// all case insensitive
125///
126/// <DOUBLE> ::= <OPTIONAL_SIGN> (<REAL> | <INF> | <NAN>)
127/// <DOUBLE> must be in range [DBL_MIN .. DBL_MAX], or Nan, or Infinity.
128/// @endcode
129///
130/// ## Remainder Output Parameter {#bdlb_numericparseutil-remainder-output-parameter}
131///
132///
133/// The parsing functions provided by `bdlb::NumericParseUtil` typically return
134/// an optional, second, output parameter named `remainder`. The output
135/// parameter `remainder` is loaded with a string reference starting at the
136/// character following the last character successfully parsed as part of the
137/// numeric value, and ending at the character one past the end of the input
138/// string. If the entire input string is parsed successfully, `remainder` is
139/// loaded with an empty string reference. However, if the parse function is
140/// not successful (i.e., it returns a non-zero error status), then it will not
141/// modify the value of `remainder`.
142///
143/// ## Floating Point Values {#bdlb_numericparseutil-floating-point-values}
144///
145///
146/// The conversion from text to values of type `double` results in the closest
147/// representable value to the decimal text. Note that this is the same as for
148/// the standard library function `strtod`. For example, the ASCII string
149/// "3.14159" is converted, on some platforms, to 3.1415899999999999.
150///
151/// The `strtod` function is locale-dependent. It uses the `LC_CTYPE` and
152/// `LC_NUMERIC` locale categories from the C standard global locale established
153/// by `setlocale`. `LC_CTYPE` is used by `strtod` to skip leading whitespace,
154/// whereas `LC_NUMERIC` is used in the actual parsing of the number. Our
155/// implementation forbids leading whitespace. When verifying the lack of
156/// leading whitespace we use both our own locale-independent character
157/// classification function (in case `LC_CTYPE` would not classify ASCII
158/// whitespace properly), as well as the C global locale-dependent
159/// `bsl::isspace` to ensure that `strtod` will not skip some special whitespace
160/// characters and parse a string as fully-a-number by mistake. That allows us
161/// to ignore the `LC_CTYPE` locale category, however we still have to require
162/// `LC_NUMERIC` to be set to the "C" locale for `strtod` itself.
163///
164/// ### Special Floating Point Values {#bdlb_numericparseutil-special-floating-point-values}
165///
166///
167/// The IEEE-754 (double precision) floating point format supports the following
168/// special values: Not-a-Number (NaN) and Infinity, both in positive or
169/// negative. `parseDouble` allows expressions for both:
170///
171/// * **infinity-expression**: results in negative of positive
172/// bsl::numeric_limits<double>::infinity() value. The expresssion
173/// consists of the following elements:
174/// - an optional plus (`+`) or minus (`-`) sign
175/// - the word "INF" or "INFINITY", ignoring case
176///
177/// * **not-a-number-expression**: results in a negative or positive
178/// bsl::numeric_limits<double>::quiet_NaN() value. The expresssion consists
179/// of the following elements:
180/// - an optional plus (`+`) or minus (`-`) sign
181/// - "NAN" or "NAN(char-sequence)" ignoring the case of "NAN". The
182/// char-sequence may be empty or contain digits, letters from the Latin
183/// alphabet and underscores.
184///
185/// ## Usage Example {#bdlb_numericparseutil-usage-example}
186///
187///
188/// In this section, we show the intended usage of this component.
189///
190/// ### Example 1: Parsing an Integer Value from a string_view {#bdlb_numericparseutil-example-1-parsing-an-integer-value-from-a-string_view}
191///
192///
193/// Suppose that we have a @ref string_view that presumably contains a (not
194/// necessarily NUL terminated) string representing a 32-bit integer value and
195/// we want to convert that string into an `int` (32-bit integer).
196///
197/// First, we create the string:
198/// @code
199/// const bsl::string_view input("20171024", 4);
200/// @endcode
201/// Then we create the output variables for the parser:
202/// @code
203/// int year;
204/// bsl::string_view rest;
205/// @endcode
206/// Next we call the parser function:
207/// @code
208/// const int rv = bdlb::NumericParseUtil::parseInt(&year, &rest, input);
209/// @endcode
210/// Then we verify the results:
211/// @code
212/// assert(0 == rv);
213/// assert(2017 == year);
214/// assert(rest.empty());
215/// @endcode
216/// @}
217/** @} */
218/** @} */
219
220/** @addtogroup bdl
221 * @{
222 */
223/** @addtogroup bdlb
224 * @{
225 */
226/** @addtogroup bdlb_numericparseutil
227 * @{
228 */
229
230#include <bdlscm_version.h>
231
232#include <bsls_assert.h>
233#include <bsls_types.h>
234
235#include <bsl_string.h>
236#include <bsl_string_view.h>
237
238
239
240namespace bdlb {
241 // =======================
242 // struct NumericParseUtil
243 // =======================
244
245/// This `struct` provides a namespace for a suite of stateless procedures
246/// that perform parsing functionality for numbers.
248
249 public:
250 // TYPES
251
252 /// Shorter name for readability.
254
255 // CLASS METHODS
256
257 /// Determine whether the specified `character` represents a digit in
258 /// the specified `base`; return the numeric equivalent if so, and -1
259 /// otherwise. The behavior is undefined if either `character` or
260 /// `base` is 0 and unless `2 <= base` and `base <= 36` (i.e., bases
261 /// where digits are representable by characters in the range [`0`-`9`],
262 /// [`a`-`z`], or [`A`-`Z`]).
263 static int characterToDigit(char character, int base);
264
265 static int parseDouble(double *result,
266 const bsl::string_view& inputString);
267 /// Parse the specified `inputString` for a sequence of characters
268 /// matching the production rule <DOUBLE> (see {Grammar Production
269 /// Rules}) and place into the specified `result` the corresponding
270 /// value. Optionally specify `remainder`, in which to store the
271 /// remainder of the `inputString` immediately following the
272 /// successfully parsed text, or the position at which a parse failure
273 /// was detected. Return zero on success, and a non-zero value
274 /// otherwise. The value of `result` is unchanged if a parse failure
275 /// occurs unless it is a range error (value `ERANGE` from `<cerrno>`).
276 /// In case of `ERANGE` return value `result` will be set to zero on
277 /// underflow and infinity in case of overflow, with the appropriate
278 /// sign. The behavior is undefined unless the current numeric locale
279 /// is the `"C"` locale, such that
280 /// `strcmp(setlocale(LC_NUMERIC, 0), "C") == 0`. For more information
281 /// see {Floating Point Values}.
282 static int parseDouble(double *result,
283 bsl::string_view *remainder,
284 const bsl::string_view& inputString);
285
286 /// Parse the specified `inputString` for the maximal sequence of
287 /// characters forming an <INT> (see {Grammar Production Rules}) in the
288 /// optionally specified `base` or in base 10 if `base` is not
289 /// specified, and place into the specified `result` the corresponding
290 /// value. Optionally specify `remainder`, in which to store the
291 /// remainder of the `inputString` immediately following the
292 /// successfully parsed text, or the position at which a parse failure
293 /// was detected. If the parsed number is outside of the
294 /// `[INT_MIN .. INT_MAX]` range the `result` will be the longest number
295 /// that does not over/underflow and `remainder` start at the first
296 /// digit that would make the number too large/small. Return zero on
297 /// success, and a non-zero value otherwise. The value of `result` is
298 /// unchanged if a parse failure occurs. The behavior is undefined
299 /// unless `2 <= base` and `base <= 36` (i.e., bases where digits are
300 /// representable by characters in the range [`0`-`9`], [`a`-`z`], or
301 /// [`A`-`Z`]).
302 ///
303 static int parseInt(int *result,
304 const bsl::string_view& inputString,
305 int base = 10);
306 /// A parse failure can occur for the following reasons:
307 /// 1. The `inputString` is empty.
308 /// 2. The first character of `inputString` is not a valid digit in
309 /// `base`, or an optional sign followed by a valid digit.
310 static int parseInt(int *result,
311 bsl::string_view *remainder,
312 const bsl::string_view& inputString,
313 int base = 10);
314
315 /// Parse the specified `inputString` for the maximal sequence of
316 /// characters forming a valid <INT64> (see {Grammar Production Rules})
317 /// in the optionally specified `base` or in base 10 if `base` is not
318 /// specified, and place into the specified `result` the corresponding
319 /// value. Optionally specify `remainder`, in which to store the
320 /// remainder of the `inputString` immediately following the
321 /// successfully parsed text, or the position at which a parse failure
322 /// was detected. If the parsed number is outside of the
323 /// `[-0x8000000000000000uLL .. 0x7FFFFFFFFFFFFFFFull]` range the
324 /// `result` will be the longest number that does not over/underflow and
325 /// `remainder` will start at the first digit that would make the number
326 /// too large/small. Return zero on success, and a non-zero value
327 /// otherwise. The value of `result` is unchanged if a parse failure
328 /// occurs. The behavior is undefined unless `2 <= base` and
329 /// `base <= 36` (i.e., bases where digits are representable by
330 /// characters in the range [`0`-`9`], [`a`-`z`], or [`A`-`Z`]).
331 ///
332 static int parseInt64(bsls::Types::Int64 *result,
333 const bsl::string_view& inputString,
334 int base = 10);
335 /// A parse failure can occur for the following reasons:
336 /// 1. The `inputString` is empty.
337 /// 2. The first character of `inputString` is not a valid digit in
338 /// `base`, or an optional sign followed by a valid digit.
339 static int parseInt64(bsls::Types::Int64 *result,
340 bsl::string_view *remainder,
341 const bsl::string_view& inputString,
342 int base = 10);
343
344 /// Parse the specified `inputString` for the maximal sequence of
345 /// characters forming a valid <SHORT> (see {Grammar Production Rules})
346 /// in the optionally specified `base` or in base 10 if `base` is not
347 /// specified, and place into the specified `result` the corresponding
348 /// value. Optionally specify `remainder`, in which to store the
349 /// remainder of the `inputString` immediately following the
350 /// successfully parsed text, or the position at which a parse failure
351 /// was detected. If the parsed number is outside of the
352 /// `[SHRT_MIN .. SHRT_MAX]` range the `result` will be the longest
353 /// number that does not over/underflow and `remainder` will start at
354 /// the first digit that would make the number too large/small. Return
355 /// zero on success, and a non-zero value otherwise. The value of
356 /// `result` is unchanged if a parse failure occurs. The behavior is
357 /// undefined unless `2 <= base` and `base <= 36` (i.e., bases where
358 /// digits are representable by characters in the range [`0`-`9`],
359 /// [`a`-`z`] or [`A`-`Z`]).
360 ///
361 static int parseShort(short *result,
362 const bsl::string_view& inputString,
363 int base = 10);
364 /// A parse failure can occur for the following reasons:
365 /// 1. The `inputString` is empty.
366 /// 2. The first character of `inputString` is not a valid digit in
367 /// `base`, or an optional sign followed by a valid digit.
368 static int parseShort(short *result,
369 bsl::string_view *remainder,
370 const bsl::string_view& inputString,
371 int base = 10);
372
373 /// Parse the specified `inputString` for the maximal sequence of
374 /// characters forming an <UNSIGNED> (see {Grammar Production Rules}) in
375 /// the optionally specified `base` or in base 10 if `base` is not
376 /// specified, and place into the specified `result` the corresponding
377 /// value. Optionally specify `remainder`, in which to store the
378 /// remainder of the `inputString` immediately following the
379 /// successfully parsed text, or the position at which a parse failure
380 /// was detected. If the parsed number is outside of the
381 /// `[0 .. UINT_MAX]` range the `result` will be the longest number that
382 /// does not overflow and `remainder` will start at the first digit that
383 /// would make the number too large. Return zero on success, and a
384 /// non-zero value otherwise. The value of `result` is unchanged if a
385 /// parse failure occurs. The behavior is undefined unless `2 <= base`
386 /// and `base <= 36` (i.e., bases where digits are representable by
387 /// characters in the range [`0`-`9`], [`a`-`z`], or [`A`-`Z`]).
388 ///
389 static int parseUint(unsigned int *result,
390 const bsl::string_view& inputString,
391 int base = 10);
392 /// A parse failure can occur for the following reasons:
393 /// 1. The `inputString` is empty.
394 /// 2. The first character of `inputString` is not a valid digit in
395 /// `base`, or an optional sign followed by a valid digit.
396 static int parseUint(unsigned int *result,
397 bsl::string_view *remainder,
398 const bsl::string_view& inputString,
399 int base = 10);
400
401 /// Parse the specified `inputString` for the maximal sequence of
402 /// characters forming a valid <UNSIGNED64> (see {Grammar Production
403 /// Rules}) in the optionally specified `base` or in base 10 if `base`
404 /// is not specified, and place into the specified `result` the
405 /// corresponding value. Optionally specify `remainder`, in which to
406 /// store the remainder of the `inputString` immediately following the
407 /// successfully parsed text, or the position at which a parse failure
408 /// was detected. If the parsed number is outside of the
409 /// `[0 .. 0XFFFFFFFFFFFFFFFF]` range the `result` will be the longest
410 /// number that does not overflow and `remainder` will start at the
411 /// first digit that would make the number too large. Return zero on
412 /// success, and a non-zero value otherwise. The value of `result` is
413 /// unchanged if a parse failure occurs. The behavior is undefined
414 /// unless `2 <= base` and `base <= 36` (i.e., bases where digits are
415 /// representable by characters in the range [`0`-`9`], [`a`-`z`], or
416 /// [`A`-`Z`]).
417 ///
418 static int parseUint64(bsls::Types::Uint64 *result,
419 const bsl::string_view& inputString,
420 int base = 10);
421 /// A parse failure can occur for the following reasons:
422 /// 1. The `inputString` is empty.
423 /// 2. The first character of `inputString` is not a valid digit in
424 /// `base`, or an optional sign followed by a valid digit.
426 bsl::string_view *remainder,
427 const bsl::string_view& inputString,
428 int base = 10);
429
430 /// Parse the specified `inputString` for the maximal sequence of
431 /// characters forming a valid <USHORT> (see {Grammar Production Rules})
432 /// in the optionally specified `base` or in base 10 if `base` is not
433 /// specified, and place into the specified `result` the corresponding
434 /// value. Optionally specify `remainder`, in which to store the
435 /// remainder of the `inputString` immediately following the
436 /// successfully parsed text, or the position at which a parse failure
437 /// was detected. If the parsed number is outside of the
438 /// `[0 .. USHRT_MAX]` range the `result` will be the longest number
439 /// that does not over/underflow and `remainder` will start at the first
440 /// digit that would make the number too large/small. Return zero on
441 /// success, and a non-zero value otherwise. The value of `result` is
442 /// unchanged if a parse failure occurs. The behavior is undefined
443 /// unless `2 <= base` and `base <= 36` (i.e., bases where digits are
444 /// representable by characters in the range [`0`-`9`], [`a`-`z`] or
445 /// [`A`-`Z`]).
446 ///
447 static int parseUshort(unsigned short *result,
448 const bsl::string_view& inputString,
449 int base = 10);
450 /// A parse failure can occur for the following reasons:
451 /// 1. The `inputString` is empty.
452 /// 2. The first character of `inputString` is not a valid digit in
453 /// `base`, or an optional sign followed by a valid digit.
454 static int parseUshort(unsigned short *result,
455 bsl::string_view *remainder,
456 const bsl::string_view& inputString,
457 int base = 10);
458
459 /// Parse the specified `inputString` for an optional sign followed by a
460 /// sequence of characters representing digits in the specified `base`,
461 /// consuming the maximum that will form a number whose value is less
462 /// than or equal to the specified `maxValue` and greater than or equal
463 /// to the specified `minValue`. Place into the specified `result` the
464 /// extracted value. Optionally specify `remainder`, in which to store
465 /// the remainder of the `inputString` immediately following the
466 /// successfully parsed text, or the position at which a parse failure
467 /// was detected. Return 0 on success, and a non-zero value otherwise.
468 /// The value of `result` is unchanged if a parse failure occurs. The
469 /// behavior is undefined unless `maxValue` a positive integer, and
470 /// `minValue` is negative (this is required to allow for efficient
471 /// implementation). The behavior is also undefined unless `2 <= base`
472 /// and `base <= 36`, (i.e., bases where digits are representable by
473 /// characters `[ 0 .. 9 ]`, `[ a .. z ]` or `[ A .. Z ]`).
474 ///
475 static int parseSignedInteger(bsls::Types::Int64 *result,
476 const bsl::string_view& inputString,
477 int base,
478 const bsls::Types::Int64 minValue,
479 const bsls::Types::Int64 maxValue);
480 /// A parse failure can occur for the following reasons:
481 /// 1. The parsed string is not a `<NUMBER>`, i.e., does not contain
482 /// an optional sign followed by at least one digit.
483 /// 2. The first digit in `inputString` is larger than `maxValue` or
484 /// smaller than `minValue`.
485 /// 3. The first digit is not a valid number for the `base`.
487 bsl::string_view *remainder,
488 const bsl::string_view& inputString,
489 int base,
490 const bsls::Types::Int64 minValue,
491 const bsls::Types::Int64 maxValue);
492
493 /// Parse the specified `inputString` for a sequence of characters
494 /// representing digits in the specified `base`, consuming the maximum
495 /// up to the optionally specified `maxNumDigits` that form a number
496 /// whose value does not exceed the specified `maxValue`. Place into
497 /// the specified `result` the extracted value. Optionally specify
498 /// `remainder`, in which to store the remainder of the `inputString`
499 /// immediately following the successfully parsed text, or the position
500 /// at which a parse failure was detected. Return 0 on success, and a
501 /// non-zero value otherwise. The value of `result` is unchanged if a
502 /// parse failure occurs. If `maxNumDigits` is not specified, it
503 /// defaults to a number larger than the number of possible digits in an
504 /// unsigned 64-bit integer. The behavior is undefined unless
505 /// `2 < = base` and `base <= 36` (i.e., bases where digits are
506 /// representable by characters `[ 0 .. 9 ]`, `[ a .. z ]` or
507 /// `[ A .. Z ]`).
508 ///
509 static int parseUnsignedInteger(bsls::Types::Uint64 *result,
510 const bsl::string_view& inputString,
511 int base,
512 const bsls::Types::Uint64 maxValue);
514 bsl::string_view *remainder,
515 const bsl::string_view& inputString,
516 int base,
517 const bsls::Types::Uint64 maxValue);
518 static int parseUnsignedInteger(bsls::Types::Uint64 *result,
519 const bsl::string_view& inputString,
520 int base,
521 const bsls::Types::Uint64 maxValue,
522 int maxNumDigits);
523 /// A parse failure can occur for the following reasons:
524 /// 1. The `inputString` is not a `<POSITIVE_NUMBER>`, i.e., does
525 /// not begin with a digit.
526 /// 2. The first digit in `inputString` is larger than `maxValue`.
527 /// 3. The first digit is not a valid number for the `base`.
529 bsl::string_view *remainder,
530 const bsl::string_view& inputString,
531 int base,
532 const bsls::Types::Uint64 maxValue,
533 int maxNumDigits);
534};
535
536// ============================================================================
537// INLINE AND TEMPLATE FUNCTION DEFINITIONS
538// ============================================================================
539
540 // -----------------------
541 // struct NumericParseUtil
542 // -----------------------
543
544inline
546 const bsl::string_view& inputString)
547{
548 BSLS_ASSERT(result);
549
550 bsl::string_view rest;
551 return parseDouble(result, &rest, inputString);
552}
553
554inline
556 const bsl::string_view& inputString,
557 int base)
558{
559 BSLS_ASSERT(result);
560
561 bsl::string_view rest;
562 return parseInt(result, &rest, inputString, base);
563}
564
565inline
567 const bsl::string_view& inputString,
568 int base)
569{
570 BSLS_ASSERT(result);
571
572 bsl::string_view rest;
573 return parseInt64(result, &rest, inputString, base);
574}
575
576inline
578 const bsl::string_view& inputString,
579 int base)
580{
581 BSLS_ASSERT(result);
582
583 bsl::string_view rest;
584 return parseShort(result, &rest, inputString, base);
585}
586
587inline
588int NumericParseUtil::parseUint(unsigned int *result,
589 const bsl::string_view& inputString,
590 int base)
591{
592 BSLS_ASSERT(result);
593
594 bsl::string_view rest;
595 return parseUint(result, &rest, inputString, base);
596}
597
598inline
600 const bsl::string_view& inputString,
601 int base)
602{
603 BSLS_ASSERT(result);
604
605 bsl::string_view rest;
606 return parseUint64(result, &rest, inputString, base);
607}
608
609inline
610int NumericParseUtil::parseUshort(unsigned short *result,
611 const bsl::string_view& inputString,
612 int base)
613{
614 BSLS_ASSERT(result);
615
616 bsl::string_view rest;
617 return parseUshort(result, &rest, inputString, base);
618}
619
620inline
622 const bsl::string_view& inputString,
623 int base,
624 const bsls::Types::Int64 minValue,
625 const bsls::Types::Int64 maxValue)
626{
627 BSLS_ASSERT(result);
628
629 bsl::string_view rest;
630 return parseSignedInteger(
631 result, &rest, inputString, base, minValue, maxValue);
632}
633
634inline
636 bsls::Types::Uint64 *result,
637 const bsl::string_view& inputString,
638 int base,
639 const bsls::Types::Uint64 maxValue)
640{
641 BSLS_ASSERT(result);
642
643 bsl::string_view rest;
644 return parseUnsignedInteger(result, &rest, inputString, base, maxValue);
645}
646
647inline
649 bsls::Types::Uint64 *result,
650 const bsl::string_view& inputString,
651 int base,
652 const bsls::Types::Uint64 maxValue,
653 int maxNumDigits)
654{
655 BSLS_ASSERT(result);
656
657 bsl::string_view rest;
659 result, &rest, inputString, base, maxValue, maxNumDigits);
660}
661
662} // close package namespace
663
664
665#endif
666
667// ----------------------------------------------------------------------------
668// Copyright 2017 Bloomberg Finance L.P.
669//
670// Licensed under the Apache License, Version 2.0 (the "License");
671// you may not use this file except in compliance with the License.
672// You may obtain a copy of the License at
673//
674// http://www.apache.org/licenses/LICENSE-2.0
675//
676// Unless required by applicable law or agreed to in writing, software
677// distributed under the License is distributed on an "AS IS" BASIS,
678// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
679// See the License for the specific language governing permissions and
680// limitations under the License.
681// ----------------------------- END-OF-FILE ----------------------------------
682
683/** @} */
684/** @} */
685/** @} */
Definition bslstl_stringview.h:441
std::size_t size_type
Definition bslstl_stringview.h:457
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_algorithmworkaroundutil.h:74
Definition bdlb_numericparseutil.h:247
static int parseUint64(bsls::Types::Uint64 *result, const bsl::string_view &inputString, int base=10)
Definition bdlb_numericparseutil.h:599
bsl::string_view::size_type size_type
Shorter name for readability.
Definition bdlb_numericparseutil.h:253
static int parseShort(short *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10)
static int parseDouble(double *result, bsl::string_view *remainder, const bsl::string_view &inputString)
static int parseUint64(bsls::Types::Uint64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10)
static int parseUnsignedInteger(bsls::Types::Uint64 *result, const bsl::string_view &inputString, int base, const bsls::Types::Uint64 maxValue)
Definition bdlb_numericparseutil.h:635
static int parseUshort(unsigned short *result, const bsl::string_view &inputString, int base=10)
Definition bdlb_numericparseutil.h:610
static int parseInt64(bsls::Types::Int64 *result, const bsl::string_view &inputString, int base=10)
Definition bdlb_numericparseutil.h:566
static int parseDouble(double *result, const bsl::string_view &inputString)
Definition bdlb_numericparseutil.h:545
static int parseInt(int *result, const bsl::string_view &inputString, int base=10)
Definition bdlb_numericparseutil.h:555
static int parseUshort(unsigned short *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10)
static int parseUnsignedInteger(bsls::Types::Uint64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base, const bsls::Types::Uint64 maxValue, int maxNumDigits)
static int parseUint(unsigned int *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10)
static int parseUint(unsigned int *result, const bsl::string_view &inputString, int base=10)
Definition bdlb_numericparseutil.h:588
static int characterToDigit(char character, int base)
static int parseInt64(bsls::Types::Int64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10)
static int parseInt(int *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base=10)
static int parseShort(short *result, const bsl::string_view &inputString, int base=10)
Definition bdlb_numericparseutil.h:577
static int parseUnsignedInteger(bsls::Types::Uint64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base, const bsls::Types::Uint64 maxValue)
static int parseSignedInteger(bsls::Types::Int64 *result, const bsl::string_view &inputString, int base, const bsls::Types::Int64 minValue, const bsls::Types::Int64 maxValue)
Definition bdlb_numericparseutil.h:621
static int parseSignedInteger(bsls::Types::Int64 *result, bsl::string_view *remainder, const bsl::string_view &inputString, int base, const bsls::Types::Int64 minValue, const bsls::Types::Int64 maxValue)
unsigned long long Uint64
Definition bsls_types.h:137
long long Int64
Definition bsls_types.h:132