* off is the offset of the first different character in the two strings * s1 and s2. If either s1 or s2 contains a prerelease suffix containing * that offset or a suffix ends right before that offset, then that * string will be forced to be on top. * * If both s1 and s2 contain a (different) suffix around that position, * their order is determined by the order of those two suffixes in the *
| 73 | * Return non-zero if *diff contains the return value for versioncmp() |
| 74 | */ |
| 75 | static int swap_prereleases(const char *s1, |
| 76 | const char *s2, |
| 77 | int off, |
| 78 | int *diff) |
| 79 | { |
| 80 | struct suffix_match match1 = { -1, off, -1 }; |
| 81 | struct suffix_match match2 = { -1, off, -1 }; |
| 82 | |
| 83 | for (size_t i = 0; i < prereleases->nr; i++) { |
| 84 | const char *suffix = prereleases->items[i].string; |
| 85 | int start, suffix_len = strlen(suffix); |
| 86 | if (suffix_len < off) |
| 87 | start = off - suffix_len; |
| 88 | else |
| 89 | start = 0; |
| 90 | find_better_matching_suffix(s1, suffix, suffix_len, start, |
| 91 | i, &match1); |
| 92 | find_better_matching_suffix(s2, suffix, suffix_len, start, |
| 93 | i, &match2); |
| 94 | } |
| 95 | if (match1.conf_pos == -1 && match2.conf_pos == -1) |
| 96 | return 0; |
| 97 | if (match1.conf_pos == match2.conf_pos) |
| 98 | /* Found the same suffix in both, e.g. "-rc" in "v1.0-rcX" |
| 99 | * and "v1.0-rcY": the caller should decide based on "X" |
| 100 | * and "Y". */ |
| 101 | return 0; |
| 102 | |
| 103 | if (match1.conf_pos >= 0 && match2.conf_pos >= 0) |
| 104 | *diff = match1.conf_pos - match2.conf_pos; |
| 105 | else if (match1.conf_pos >= 0) |
| 106 | *diff = -1; |
| 107 | else /* if (match2.conf_pos >= 0) */ |
| 108 | *diff = 1; |
| 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * Compare S1 and S2 as strings holding indices/version numbers, |
no test coverage detected