** Compare two strings 'ts1' x 'ts2', returning an integer less-equal- ** -greater than zero if 'ts1' is less-equal-greater than 'ts2'. ** The code is a little tricky because it allows '\0' in the strings ** and it uses 'strcoll' (to respect locales) for each segment ** of the strings. Note that segments can compare equal but still ** have different lengths. */
| 386 | ** have different lengths. |
| 387 | */ |
| 388 | static int l_strcmp (const TString *ts1, const TString *ts2) { |
| 389 | const char *s1 = getstr(ts1); |
| 390 | size_t rl1 = tsslen(ts1); /* real length */ |
| 391 | const char *s2 = getstr(ts2); |
| 392 | size_t rl2 = tsslen(ts2); |
| 393 | for (;;) { /* for each segment */ |
| 394 | int temp = strcoll(s1, s2); |
| 395 | if (temp != 0) /* not equal? */ |
| 396 | return temp; /* done */ |
| 397 | else { /* strings are equal up to a '\0' */ |
| 398 | size_t zl1 = strlen(s1); /* index of first '\0' in 's1' */ |
| 399 | size_t zl2 = strlen(s2); /* index of first '\0' in 's2' */ |
| 400 | if (zl2 == rl2) /* 's2' is finished? */ |
| 401 | return (zl1 == rl1) ? 0 : 1; /* check 's1' */ |
| 402 | else if (zl1 == rl1) /* 's1' is finished? */ |
| 403 | return -1; /* 's1' is less than 's2' ('s2' is not finished) */ |
| 404 | /* both strings longer than 'zl'; go on comparing after the '\0' */ |
| 405 | zl1++; zl2++; |
| 406 | s1 += zl1; rl1 -= zl1; s2 += zl2; rl2 -= zl2; |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | |
| 412 | /* |
no outgoing calls
no test coverage detected