| 150 | |
| 151 | |
| 152 | static S32 strnatcmp0(const nat_char* a, const nat_char* b, S32 fold_case) |
| 153 | { |
| 154 | S32 ai, bi; |
| 155 | nat_char ca, cb; |
| 156 | S32 fractional, result; |
| 157 | |
| 158 | ai = bi = 0; |
| 159 | while (1) { |
| 160 | ca = a[ai]; cb = b[bi]; |
| 161 | |
| 162 | /* skip over leading spaces or zeros */ |
| 163 | while (nat_isspace(ca)) |
| 164 | ca = a[++ai]; |
| 165 | |
| 166 | while (nat_isspace(cb)) |
| 167 | cb = b[++bi]; |
| 168 | |
| 169 | /* process run of digits */ |
| 170 | if (nat_isdigit(ca) && nat_isdigit(cb)) { |
| 171 | fractional = (ca == '0' || cb == '0'); |
| 172 | |
| 173 | if (fractional) { |
| 174 | if ((result = compare_left(a+ai, b+bi)) != 0) |
| 175 | return result; |
| 176 | } else { |
| 177 | if ((result = compare_right(a+ai, b+bi)) != 0) |
| 178 | return result; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | if (!ca && !cb) { |
| 183 | /* The strings compare the same. Perhaps the caller |
| 184 | will want to call strcmp to break the tie. */ |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | if (fold_case) { |
| 189 | ca = nat_toupper(ca); |
| 190 | cb = nat_toupper(cb); |
| 191 | } |
| 192 | |
| 193 | if (ca < cb) |
| 194 | return -1; |
| 195 | else if (ca > cb) |
| 196 | return +1; |
| 197 | |
| 198 | ++ai; ++bi; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | |
| 203 | S32 dStrnatcmp(const nat_char* a, const nat_char* b) { |
no test coverage detected