String routines to complement <string> && <cstring>:
strnum.h
Go to the documentation of this file.
1 // strnum.h (c) 2019 adolfo.dimare@gmail.com
2 
3 /** \file strnum.h
4  \brief Complement routines for \c <string> && \c <cstring>
5 
6  \author adolfo.dimare@gmail.com
7  \date 2019
8 */
9 
10 #ifndef strnum_h
11 #define strnum_h ///< Avoid multiple inclusion
12 
13 #include <cstring> // size_t, strlen(), etc.
14 #include <cstdint> // intmax_t && uintmax_t
15 #include <cstdlib> // strtoull()
16 
17 /// Safe size for 'insnsep()'
18 const size_t insnsep_size=96;
19 
20 // Insert in place the separator 'sep' for a numeric string.
21 // - [ej: sep==',' && w==3 for thousands]
22 char *insnsep( char* num, char sep, unsigned w );
23 
24 // Use 'insnsep()' to format a Rupee amount.
25 char* insnsep_Rupee( char *num, char sep );
26 
27 // Use 'insnsep()' to format a date.
28 char* insnsep_date8( char *num, char sep, bool YMD );
29 
30 // Take all numeric values from 'str' to fill up 'VEC[]'.
31 size_t atoi_vec( const char* str, intmax_t VEC[], size_t N );
32 
33 // Take all numeric values from 'str' to fill up 'VEC[]'.
34 size_t atou_vec( const char* str, uintmax_t VEC[], size_t N );
35 
36 // Extract the next number of 'N' digits.
37 uintmax_t atou_ndigit( const char* *str, unsigned N );
38 
39 /// Converts 'str' into an unsigned number invoking \c strtoull()
40 inline uintmax_t atouint( const char * str ) {
41  return strtoull( str,NULL,0 );
42 }
43 
44 // Converts "val" into the zero terminated C-string "dst"
45 char* utoa_sz( uintmax_t val, char *dst, unsigned base, size_t sz );
46 
47 #endif // strnum_h
48 
49 // EOF: strnum.h
atou_vec
size_t atou_vec(const char *str, uintmax_t VEC[], size_t N)
Takes all leading numeric values from 'str' to fill up 'VEC[]'.
Definition: strnum.cpp:178
utoa_sz
char * utoa_sz(uintmax_t val, char *dst, unsigned base, size_t sz)
Converts 'val' into the zero terminated C-string 'dst'.
Definition: strnum.cpp:303
atouint
uintmax_t atouint(const char *str)
Converts 'str' into an unsigned number invoking strtoull()
Definition: strnum.h:40
atoi_vec
size_t atoi_vec(const char *str, intmax_t VEC[], size_t N)
Take all numeric values from 'str' to fill up 'VEC[]'.
Definition: strnum.cpp:214
insnsep_Rupee
char * insnsep_Rupee(char *num, char sep)
Use 'insnsep()' to format a Rupee amount.
Definition: strnum.cpp:98
insnsep
char * insnsep(char *num, char sep, unsigned w)
Insert in place the separator 'sep' for a numeric string.
Definition: strnum.cpp:42
insnsep_date8
char * insnsep_date8(char *num, char sep, bool YMD)
Use 'insnsep()' to format a date.
Definition: strnum.cpp:134
insnsep_size
const size_t insnsep_size
Safe size for 'insnsep()'.
Definition: strnum.h:18
atou_ndigit
uintmax_t atou_ndigit(const char **str, unsigned N)
Extract the next number of 'N' digits from '*str'.
Definition: strnum.cpp:260