-
Notifications
You must be signed in to change notification settings - Fork 0
/
ts_string.h
188 lines (146 loc) · 4.29 KB
/
ts_string.h
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Copyright 2013 Marco Lizza ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* wcecompat: Windows CE C Runtime Library "compatibility" library.
*
* Copyright (C) 2001-2002 Essemer Pty Ltd. All rights reserved.
* http://www.essemer.com.au/
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __wcecompat__ts_string_h__
#define __wcecompat__ts_string_h__
#include <string.h>
#include <windows.h>
void ascii2unicode(const char* ascii, WCHAR* unicode);
void unicode2ascii(const WCHAR* unicode, char* ascii);
void ascii2unicode(const char* ascii, WCHAR* unicode, int maxChars);
void unicode2ascii(const WCHAR* unicode, char* ascii, int maxChars);
//
// ascii/unicode typesafe versions of strlen
//
inline size_t ts_strlen(const char* str)
{
return strlen(str);
}
inline size_t ts_strlen(const wchar_t* str)
{
return wcslen(str);
}
//
// ascii/unicode typesafe versions of strsize
// (returns size in bytes of str, not num characters as strlen does. Does not include zero termination)
//
inline size_t ts_strsize(const char* str)
{
return strlen(str);
}
inline size_t ts_strsize(const wchar_t* str)
{
return wcslen(str)*2;
}
//
// ascii/unicode typesafe versions of strsize
// (returns size in bytes of str, not num characters as strlen does. Includes zero termination)
//
inline size_t ts_strsizez(const char* str)
{
return strlen(str)+1;
}
inline size_t ts_strsizez(const WCHAR* str)
{
return (wcslen(str)+1)*2;
}
//
// ascii/unicode typesafe versions of strcpy
//
inline char* ts_strcpy(char* dest, const char* src)
{
return strcpy(dest, src);
}
inline char* ts_strcpy(char* dest, const WCHAR* src)
{
unicode2ascii(src, dest);
return dest;
}
inline WCHAR* ts_strcpy(WCHAR* dest, const char* src)
{
ascii2unicode(src, dest);
return dest;
}
inline WCHAR* ts_strcpy(WCHAR* dest, WCHAR* src)
{
return wcscpy(dest, src);
}
//
// ascii/unicode typesafe versions of strncpy
//
inline char* ts_strncpy(char* dest, const char* src, int n)
{
return strncpy(dest, src, n);
}
inline char* ts_strncpy(char* dest, const WCHAR* src, int n)
{
unicode2ascii(src, dest, n);
return dest;
}
inline WCHAR* ts_strncpy(WCHAR* dest, const char* src, int n)
{
ascii2unicode(src, dest, n);
return dest;
}
inline WCHAR* ts_strncpy(WCHAR* dest, const WCHAR* src, int n)
{
return wcsncpy(dest, src, n);
}
//
// ascii/unicode typesafe versions of strcat
//
inline char* ts_strcat(char* dest, const char* src)
{
return strcat(dest, src);
}
char* ts_strcat(char* dest, const WCHAR* src);
WCHAR* ts_strcat(WCHAR* dest, const char* src);
inline WCHAR* ts_strcat(WCHAR* dest, const WCHAR* src)
{
return wcscat(dest, src);
}
//
// ascii/unicode typesafe versions of strdup
//
inline char* ts_strdup(const char* str)
{
return _strdup(str);
}
char* ts_strdup_unicode_to_ascii(const WCHAR* str);
inline WCHAR* ts_strdup(const WCHAR* str)
{
return wcsdup(str);
}
WCHAR* ts_strdup_ascii_to_unicode(const char* str);
#endif /* __wcecompat__ts_string_h__ */