ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/GBase.cpp
(Generate patch)
# Line 163 | Line 163
163    return copy;
164    }
165  
166 < int Gstrcmp(char* a, char* b) {
166 > int Gstrcmp(const char* a, const char* b, int n) {
167   if (a==NULL || b==NULL) {
168     return a==NULL ? -1 : 1;
169     }
170 < else return strcmp(a,b);
170 > else {
171 >   if (n<0) return strcmp(a,b);
172 >       else return strncmp(a,b,n);
173 > }
174 >
175   }
176  
177 < int Gstricmp(const char* a, const char* b) {
177 > int Gstricmp(const char* a, const char* b, int n) {
178   if (a==NULL || b==NULL) return a==NULL ? -1 : 1;
179   register int ua, ub;
180 < while ((*a!=0) && (*b!=0)) {
181 <  ua=tolower((unsigned char)*a);
182 <  ub=tolower((unsigned char)*b);
183 <  a++;b++;
184 <  if (ua!=ub) return ua < ub ? -1 : 1;
180 > if (n<0) {
181 >   while ((*a!=0) && (*b!=0)) {
182 >    ua=tolower((unsigned char)*a);
183 >    ub=tolower((unsigned char)*b);
184 >    a++;b++;
185 >    if (ua!=ub) return ua < ub ? -1 : 1;
186 >    }
187 >    return (*a == 0) ? ( (*b == 0) ? 0 : -1 ) : 1 ;
188 >  }
189 > else {
190 >   while (n && (*a!=0) && (*b!=0)) {
191 >    ua=tolower((unsigned char)*a);
192 >    ub=tolower((unsigned char)*b);
193 >    a++;b++;n--;
194 >    if (ua!=ub) return ua < ub ? -1 : 1;
195 >    }
196 >    //return (*a == 0) ? ( (*b == 0) ? 0 : -1 ) : 1 ;
197 >   if (n==0) return 0;
198 >   else { return (*a == 0) ? ( (*b == 0) ? 0 : -1 ) : 1 ; }
199    }
182  return (*a == 0) ? ( (*b == 0) ? 0 : -1 ) : 1 ;
200   }
201  
202   int strsplit(char* str, char** fields, int maxfields, const char* delim) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines