MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / l_strcmp

Function l_strcmp

third-party/lua-5.5.0/src/lvm.c:391–412  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

389** have different lengths.
390*/
391static int l_strcmp (const TString *ts1, const TString *ts2) {
392 size_t rl1; /* real length */
393 const char *s1 = getlstr(ts1, rl1);
394 size_t rl2;
395 const char *s2 = getlstr(ts2, rl2);
396 for (;;) { /* for each segment */
397 int temp = l_strcoll(s1, s2);
398 if (temp != 0) /* not equal? */
399 return temp; /* done */
400 else { /* strings are equal up to a '\0' */
401 size_t zl1 = strlen(s1); /* index of first '\0' in 's1' */
402 size_t zl2 = strlen(s2); /* index of first '\0' in 's2' */
403 if (zl2 == rl2) /* 's2' is finished? */
404 return (zl1 == rl1) ? 0 : 1; /* check 's1' */
405 else if (zl1 == rl1) /* 's1' is finished? */
406 return -1; /* 's1' is less than 's2' ('s2' is not finished) */
407 /* both strings longer than 'zl'; go on comparing after the '\0' */
408 zl1++; zl2++;
409 s1 += zl1; rl1 -= zl1; s2 += zl2; rl2 -= zl2;
410 }
411 }
412}
413
414
415/*

Callers 2

lessthanothersFunction · 0.70
lessequalothersFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected