diff options
Diffstat (limited to 'libq/atom_explode.c')
-rw-r--r-- | libq/atom_explode.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/libq/atom_explode.c b/libq/atom_explode.c index faf24ffc..99a60d02 100644 --- a/libq/atom_explode.c +++ b/libq/atom_explode.c @@ -256,26 +256,29 @@ atom_explode(const char *atom) ret->suffixes[idx] = t; } - /* allow for 1 optional suffix letter, must be following a number */ - ptr = ret->PV + strlen(ret->PV); - if (ptr[-1] >= 'a' && ptr[-1] <= 'z' && - ptr - 2 > ret->PV && ptr[-2] >= '0' && ptr[-2] <= '9') - { - ret->letter = ptr[-1]; - --ptr; - } + /* skip back to the "end" */ + for (ptr = ret->PV; *ptr != '\0' && *ptr != '_'; ptr++) + ; + ptr--; - /* eat the trailing version number [-.0-9]+ */ - while (--ptr > ret->PV) { - if (*ptr == '-') { - *ptr = '\0'; - break; - } else if (*ptr != '.' && !isdigit(*ptr)) + /* allow for 1 optional suffix letter */ + if (*ptr >= 'a' && *ptr <= 'z') + ret->letter = *ptr--; + + /* eat the trailing version number [.0-9]+ */ + while (ptr > ret->PV) { + if (*ptr != '.' && !isdigit(*ptr)) break; + ptr--; } - ptr = stpcpy(ret->PVR, ret->PV); - sprintf(ptr, "-r%i", ret->PR_int); + if (ptr != ret->PV) { + /* PV isn't exactly a number */ + ret->PV = ret->PVR = NULL; + } else { + ptr = stpcpy(ret->PVR, ret->PV); + sprintf(ptr, "-r%i", ret->PR_int); + } return ret; } |