implement non-stub strverscmp
patch by Isaac Dunham.
This commit is contained in:
parent
d1eae83a59
commit
4853c1f7f7
1 changed files with 35 additions and 2 deletions
|
|
@ -1,7 +1,40 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int strverscmp(const char *l, const char *r)
|
||||
{
|
||||
/* FIXME */
|
||||
return strcmp(l, r);
|
||||
int haszero=1;
|
||||
while (*l==*r) {
|
||||
if (!*l) return 0;
|
||||
|
||||
if (*l=='0') {
|
||||
if (haszero==1) {
|
||||
haszero=0;
|
||||
}
|
||||
} else if (isdigit(*l)) {
|
||||
if (haszero==1) {
|
||||
haszero=2;
|
||||
}
|
||||
} else {
|
||||
haszero=1;
|
||||
}
|
||||
l++; r++;
|
||||
}
|
||||
if (haszero==1 && (*l=='0' || *r=='0')) {
|
||||
haszero=0;
|
||||
}
|
||||
if ((isdigit(*l) && isdigit(*r) ) && haszero) {
|
||||
size_t lenl=0, lenr=0;
|
||||
while (isdigit(l[lenl]) ) lenl++;
|
||||
while (isdigit(r[lenr]) ) lenr++;
|
||||
if (lenl==lenr) {
|
||||
return (*l - *r);
|
||||
} else {
|
||||
return (lenl - lenr);
|
||||
}
|
||||
} else {
|
||||
return (*l - *r);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue