34#ifdef LUPI_printDeprecatedInformation
35 std::cerr <<
"The function '" << a_functionName <<
"' is decreated";
36 if( a_asOf !=
"" ) std::cerr <<
" and will no longer be available starting with GIDI+ '" << a_asOf <<
"'";
38 if( a_replacementName !=
"" ) std::cerr <<
" Please use '" << a_replacementName <<
"' instead.";
39 std::cerr << std::endl;
52 std::runtime_error( a_message ) {
68std::string
stripString( std::string
const &a_string,
bool a_left,
bool a_right ) {
70 std::string stripped( a_string );
71 std::string::iterator beginning = stripped.begin( ), ending = stripped.end( );
74 for( ; beginning != ending; ++beginning )
75 if( !std::isspace( *beginning ) )
break;
78 if( ( beginning != ending ) && a_right ) {
80 for( ; beginning != ending; --ending )
81 if( !std::isspace( *ending ) )
break;
85 stripped.erase( ending, stripped.end( ) );
86 stripped.erase( stripped.begin( ), beginning );
103std::vector<std::string>
splitString( std::string
const &a_string,
char a_delimiter,
bool a_strip ) {
105 std::stringstream stringStream( a_string );
107 std::vector<std::string> segments;
109 while( std::getline( stringStream, segment, a_delimiter ) ) {
110 if( ( a_delimiter ==
' ' ) && ( segment.size( ) == 0 ) )
continue;
113 segments.push_back( segment );
129std::vector<std::string>
splitString( std::string
const &a_string, std::string
const &a_delimiter,
bool a_strip ) {
132 std::vector<std::string> segments;
134 for( std::size_t index1 = 0; ; ) {
135 std::size_t index2 = a_string.find( a_delimiter, index1 );
137 segment = a_string.substr( index1, index2 - index1 );
140 segments.push_back( segment );
141 if( index2 == std::string::npos )
break;
143 index1 = index2 + a_delimiter.size( );
158std::string
joinStrings( std::string
const &a_sep, std::vector<std::string> a_strings ) {
161 std::string sep =
"";
162 std::string
const *sepPointer = &sep;
164 for(
auto iter = a_strings.begin( ); iter != a_strings.end( ); ++iter ) {
165 string += *sepPointer + *iter;
183std::string
replaceString( std::string
const &a_string, std::string
const &a_old, std::string
const &a_new,
bool a_all ) {
185 std::string
string( a_string );
188 std::size_t index =
string.find( a_old );
189 if( index == std::string::npos )
break;
190 string.replace( index, a_old.size( ), a_new );
209 std::vector<std::string> elements;
211 std::size_t start = 0;
213 while( a_XLink[start] ==
'/' ) ++start;
215 std::size_t end = start;
216 std::size_t size = a_XLink.size( );
219 elements.push_back(
"" );
222 for( ; end < size ; ++end ) {
223 char current = a_XLink[end];
225 if( current == quote ) quote =
' ';
229 if( ( current ==
'\'' ) || ( current ==
'"' ) ) {
234 if( current ==
'/' ) {
235 std::string element = a_XLink.substr( start, end - start );
236 elements.push_back( std::move( element ) );
237 while( a_XLink[end] ==
'/' ) ++end;
239 if( end == size )
break;
244 std::string element = a_XLink.substr( start, end - start );
245 elements.push_back( element );
262 char const *digits = a_string.c_str( );
264 long value = strtol( digits, &nonDigit, 10 );
266 if( digits == nonDigit )
return(
false );
267 if( *nonDigit != 0 )
return(
false );
270 a_value =
static_cast<int>( value );
285 char const *digits = a_string.c_str( );
287 long value = strtol( digits, &nonDigit, 10 );
289 if( digits == nonDigit )
return(
false );
290 if( *nonDigit != 0 )
return(
false );
291 if( ( value < 0 ) || ( value > LONG_MAX ) )
return(
false );
293 a_value =
static_cast<std::size_t
>( value );
309 va_start( args, a_format );
313 std::string
string( charStr );
327std::string
doubleToString3(
char const *a_format,
double a_value,
bool a_reduceBits ) {
353 std::string stringValue( charValue );
356 return( stringValue );
367void printCommand( std::string
const &a_indent,
int a_argc,
char **a_argv ) {
369 std::cout << a_indent << a_argv[0];
370 for(
int iargc = 1; iargc < a_argc; ++iargc ) std::cout <<
" " << a_argv[iargc];
371 std::cout << std::endl;
378#if defined (GIDIP_HAVE_COMPILER_FLOATING_POINT_EXCEPTIONS)
397void LUPI_FPE_enable(
char const *a_file,
int a_line ) {
399 static int num_errors = 0;
403 int result = feenableexcept( FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID );
405 if( result == -1 && num_errors < 3 ) {
407 std::cerr <<
"LUPI_FPE_enable:: feenableexcept() returned -1: called from file " << a_file <<
" at line" << a_line <<
".\n";
418void LUPI_FPE_disable_and_clear(
char const *a_file,
int a_line ) {
420 static int num_errors = 0;
425 int result = feholdexcept(&envp);
427 if( result != 0 && num_errors < 3 ) {
429 std::cerr <<
"LUPI_FPE_disable_and_clear:: feholdexcept returned error " << result <<
": called from file " << a_file <<
" at line " << a_line <<
".\n";
440void LUPI_FPE_test(
char const *a_file,
int a_line ) {
442 static int num_errors = 0;
444 if( fetestexcept(FE_DIVBYZERO) != 0 && num_errors < 10 ) {
446 std::cerr <<
"LUPI_FPE_test:: division by 0.error: called from file " << a_file <<
" at line " << a_line <<
".\n";
449 if( fetestexcept(FE_UNDERFLOW) != 0 && num_errors < 10 ) {
451 std::cerr <<
"LUPI_FPE_test:: underflow error: called from file " << a_file <<
" at line " << a_line <<
".\n";
454 if( fetestexcept(FE_OVERFLOW) != 0 && num_errors < 10 ) {
456 std::cerr <<
"LUPI_FPE_test:: overflow error: called from file " << a_file <<
" at line " << a_line <<
".\n";
459 if( fetestexcept(FE_INVALID) != 0 && num_errors < 10) {
461 std::cerr <<
"LUPI_FPE_test:: invalid error: called from file " << a_file <<
" at line " << a_line <<
".\n";
Exception(std::string const &a_message)
std::string doubleToShortestString(double a_value, int a_significantDigits=15, int a_favorEFormBy=0)
std::vector< std::string > splitXLinkString(std::string const &a_string)
std::string replaceString(std::string const &a_string, std::string const &a_old, std::string const &a_new, bool a_all)
std::string joinStrings(std::string const &a_sep, std::vector< std::string > a_strings)
void printCommand(std::string const &a_indent, int a_argc, char **a_argv)
std::vector< std::string > splitString(std::string const &a_string, char a_delimiter, bool a_strip=false)
std::string argumentsToString(char const *a_format,...)
bool stringToSize_t(std::string const &a_string, std::size_t &a_value)
std::string stripString(std::string const &a_string, bool a_left=true, bool a_right=true)
std::string doubleToString3(char const *a_format, double a_value, bool a_reduceBits=false)
bool stringToInt(std::string const &a_string, int &a_value)
void deprecatedFunction(std::string const &a_functionName, std::string const &a_replacementName, std::string const &a_asOf)
#define nf_floatToShortestString_trimZeros
char * nf_floatToShortestString(double value, int significantDigits, int favorEFormBy, int flags)
char * smr_vallocateFormatMessage(char const *fmt, va_list *args)