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

Function l_strcmp

third-party/lua-5.3.5/src/lvm.c:248–268  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

246** of the strings.
247*/
248static int l_strcmp (const TString *ls, const TString *rs) {
249 const char *l = getstr(ls);
250 size_t ll = tsslen(ls);
251 const char *r = getstr(rs);
252 size_t lr = tsslen(rs);
253 for (;;) { /* for each segment */
254 int temp = strcoll(l, r);
255 if (temp != 0) /* not equal? */
256 return temp; /* done */
257 else { /* strings are equal up to a '\0' */
258 size_t len = strlen(l); /* index of first '\0' in both strings */
259 if (len == lr) /* 'rs' is finished? */
260 return (len == ll) ? 0 : 1; /* check 'ls' */
261 else if (len == ll) /* 'ls' is finished? */
262 return -1; /* 'ls' is smaller than 'rs' ('rs' is not finished) */
263 /* both strings longer than 'len'; go on comparing after the '\0' */
264 len++;
265 l += len; ll -= len; r += len; lr -= len;
266 }
267 }
268}
269
270
271/*

Callers 2

luaV_lessthanFunction · 0.70
luaV_lessequalFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected