mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
LibC: Implement str{n}casecmp
This commit is contained in:
parent
2f4e7edee5
commit
f0f5dd6cef
2 changed files with 32 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include "ctype.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -91,6 +92,35 @@ int strncmp(const char* s1, const char* s2, size_t n)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int strcasecmp(const char* s1, const char* s2)
|
||||
{
|
||||
int c1, c2;
|
||||
for (;;) {
|
||||
c1 = tolower(*s1++);
|
||||
c2 = tolower(*s2++);
|
||||
if (c1 == 0 || c1 != c2) {
|
||||
return c1 - c2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int strncasecmp(const char* s1, const char* s2, size_t n)
|
||||
{
|
||||
if (n == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (n-- != 0 && tolower(*s1) == tolower(*s2)) {
|
||||
if (n == 0 || *s1 == '\0' || *s2 == '\0') {
|
||||
break;
|
||||
}
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return tolower(*s1) - tolower(*s2);
|
||||
}
|
||||
|
||||
int memcmp(const void* v1, const void* v2, size_t n)
|
||||
{
|
||||
auto* s1 = (const uint8_t*)v1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue