From c316f21fe615bef4b470c2b0f191cbb8a567df8d Mon Sep 17 00:00:00 2001 From: davyw Date: Fri, 10 Feb 2012 22:37:18 +0100 Subject: [PATCH] Use of internal StrCmpIns function in stead of runtime stricmp/strcasecmp. * Because of incompatible implementations of string comparison functions on different platforms (uppercase vs lowercase compares) it is better to have an scl specific StrCmpIns function. This fixes issues creating and validating complex structures in stepfile.cc. --- src/clutils/Str.cc | 9 +++++++++ src/clutils/Str.h | 12 +----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/clutils/Str.cc b/src/clutils/Str.cc index 2a0a1607..29496d9c 100644 --- a/src/clutils/Str.cc +++ b/src/clutils/Str.cc @@ -96,6 +96,15 @@ const char * StrToConstant( const char * word, std::string & s ) { return const_cast( s.c_str() ); } +int StrCmpIns( const char * str1, const char * str2 ) { + char c1, c2; + while ((c1 = tolower(*str1)) == (c2 = tolower(*str2)) && c1 != '\0') { + str1++; + str2++; + } + return c1 - c2; +} + /**************************************************************//** ** \fn PrettyTmpName (char * oldname) ** \returns a new capitalized name in a static buffer diff --git a/src/clutils/Str.h b/src/clutils/Str.h index 25643751..efdd1bcf 100644 --- a/src/clutils/Str.h +++ b/src/clutils/Str.h @@ -21,23 +21,13 @@ #include #include - -//StrCmpIns - case-insensitive string compare. Original fct (replaced Sep 2011) -//called PrettyTmpName(). Not doing so may affect sort order but that shouldn't hurt -#if defined(__MSVC__) -#define StrCmpIns(a,b) _stricmp(a,b) -#elif defined(__BORLAND__) -#define StrCmpIns(a,b) stricmp(a,b) -#else -#define StrCmpIns(a,b) strcasecmp(a,b) -#endif - SCL_UTILS_EXPORT char ToLower( const char c ); SCL_UTILS_EXPORT char ToUpper( const char c ); SCL_UTILS_EXPORT char * StrToLower( const char *, char * ); SCL_UTILS_EXPORT const char * StrToLower( const char * word, std::string & s ); SCL_UTILS_EXPORT const char * StrToUpper( const char * word, std::string & s ); SCL_UTILS_EXPORT const char * StrToConstant( const char * word, std::string & s ); +SCL_UTILS_EXPORT int StrCmpIns( const char *str1, const char *str2 ); SCL_UTILS_EXPORT const char * PrettyTmpName( const char * oldname ); SCL_UTILS_EXPORT char * PrettyNewName( const char * oldname ); SCL_UTILS_EXPORT char * EntityClassName( char * oldname );