Skip to content

Commit 1a130a1

Browse files
committed
replace StrCmpIns with a #define for _stricmp or strcasecmp - much faster
1 parent 696d8e3 commit 1a130a1

File tree

2 files changed

+19
-57
lines changed

2 files changed

+19
-57
lines changed

src/clutils/Str.cc

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
* and is not subject to copyright.
1111
*/
1212

13-
/* $Id: Str.cc,v 3.0.1.3 1997/11/05 22:33:52 sauderd DP3.1 $ */
14-
1513
#include <Str.h>
1614

1715
/******************************************************************
@@ -24,8 +22,7 @@
2422
** Status: complete
2523
******************************************************************/
2624

27-
char
28-
ToLower( const char c ) {
25+
char ToLower( const char c ) {
2926
if( isupper( c ) ) {
3027
return ( tolower( c ) );
3128
} else {
@@ -34,20 +31,16 @@ ToLower( const char c ) {
3431

3532
}
3633

37-
char
38-
ToUpper( const char c ) {
34+
char ToUpper( const char c ) {
3935
if( islower( c ) ) {
4036
return ( toupper( c ) );
4137
} else {
4238
return ( c );
4339
}
4440
}
4541

46-
char *
47-
StrToLower( const char * strOld, char * strNew )
48-
/*
49-
* Place in strNew a lowercase version of strOld.
50-
*/
42+
// Place in strNew a lowercase version of strOld.
43+
char * StrToLower( const char * strOld, char * strNew )
5144
{
5245
int i = 0;
5346

@@ -59,11 +52,9 @@ StrToLower( const char * strOld, char * strNew )
5952
return strNew;
6053
}
6154

62-
const char *
63-
StrToLower( const char * word, std::string & s ) {
55+
const char * StrToLower( const char * word, std::string & s ) {
6456
char newword [BUFSIZ];
6557
int i = 0;
66-
// char ToLower (char c);
6758

6859
while( word [i] != '\0' ) {
6960
newword [i] = ToLower( word [i] );
@@ -74,27 +65,22 @@ StrToLower( const char * word, std::string & s ) {
7465
return const_cast<char *>( s.c_str() );
7566
}
7667

77-
const char *
78-
StrToUpper( const char * word, std::string & s ) {
68+
const char * StrToUpper( const char * word, std::string & s ) {
7969
char newword [BUFSIZ];
8070
int i = 0;
81-
// char ToUpper (char c);
8271

8372
while( word [i] != '\0' ) {
8473
newword [i] = ToUpper( word [i] );
8574
++i;
86-
8775
}
8876
newword [i] = '\0';
8977
s = newword;
9078
return const_cast<char *>( s.c_str() );
9179
}
9280

93-
const char *
94-
StrToConstant( const char * word, std::string & s ) {
81+
const char * StrToConstant( const char * word, std::string & s ) {
9582
char newword [BUFSIZ];
9683
int i = 0;
97-
// char ToUpper (char c);
9884

9985
while( word [i] != '\0' ) {
10086
if( word [i] == '/' || word [i] == '.' ) {
@@ -103,7 +89,6 @@ StrToConstant( const char * word, std::string & s ) {
10389
newword [i] = ToUpper( word [i] );
10490
}
10591
++i;
106-
10792
}
10893
newword [i] = '\0';
10994
s = newword;
@@ -119,8 +104,7 @@ StrToConstant( const char * word, std::string & s ) {
119104
PrettyTmpName returns new name in a static buffer
120105
** Status: OK 7-Oct-1992 kcm
121106
******************************************************************/
122-
const char *
123-
PrettyTmpName( const char * oldname ) {
107+
const char * PrettyTmpName( const char * oldname ) {
124108
int i = 0;
125109
static char newname [BUFSIZ];
126110
newname [0] = '\0';
@@ -134,38 +118,18 @@ PrettyTmpName( const char * oldname ) {
134118
++i;
135119
}
136120
}
137-
138121
newname [0] = ToUpper( oldname [0] );
139122
newname [i] = '\0';
140123
return newname;
141124
}
142125

143-
char *
144-
PrettyNewName( const char * oldname ) {
126+
char * PrettyNewName( const char * oldname ) {
145127

146128
char * name = new char [strlen( oldname ) + 1];
147129
strcpy( name, PrettyTmpName( oldname ) );
148130
return name;
149131
}
150132

151-
int
152-
StrCmpIns( const char * strA, const char * strB )
153-
/*
154-
* An insensitive string compare function. Used most often to compare
155-
* names of objects where case is not known and not significant.
156-
*
157-
* NOTE - cygnus does not define strcmpi/stricmp. I'm sure there's a nifty
158-
* way to add preprocessor commands to check if it exists, and if so to
159-
* use it, but I didn't bother.
160-
*/
161-
{
162-
char str1[BUFSIZ], str2[BUFSIZ];
163-
164-
strncpy( str1, PrettyTmpName( strA ), BUFSIZ - 1 );
165-
strncpy( str2, PrettyTmpName( strB ), BUFSIZ - 1 );
166-
return ( strcmp( str1, str2 ) );
167-
}
168-
169133
// This function is used to check an input stream following a read. It writes
170134
// error messages in the 'ErrorDescriptor &err' argument as appropriate.
171135
// 'const char *tokenList' argument contains a string made up of delimiters

src/clutils/Str.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@
1313
* and is not subject to copyright.
1414
*/
1515

16-
/* $Id: Str.h,v 3.0.1.3 1997/11/05 22:33:52 sauderd DP3.1 $ */
17-
18-
#ifdef __O3DB__
19-
#include <OpenOODB.h>
20-
#endif
21-
2216
#include <ctype.h>
2317

24-
//#include <std.h> // not found in CenterLine C++
25-
// the two includes stdio.h and stdlib.h below are replacing std.h since
26-
// CenterLine doesn't have std.h
27-
28-
#include <stdio.h> // added to have the definition for BUFSIZE
18+
#include <stdio.h>
2919
#include <stdlib.h>
3020
#include <string.h>
3121
#include <errordesc.h>
3222

23+
24+
//StrCmpIns - case-insensitive string compare. Original fct (replaced Sep 2011)
25+
//called PrettyTmpName(). Not doing so may affect sort order but that shouldn't hurt
26+
#ifdef _MSC_VER
27+
#define StrCmpIns(a,b) _stricmp(a,b)
28+
#else
29+
#define StrCmpIns(a,b) strcasecmp(a,b)
30+
#endif
31+
3332
char ToLower (const char c);
3433
char ToUpper (const char c);
3534
char * StrToLower (const char *, char *);
@@ -38,7 +37,6 @@ const char * StrToUpper (const char * word, std::string &s);
3837
const char * StrToConstant (const char * word, std::string &s);
3938
const char * PrettyTmpName (const char * oldname);
4039
char * PrettyNewName (const char * oldname);
41-
int StrCmpIns (const char *, const char *);
4240
char * EntityClassName ( char * oldname);
4341

4442
extern Severity CheckRemainingInput

0 commit comments

Comments
 (0)