** Compare two strings 'ls' x 'rs', returning an integer less-equal- ** -greater than zero if 'ls' is less-equal-greater 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. */
| 373 | ** of the strings. |
| 374 | */ |
| 375 | static int l_strcmp (const TString *ls, const TString *rs) { |
| 376 | const char *l = getstr(ls); |
| 377 | size_t ll = tsslen(ls); |
| 378 | const char *r = getstr(rs); |
| 379 | size_t lr = tsslen(rs); |
| 380 | for (;;) { /* for each segment */ |
| 381 | int temp = strcoll(l, r); |
| 382 | if (temp != 0) /* not equal? */ |
| 383 | return temp; /* done */ |
| 384 | else { /* strings are equal up to a '\0' */ |
| 385 | size_t len = strlen(l); /* index of first '\0' in both strings */ |
| 386 | if (len == lr) /* 'rs' is finished? */ |
| 387 | return (len == ll) ? 0 : 1; /* check 'ls' */ |
| 388 | else if (len == ll) /* 'ls' is finished? */ |
| 389 | return -1; /* 'ls' is less than 'rs' ('rs' is not finished) */ |
| 390 | /* both strings longer than 'len'; go on comparing after the '\0' */ |
| 391 | len++; |
| 392 | l += len; ll -= len; r += len; lr -= len; |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | |
| 398 | /* |
no outgoing calls
no test coverage detected