MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / tcslicmp

Function tcslicmp

source/util.cpp:533–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

531
532
533int tcslicmp(LPTSTR aBuf1, LPTSTR aBuf2, size_t aLength1, size_t aLength2)
534// Similar to strnicmp but considers each aBuf to be a string of length aLength if aLength was
535// specified. In other words, unlike strnicmp() which would consider strnicmp("ab", "abc", 2)
536// [example verified correct] to be a match, this function would consider them to be
537// a mismatch. Another way of looking at it: aBuf1 and aBuf2 will be directly
538// compared to one another as though they were actually of length aLength1 and
539// aLength2, respectively and then passed to stricmp() (not strnicmp) as those
540// shorter strings. This behavior is useful for cases where you don't want
541// to have to bother with temporarily terminating a string so you can compare
542// only a substring to something else. The return value meaning is the
543// same as strnicmp(). If either aLength param is UINT_MAX (via the default
544// parameters or via explicit call), it will be assumed that the entire
545// length of the respective aBuf will be used.
546{
547 if (!aBuf1 || !aBuf2) return 0;
548 if (aLength1 == -1) aLength1 = _tcslen(aBuf1);
549 if (aLength2 == -1) aLength2 = _tcslen(aBuf2);
550 size_t least_length = aLength1 < aLength2 ? aLength1 : aLength2;
551 int diff;
552 for (size_t i = 0; i < least_length; ++i)
553 if ( diff = (int)(ctoupper(aBuf1[i]) - ctoupper(aBuf2[i])) )
554 return diff;
555 // Since the above didn't return, the strings are equal if they're the same length.
556 // Otherwise, the longer one is considered greater than the shorter one since the
557 // longer one's next character is by definition something non-zero. I'm not completely
558 // sure that this is the same policy followed by ANSI strcmp():
559 return (int)(aLength1 - aLength2);
560}
561
562
563

Callers 1

TextToSpecialFunction · 0.85

Calls 1

ctoupperFunction · 0.85

Tested by

no test coverage detected