blob: 3bc0337a897be380f92e2e76b782048f1c1bd7f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include <BH/String.h>
#include <BH/Unicode.h>
#include <string.h>
#include <stdlib.h>
char *BH_StringDup(const char *string)
{
size_t length;
char *result;
if (!string)
return NULL;
length = strlen(string) + 1;
result = malloc(length);
if (result)
memcpy(result, string, length);
return result;
}
int BH_StringCompare(const char *s1,
const char *s2)
{
return strcmp(s1, s2);
}
int BH_StringCompareCaseless(const char *s1,
const char *s2)
{
uint32_t c1, c2;
while (*s1 && *s2)
{
s1 += BH_UnicodeDecodeUtf8(s1, 4, &c1);
s2 += BH_UnicodeDecodeUtf8(s2, 4, &c2);
c1 = BH_UnicodeLower(c1);
c2 = BH_UnicodeLower(c2);
if (c1 != c2)
return (c1 < c2) ? -1 : 1;
}
return (!*s1) ? (!*s2 ? 0 : -1) : 1;
}
|