Line | Count | Source |
1 | | #include "prism/internal/strncasecmp.h" |
2 | | |
3 | | #include "prism/compiler/inline.h" |
4 | | |
5 | | /** |
6 | | * A locale-insensitive version of `tolower(3)` |
7 | | */ |
8 | | static PRISM_INLINE int |
9 | 20.5k | pm_tolower(int c) { |
10 | 20.5k | if ('A' <= c && c <= 'Z'11.5k ) { Branch (10:9): [True: 11.5k, False: 8.99k]
Branch (10:21): [True: 6.79k, False: 4.73k]
|
11 | 6.79k | return c | 0x20; |
12 | 6.79k | } |
13 | 13.7k | return c; |
14 | 20.5k | } |
15 | | |
16 | | /** |
17 | | * Compare two strings, ignoring case, up to the given length. Returns 0 if the |
18 | | * strings are equal, a negative number if string1 is less than string2, or a |
19 | | * positive number if string1 is greater than string2. |
20 | | * |
21 | | * Note that this is effectively our own implementation of strncasecmp, but it's |
22 | | * not available on all of the platforms we want to support so we're rolling it |
23 | | * here. |
24 | | */ |
25 | | int |
26 | 1.75k | pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length) { |
27 | 1.75k | size_t offset = 0; |
28 | 1.75k | int difference = 0; |
29 | | |
30 | 10.6k | while (offset < length && string1[offset] != '\0'10.2k ) { Branch (30:12): [True: 10.2k, False: 351]
Branch (30:31): [True: 10.2k, False: 24]
|
31 | 10.2k | if (string2[offset] == '\0') return string1[offset]0 ; Branch (31:13): [True: 0, False: 10.2k]
|
32 | 10.2k | if ((difference = pm_tolower(string1[offset]) - pm_tolower(string2[offset])) != 0) return difference1.37k ; Branch (32:13): [True: 1.37k, False: 8.88k]
|
33 | 8.88k | offset++; |
34 | 8.88k | } |
35 | | |
36 | 375 | return difference; |
37 | 1.75k | } |