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

Function l_strcmp

third-party/lua-5.4.6/src/lvm.c:381–402  ·  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

379** have different lengths.
380*/
381static int l_strcmp (const TString *ts1, const TString *ts2) {
382 const char *s1 = getstr(ts1);
383 size_t rl1 = tsslen(ts1); /* real length */
384 const char *s2 = getstr(ts2);
385 size_t rl2 = tsslen(ts2);
386 for (;;) { /* for each segment */
387 int temp = strcoll(s1, s2);
388 if (temp != 0) /* not equal? */
389 return temp; /* done */
390 else { /* strings are equal up to a '\0' */
391 size_t zl1 = strlen(s1); /* index of first '\0' in 's1' */
392 size_t zl2 = strlen(s2); /* index of first '\0' in 's2' */
393 if (zl2 == rl2) /* 's2' is finished? */
394 return (zl1 == rl1) ? 0 : 1; /* check 's1' */
395 else if (zl1 == rl1) /* 's1' is finished? */
396 return -1; /* 's1' is less than 's2' ('s2' is not finished) */
397 /* both strings longer than 'zl'; go on comparing after the '\0' */
398 zl1++; zl2++;
399 s1 += zl1; rl1 -= zl1; s2 += zl2; rl2 -= zl2;
400 }
401 }
402}
403
404
405/*

Callers 2

lessthanothersFunction · 0.70
lessequalothersFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected