summaryrefslogtreecommitdiff
path: root/Build/source/libs/graphite/src/segment/Platform.cpp
blob: 30ec3f4bf1f200598a4e79a8b6e682dd2f3ca443 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "GrPlatform.h"

#ifdef _WIN32
#include "windows.h"

namespace gr
{

size_t Platform_UnicodeToANSI(const utf16 * prgchwSrc, size_t cchwSrc, char * prgchsDst, size_t cchsDst)
{
	return ::WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)prgchwSrc, cchwSrc, prgchsDst, cchsDst, NULL, NULL);
}

size_t Platform_AnsiToUnicode(const char * prgchsSrc, size_t cchsSrc, utf16 * prgchwDst, size_t cchwDst)
{
	return ::MultiByteToWideChar(CP_ACP, 0, prgchsSrc, cchsSrc, (LPWSTR)prgchwDst, cchwDst);
}

size_t Platform_8bitToUnicode(int nCodePage, const char * prgchsSrc, int cchsSrc,
	utf16 * prgchwDst, int cchwDst)
{
	return ::MultiByteToWideChar(nCodePage, 0, prgchsSrc, cchsSrc, (LPWSTR)prgchwDst, cchwDst);
}

size_t utf8len(const char *s)
{
	return mbstowcs(NULL,s,0);
}

utf16 *utf16cpy(utf16 *dest, const utf16 *src)
{
	return (utf16*)wcscpy((wchar_t*)dest, (const wchar_t*)src);
}

utf16 *utf16ncpy(utf16 *dest, const utf16 *src, size_t n)
{
	return (utf16*)wcsncpy((wchar_t*)dest, (const wchar_t*)src, n);
}

utf16 *utf16ncpy(utf16 *dest, const char *src, size_t n)
{
	#ifdef UTF16DEBUG
	std::cerr << "utf16ncpy8: " << src << std::endl;
	#endif
	Platform_AnsiToUnicode(src, strlen(src), dest, n);
	return dest;
}


size_t utf16len(const utf16 *s)
{
	return wcslen((const wchar_t*)s);
}

int utf16cmp(const utf16 *s1, const utf16 *s2)
{
return wcscmp((const wchar_t*)s1, (const wchar_t*)s2);
}

int utf16ncmp(const utf16 *s1, const utf16 *s2, size_t n)
{
	return wcsncmp((const wchar_t*)s1, (const wchar_t*)s2, n);
}

int utf16cmp(const utf16 *s1, const char *s2)
{
	while (*s1 && s2)
	{
		if (*s1 < *s2)
		{
			return -1;
		}
		if (*s1 > *s2)
		{
			return 1;
		}
		*s1++;
		*s2++;
	}
	if (*s1) return -1;
	else if (*s2) return 1;
	return 0;
}

}
#else // not _WIN32

#include <iostream>
#include <stdlib.h>
#include <string.h>

#ifndef HAVE_FABSF
float fabsf(float x)
{
    return (x < 0.0f) ? -x : x;
}
#endif

namespace gr
{

size_t utf16len(const utf16 *s)
{
	// assumes NULL terminated strings
	const utf16 *start = s;
	for (; *s; ++s);
	
	return s - start;
}

} // namespace gr
#endif // _WIN32