Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
nf_stringToInt32s.c File Reference
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include "nf_utilities.h"

Go to the source code of this file.

Macros

#define numberOfStaticInt32s   ( 100 * 1000 )
#define INT32_MIN   -2147483648
#define INT32_MAX   2147483647

Functions

int32_t * nfu_stringToListOfInt32s (statusMessageReporting *smr, char const *str, char sep, int64_t *numberConverted, char **endCharacter)
int nfu_stringToInt32 (statusMessageReporting *smr, char const *str, char **endCharacter, int32_t *value)

Macro Definition Documentation

◆ INT32_MAX

#define INT32_MAX   2147483647

Definition at line 20 of file nf_stringToInt32s.c.

Referenced by nfu_stringToInt32().

◆ INT32_MIN

#define INT32_MIN   -2147483648

Definition at line 19 of file nf_stringToInt32s.c.

Referenced by nfu_stringToInt32().

◆ numberOfStaticInt32s

#define numberOfStaticInt32s   ( 100 * 1000 )

Definition at line 16 of file nf_stringToInt32s.c.

Function Documentation

◆ nfu_stringToInt32()

int nfu_stringToInt32 ( statusMessageReporting * smr,
char const * str,
char ** endCharacter,
int32_t * value )

Definition at line 126 of file nf_stringToInt32s.c.

126 {
127
128 long lValue = strtol( str, endCharacter, 10 );
129
130 if( lValue < INT32_MIN ) {
131 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badInput, "int32_t underflow: %l", lValue );
132 return( -1 ); }
133 else if( lValue > INT32_MAX ) {
134 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badInput, "int32_t overflow: %l", lValue );
135 return( 1 );
136 }
137 *value = (int) lValue;
138 return( 0 );
139}
#define INT32_MAX
#define INT32_MIN
@ nfu_badInput
int nfu_SMR_libraryID
#define smr_setReportError2(smr, libraryID, code, fmt,...)

◆ nfu_stringToListOfInt32s()

int32_t * nfu_stringToListOfInt32s ( statusMessageReporting * smr,
char const * str,
char sep,
int64_t * numberConverted,
char ** endCharacter )

Definition at line 27 of file nf_stringToInt32s.c.

28 {
29
30 if( strchr( "0123456789.+-eE", sep ) != NULL ) {
31 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badInput, "Invalid sep ='%c'.", sep );
32 return( NULL );
33 }
34
35 *numberConverted = 0;
36 *endCharacter = (char *) str;
37 if( isspace( sep ) ) sep = ' '; /* Make it the space character if any white space as it simplifies logic below. */
38 return( nfu_stringToListOfInt32s_2( smr, str, sep, numberConverted, endCharacter ) );
39}