Ruby: prism/util/pm_strncasecmp.c Source File

Ruby 3.4.7p58 (2025-10-08 revision 7a5688e2a27668e48f8d6ff4af5b2208b98a2f5e)

pm_strncasecmp.c
1#include "prism/util/pm_strncasecmp.h"
2
6static inline int
7pm_tolower(int c)
8{
9 if ('A' <= c && c <= 'Z') {
10 return c | 0x20;
11 }
12 return c;
13}
14
24int
25pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length) {
26 size_t offset = 0;
27 int difference = 0;
28
29 while (offset < length && string1[offset] != '\0') {
30 if (string2[offset] == '\0') return string1[offset];
31 if ((difference = pm_tolower(string1[offset]) - pm_tolower(string2[offset])) != 0) return difference;
32 offset++;
33 }
34
35 return difference;
36}
pm_strncasecmp.h
A custom strncasecmp implementation.