** Compare two strings 'ls' x 'rs', returning an integer smaller-equal- ** -larger than zero if 'ls' is smaller-equal-larger than 'rs'. ** The code is a little tricky because it allows '\0' in the strings ** and it uses 'strcoll' (to respect locales) for each segments ** of the strings. */
| 258 | ** of the strings. |
| 259 | */ |
| 260 | static int l_strcmp(const TString *ls, const TString *rs) { |
| 261 | const char *l = getstr(ls); |
| 262 | size_t ll = tsslen(ls); |
| 263 | const char *r = getstr(rs); |
| 264 | size_t lr = tsslen(rs); |
| 265 | if (ll != lr) |
| 266 | return (int)ll - (int) lr; |
| 267 | for (;;) { /* for each segment */ |
| 268 | int temp = strcoll(l, r); |
| 269 | if (temp != 0) /* not equal? */ |
| 270 | return temp; /* done */ |
| 271 | else { /* strings are equal up to a '\0' */ |
| 272 | size_t len = strlen(l); /* index of first '\0' in both strings */ |
| 273 | if (len == lr) /* 'rs' is finished? */ |
| 274 | return (len == ll) ? 0 : 1; /* check 'ls' */ |
| 275 | else if (len == ll) /* 'ls' is finished? */ |
| 276 | return -1; /* 'ls' is smaller than 'rs' ('rs' is not finished) */ |
| 277 | /* both strings longer than 'len'; go on comparing after the '\0' */ |
| 278 | len++; |
| 279 | l += len; ll -= len; r += len; lr -= len; |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | static int l_c_str_cmp(const char *l, const char *r) |
| 285 | { |
no outgoing calls
no test coverage detected