diff options
Diffstat (limited to 'firmware/common/strnatcmp.c')
-rw-r--r-- | firmware/common/strnatcmp.c | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/firmware/common/strnatcmp.c b/firmware/common/strnatcmp.c index 93a649358f..0084ff3582 100644 --- a/firmware/common/strnatcmp.c +++ b/firmware/common/strnatcmp.c | |||
@@ -75,26 +75,26 @@ compare_right(char const *a, char const *b) | |||
75 | int ca, cb; | 75 | int ca, cb; |
76 | 76 | ||
77 | /* The longest run of digits wins. That aside, the greatest | 77 | /* The longest run of digits wins. That aside, the greatest |
78 | value wins, but we can't know that it will until we've scanned | 78 | value wins, but we can't know that it will until we've scanned |
79 | both numbers to know that they have the same magnitude, so we | 79 | both numbers to know that they have the same magnitude, so we |
80 | remember it in BIAS. */ | 80 | remember it in BIAS. */ |
81 | for (;; a++, b++) { | 81 | for (;; a++, b++) { |
82 | ca = to_int(*a); | 82 | ca = to_int(*a); |
83 | cb = to_int(*b); | 83 | cb = to_int(*b); |
84 | if (!nat_isdigit(ca) && !nat_isdigit(cb)) | 84 | if (!nat_isdigit(ca) && !nat_isdigit(cb)) |
85 | return bias; | 85 | return bias; |
86 | else if (!nat_isdigit(ca)) | 86 | else if (!nat_isdigit(ca)) |
87 | return -1; | 87 | return -1; |
88 | else if (!nat_isdigit(cb)) | 88 | else if (!nat_isdigit(cb)) |
89 | return +1; | 89 | return +1; |
90 | else if (ca < cb) { | 90 | else if (ca < cb) { |
91 | if (!bias) | 91 | if (!bias) |
92 | bias = -1; | 92 | bias = -1; |
93 | } else if (ca > cb) { | 93 | } else if (ca > cb) { |
94 | if (!bias) | 94 | if (!bias) |
95 | bias = +1; | 95 | bias = +1; |
96 | } else if (!ca && !cb) | 96 | } else if (!ca && !cb) |
97 | return bias; | 97 | return bias; |
98 | } | 98 | } |
99 | 99 | ||
100 | return 0; | 100 | return 0; |
@@ -107,18 +107,18 @@ compare_left(char const *a, char const *b) | |||
107 | /* Compare two left-aligned numbers: the first to have a | 107 | /* Compare two left-aligned numbers: the first to have a |
108 | different value wins. */ | 108 | different value wins. */ |
109 | for (;; a++, b++) { | 109 | for (;; a++, b++) { |
110 | if (!nat_isdigit(*a) && !nat_isdigit(*b)) | 110 | if (!nat_isdigit(*a) && !nat_isdigit(*b)) |
111 | return 0; | 111 | return 0; |
112 | else if (!nat_isdigit(*a)) | 112 | else if (!nat_isdigit(*a)) |
113 | return -1; | 113 | return -1; |
114 | else if (!nat_isdigit(*b)) | 114 | else if (!nat_isdigit(*b)) |
115 | return +1; | 115 | return +1; |
116 | else if (*a < *b) | 116 | else if (*a < *b) |
117 | return -1; | 117 | return -1; |
118 | else if (*a > *b) | 118 | else if (*a > *b) |
119 | return +1; | 119 | return +1; |
120 | } | 120 | } |
121 | 121 | ||
122 | return 0; | 122 | return 0; |
123 | } | 123 | } |
124 | 124 | ||
@@ -134,39 +134,39 @@ static int strnatcmp0(char const *a, char const *b, int fold_case) | |||
134 | ca = to_int(a[ai]); | 134 | ca = to_int(a[ai]); |
135 | cb = to_int(b[bi]); | 135 | cb = to_int(b[bi]); |
136 | 136 | ||
137 | /* process run of digits */ | 137 | /* process run of digits */ |
138 | if (nat_isdigit(ca) && nat_isdigit(cb)) { | 138 | if (nat_isdigit(ca) && nat_isdigit(cb)) { |
139 | fractional = (ca == '0' || cb == '0'); | 139 | fractional = (ca == '0' || cb == '0'); |
140 | 140 | ||
141 | if (fractional) { | 141 | if (fractional) { |
142 | if ((result = compare_left(a+ai, b+bi)) != 0) | 142 | if ((result = compare_left(a+ai, b+bi)) != 0) |
143 | return result; | 143 | return result; |
144 | } else { | 144 | } else { |
145 | if ((result = compare_right(a+ai, b+bi)) != 0) | 145 | if ((result = compare_right(a+ai, b+bi)) != 0) |
146 | return result; | 146 | return result; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | if (!ca && !cb) { | 150 | if (!ca && !cb) { |
151 | /* The strings compare the same. Call str[case]cmp() to ensure | 151 | /* The strings compare the same. Call str[case]cmp() to ensure |
152 | consistent results. */ | 152 | consistent results. */ |
153 | if(fold_case) | 153 | if(fold_case) |
154 | return strcasecmp(a,b); | 154 | return strcasecmp(a,b); |
155 | else | 155 | else |
156 | return strcmp(a,b); | 156 | return strcmp(a,b); |
157 | } | 157 | } |
158 | 158 | ||
159 | if (fold_case) { | 159 | if (fold_case) { |
160 | ca = nat_unify_case(ca); | 160 | ca = nat_unify_case(ca); |
161 | cb = nat_unify_case(cb); | 161 | cb = nat_unify_case(cb); |
162 | } | 162 | } |
163 | 163 | ||
164 | if (ca < cb) | 164 | if (ca < cb) |
165 | return -1; | 165 | return -1; |
166 | else if (ca > cb) | 166 | else if (ca > cb) |
167 | return +1; | 167 | return +1; |
168 | 168 | ||
169 | ++ai; ++bi; | 169 | ++ai; ++bi; |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||