FreeRDP
winpr/include/winpr/string.h
1 
21 #ifndef WINPR_CRT_STRING_H
22 #define WINPR_CRT_STRING_H
23 
24 #include <wchar.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <winpr/config.h>
28 #include <winpr/winpr.h>
29 #include <winpr/wtypes.h>
30 
31 WINPR_PRAGMA_DIAG_PUSH
32 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
33 
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38 
39  WINPR_API char* winpr_str_url_encode(const char* str, size_t len);
40  WINPR_API char* winpr_str_url_decode(const char* str, size_t len);
41 
42  WINPR_API BOOL winpr_str_append(const char* what, char* buffer, size_t size,
43  const char* separator);
44 
45  WINPR_API int winpr_asprintf(char** s, size_t* slen, const char* templ, ...);
46  WINPR_API int winpr_vasprintf(char** s, size_t* slen, const char* templ, va_list ap);
47 
48 #ifndef _WIN32
49 
50 #define CSTR_LESS_THAN 1
51 #define CSTR_EQUAL 2
52 #define CSTR_GREATER_THAN 3
53 
54 #define CP_ACP 0
55 #define CP_OEMCP 1
56 #define CP_MACCP 2
57 #define CP_THREAD_ACP 3
58 #define CP_SYMBOL 42
59 #define CP_UTF7 65000
60 #define CP_UTF8 65001
61 
62 #define MB_PRECOMPOSED 0x00000001
63 #define MB_COMPOSITE 0x00000002
64 #define MB_USEGLYPHCHARS 0x00000004
65 #define MB_ERR_INVALID_CHARS 0x00000008
66 
67  WINPR_API char* _strdup(const char* strSource);
68  WINPR_API WCHAR* _wcsdup(const WCHAR* strSource);
69 
70  WINPR_API int _stricmp(const char* string1, const char* string2);
71  WINPR_API int _strnicmp(const char* string1, const char* string2, size_t count);
72 
73  WINPR_API int _wcscmp(const WCHAR* string1, const WCHAR* string2);
74  WINPR_API int _wcsncmp(const WCHAR* string1, const WCHAR* string2, size_t count);
75 
76  WINPR_API size_t _wcslen(const WCHAR* str);
77  WINPR_API size_t _wcsnlen(const WCHAR* str, size_t maxNumberOfElements);
78 
79  WINPR_API WCHAR* _wcsstr(const WCHAR* str, const WCHAR* strSearch);
80 
81  WINPR_API WCHAR* _wcschr(const WCHAR* str, WCHAR c);
82  WINPR_API WCHAR* _wcsrchr(const WCHAR* str, WCHAR c);
83 
84  WINPR_API char* strtok_s(char* strToken, const char* strDelimit, char** context);
85  WINPR_API WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context);
86 
87  WINPR_API WCHAR* _wcsncat(WCHAR* dst, const WCHAR* src, size_t sz);
88 #else
89 
90 #define _wcscmp wcscmp
91 #define _wcsncmp wcsncmp
92 #define _wcslen wcslen
93 #define _wcsnlen wcsnlen
94 #define _wcsstr wcsstr
95 #define _wcschr wcschr
96 #define _wcsrchr wcsrchr
97 #define _wcsncat wcsncat
98 
99 #endif /* _WIN32 */
100 
101 #if !defined(_WIN32) || defined(_UWP)
102 
103  WINPR_API LPSTR CharUpperA(LPSTR lpsz);
104  WINPR_API LPWSTR CharUpperW(LPWSTR lpsz);
105 
106 #ifdef UNICODE
107 #define CharUpper CharUpperW
108 #else
109 #define CharUpper CharUpperA
110 #endif
111 
112  WINPR_API DWORD CharUpperBuffA(LPSTR lpsz, DWORD cchLength);
113  WINPR_API DWORD CharUpperBuffW(LPWSTR lpsz, DWORD cchLength);
114 
115 #ifdef UNICODE
116 #define CharUpperBuff CharUpperBuffW
117 #else
118 #define CharUpperBuff CharUpperBuffA
119 #endif
120 
121  WINPR_API LPSTR CharLowerA(LPSTR lpsz);
122  WINPR_API LPWSTR CharLowerW(LPWSTR lpsz);
123 
124 #ifdef UNICODE
125 #define CharLower CharLowerW
126 #else
127 #define CharLower CharLowerA
128 #endif
129 
130  WINPR_API DWORD CharLowerBuffA(LPSTR lpsz, DWORD cchLength);
131  WINPR_API DWORD CharLowerBuffW(LPWSTR lpsz, DWORD cchLength);
132 
133 #ifdef UNICODE
134 #define CharLowerBuff CharLowerBuffW
135 #else
136 #define CharLowerBuff CharLowerBuffA
137 #endif
138 
139  WINPR_API BOOL IsCharAlphaA(CHAR ch);
140  WINPR_API BOOL IsCharAlphaW(WCHAR ch);
141 
142 #ifdef UNICODE
143 #define IsCharAlpha IsCharAlphaW
144 #else
145 #define IsCharAlpha IsCharAlphaA
146 #endif
147 
148  WINPR_API BOOL IsCharAlphaNumericA(CHAR ch);
149  WINPR_API BOOL IsCharAlphaNumericW(WCHAR ch);
150 
151 #ifdef UNICODE
152 #define IsCharAlphaNumeric IsCharAlphaNumericW
153 #else
154 #define IsCharAlphaNumeric IsCharAlphaNumericA
155 #endif
156 
157  WINPR_API BOOL IsCharUpperA(CHAR ch);
158  WINPR_API BOOL IsCharUpperW(WCHAR ch);
159 
160 #ifdef UNICODE
161 #define IsCharUpper IsCharUpperW
162 #else
163 #define IsCharUpper IsCharUpperA
164 #endif
165 
166  WINPR_API BOOL IsCharLowerA(CHAR ch);
167  WINPR_API BOOL IsCharLowerW(WCHAR ch);
168 
169 #ifdef UNICODE
170 #define IsCharLower IsCharLowerW
171 #else
172 #define IsCharLower IsCharLowerA
173 #endif
174 
175 #endif
176 
177 #ifndef _WIN32
178 
179 #define sprintf_s snprintf
180 #define _snprintf snprintf
181 #define _scprintf(...) snprintf(NULL, 0, __VA_ARGS__)
182 
183 #define _scprintf(...) snprintf(NULL, 0, __VA_ARGS__)
184 
185  /* Unicode Conversion */
186 
187 #if defined(WITH_WINPR_DEPRECATED)
188  WINPR_API WINPR_DEPRECATED_VAR("Use ConvertUtf8ToWChar instead",
189  int MultiByteToWideChar(UINT CodePage, DWORD dwFlags,
190  LPCSTR lpMultiByteStr, int cbMultiByte,
191  LPWSTR lpWideCharStr, int cchWideChar));
192 
193  WINPR_API WINPR_DEPRECATED_VAR("Use ConvertWCharToUtf8 instead",
194  int WideCharToMultiByte(UINT CodePage, DWORD dwFlags,
195  LPCWSTR lpWideCharStr, int cchWideChar,
196  LPSTR lpMultiByteStr, int cbMultiByte,
197  LPCSTR lpDefaultChar,
198  LPBOOL lpUsedDefaultChar));
199 #endif
200 
201 #endif
202 
203  /* Extended API */
219  WINPR_API SSIZE_T ConvertWCharToUtf8(const WCHAR* wstr, char* str, size_t len);
220 
238  WINPR_API SSIZE_T ConvertWCharNToUtf8(const WCHAR* wstr, size_t wlen, char* str, size_t len);
239 
258  WINPR_API SSIZE_T ConvertMszWCharNToUtf8(const WCHAR* wstr, size_t wlen, char* str, size_t len);
259 
275  WINPR_API SSIZE_T ConvertUtf8ToWChar(const char* str, WCHAR* wstr, size_t wlen);
276 
294  WINPR_API SSIZE_T ConvertUtf8NToWChar(const char* str, size_t len, WCHAR* wstr, size_t wlen);
295 
314  WINPR_API SSIZE_T ConvertMszUtf8NToWChar(const char* str, size_t len, WCHAR* wstr, size_t wlen);
315 
326  WINPR_API char* ConvertWCharToUtf8Alloc(const WCHAR* wstr, size_t* pSize);
327 
340  WINPR_API char* ConvertWCharNToUtf8Alloc(const WCHAR* wstr, size_t wlen, size_t* pSize);
341 
354  WINPR_API char* ConvertMszWCharNToUtf8Alloc(const WCHAR* wstr, size_t wlen, size_t* pSize);
355 
366  WINPR_API WCHAR* ConvertUtf8ToWCharAlloc(const char* str, size_t* pSize);
367 
380  WINPR_API WCHAR* ConvertUtf8NToWCharAlloc(const char* str, size_t len, size_t* pSize);
381 
394  WINPR_API WCHAR* ConvertMszUtf8NToWCharAlloc(const char* str, size_t len, size_t* pSize);
395 
404  WINPR_API const WCHAR* InitializeConstWCharFromUtf8(const char* str, WCHAR* buffer, size_t len);
405 
406 #if defined(WITH_WINPR_DEPRECATED)
407  WINPR_API WINPR_DEPRECATED_VAR("Use ConvertUtf8ToWChar functions instead",
408  int ConvertToUnicode(UINT CodePage, DWORD dwFlags,
409  LPCSTR lpMultiByteStr, int cbMultiByte,
410  LPWSTR* lpWideCharStr, int cchWideChar));
411 
412  WINPR_API WINPR_DEPRECATED_VAR("Use ConvertWCharToUtf8 functions instead",
413  int ConvertFromUnicode(UINT CodePage, DWORD dwFlags,
414  LPCWSTR lpWideCharStr, int cchWideChar,
415  LPSTR* lpMultiByteStr, int cbMultiByte,
416  LPCSTR lpDefaultChar,
417  LPBOOL lpUsedDefaultChar));
418 #endif
419 
420  WINPR_API const WCHAR* ByteSwapUnicode(WCHAR* wstr, size_t length);
421 
422  WINPR_API size_t ConvertLineEndingToLF(char* str, size_t size);
423  WINPR_API char* ConvertLineEndingToCRLF(const char* str, size_t* size);
424 
425  WINPR_API char* StrSep(char** stringp, const char* delim);
426 
427  WINPR_API INT64 GetLine(char** lineptr, size_t* size, FILE* stream);
428 
429 #if !defined(WINPR_HAVE_STRNDUP)
430  WINPR_ATTR_MALLOC(free, 1)
431  WINPR_API char* strndup(const char* s, size_t n);
432 #endif
433 
444  WINPR_ATTR_MALLOC(free, 1)
445  WINPR_API WCHAR* wcsndup(const WCHAR* s, size_t n);
446 
447 #ifdef __cplusplus
448 }
449 #endif
450 
451 WINPR_PRAGMA_DIAG_POP
452 
453 #endif /* WINPR_CRT_STRING_H */