21 #ifndef WINPR_CRT_STRING_H
22 #define WINPR_CRT_STRING_H
27 #include <winpr/config.h>
28 #include <winpr/winpr.h>
29 #include <winpr/wtypes.h>
31 WINPR_PRAGMA_DIAG_PUSH
32 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
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);
42 WINPR_API BOOL winpr_str_append(
const char* what,
char* buffer,
size_t size,
43 const char* separator);
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);
50 #define CSTR_LESS_THAN 1
52 #define CSTR_GREATER_THAN 3
57 #define CP_THREAD_ACP 3
62 #define MB_PRECOMPOSED 0x00000001
63 #define MB_COMPOSITE 0x00000002
64 #define MB_USEGLYPHCHARS 0x00000004
65 #define MB_ERR_INVALID_CHARS 0x00000008
67 WINPR_API
char* _strdup(
const char* strSource);
68 WINPR_API WCHAR* _wcsdup(
const WCHAR* strSource);
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);
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);
76 WINPR_API
size_t _wcslen(
const WCHAR* str);
77 WINPR_API
size_t _wcsnlen(
const WCHAR* str,
size_t maxNumberOfElements);
79 WINPR_API WCHAR* _wcsstr(
const WCHAR* str,
const WCHAR* strSearch);
81 WINPR_API WCHAR* _wcschr(
const WCHAR* str, WCHAR c);
82 WINPR_API WCHAR* _wcsrchr(
const WCHAR* str, WCHAR c);
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);
87 WINPR_API WCHAR* _wcsncat(WCHAR* dst,
const WCHAR* src,
size_t sz);
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
101 #if !defined(_WIN32) || defined(_UWP)
103 WINPR_API LPSTR CharUpperA(LPSTR lpsz);
104 WINPR_API LPWSTR CharUpperW(LPWSTR lpsz);
107 #define CharUpper CharUpperW
109 #define CharUpper CharUpperA
112 WINPR_API DWORD CharUpperBuffA(LPSTR lpsz, DWORD cchLength);
113 WINPR_API DWORD CharUpperBuffW(LPWSTR lpsz, DWORD cchLength);
116 #define CharUpperBuff CharUpperBuffW
118 #define CharUpperBuff CharUpperBuffA
121 WINPR_API LPSTR CharLowerA(LPSTR lpsz);
122 WINPR_API LPWSTR CharLowerW(LPWSTR lpsz);
125 #define CharLower CharLowerW
127 #define CharLower CharLowerA
130 WINPR_API DWORD CharLowerBuffA(LPSTR lpsz, DWORD cchLength);
131 WINPR_API DWORD CharLowerBuffW(LPWSTR lpsz, DWORD cchLength);
134 #define CharLowerBuff CharLowerBuffW
136 #define CharLowerBuff CharLowerBuffA
139 WINPR_API BOOL IsCharAlphaA(CHAR ch);
140 WINPR_API BOOL IsCharAlphaW(WCHAR ch);
143 #define IsCharAlpha IsCharAlphaW
145 #define IsCharAlpha IsCharAlphaA
148 WINPR_API BOOL IsCharAlphaNumericA(CHAR ch);
149 WINPR_API BOOL IsCharAlphaNumericW(WCHAR ch);
152 #define IsCharAlphaNumeric IsCharAlphaNumericW
154 #define IsCharAlphaNumeric IsCharAlphaNumericA
157 WINPR_API BOOL IsCharUpperA(CHAR ch);
158 WINPR_API BOOL IsCharUpperW(WCHAR ch);
161 #define IsCharUpper IsCharUpperW
163 #define IsCharUpper IsCharUpperA
166 WINPR_API BOOL IsCharLowerA(CHAR ch);
167 WINPR_API BOOL IsCharLowerW(WCHAR ch);
170 #define IsCharLower IsCharLowerW
172 #define IsCharLower IsCharLowerA
179 #define sprintf_s snprintf
180 #define _snprintf snprintf
181 #define _scprintf(...) snprintf(NULL, 0, __VA_ARGS__)
183 #define _scprintf(...) snprintf(NULL, 0, __VA_ARGS__)
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));
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));
219 WINPR_API SSIZE_T ConvertWCharToUtf8(
const WCHAR* wstr,
char* str,
size_t len);
238 WINPR_API SSIZE_T ConvertWCharNToUtf8(
const WCHAR* wstr,
size_t wlen,
char* str,
size_t len);
258 WINPR_API SSIZE_T ConvertMszWCharNToUtf8(
const WCHAR* wstr,
size_t wlen,
char* str,
size_t len);
275 WINPR_API SSIZE_T ConvertUtf8ToWChar(
const char* str, WCHAR* wstr,
size_t wlen);
294 WINPR_API SSIZE_T ConvertUtf8NToWChar(
const char* str,
size_t len, WCHAR* wstr,
size_t wlen);
314 WINPR_API SSIZE_T ConvertMszUtf8NToWChar(
const char* str,
size_t len, WCHAR* wstr,
size_t wlen);
326 WINPR_API
char* ConvertWCharToUtf8Alloc(
const WCHAR* wstr,
size_t* pSize);
340 WINPR_API
char* ConvertWCharNToUtf8Alloc(
const WCHAR* wstr,
size_t wlen,
size_t* pSize);
354 WINPR_API
char* ConvertMszWCharNToUtf8Alloc(
const WCHAR* wstr,
size_t wlen,
size_t* pSize);
366 WINPR_API WCHAR* ConvertUtf8ToWCharAlloc(
const char* str,
size_t* pSize);
380 WINPR_API WCHAR* ConvertUtf8NToWCharAlloc(
const char* str,
size_t len,
size_t* pSize);
394 WINPR_API WCHAR* ConvertMszUtf8NToWCharAlloc(
const char* str,
size_t len,
size_t* pSize);
404 WINPR_API
const WCHAR* InitializeConstWCharFromUtf8(
const char* str, WCHAR* buffer,
size_t len);
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));
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));
420 WINPR_API
const WCHAR* ByteSwapUnicode(WCHAR* wstr,
size_t length);
422 WINPR_API
size_t ConvertLineEndingToLF(
char* str,
size_t size);
423 WINPR_API
char* ConvertLineEndingToCRLF(
const char* str,
size_t* size);
425 WINPR_API
char* StrSep(
char** stringp,
const char* delim);
427 WINPR_API INT64 GetLine(
char** lineptr,
size_t* size, FILE* stream);
429 #if !defined(WINPR_HAVE_STRNDUP)
430 WINPR_ATTR_MALLOC(free, 1)
431 WINPR_API
char* strndup(const
char* s,
size_t n);
444 WINPR_ATTR_MALLOC(free, 1)
445 WINPR_API WCHAR* wcsndup(const WCHAR* s,
size_t n);
451 WINPR_PRAGMA_DIAG_POP