MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / l_strcmp

Function l_strcmp

libraries/AP_Scripting/lua/src/lvm.c:252–272  ·  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

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

Callers 2

luaV_lessthanFunction · 0.85
luaV_lessequalFunction · 0.85

Calls 1

strlenFunction · 0.85

Tested by

no test coverage detected