123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- /**
- * WinPR: Windows Portable Runtime
- * String Manipulation (CRT)
- *
- * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
- * Copyright 2016 David PHAM-VAN <d.phamvan@inuvika.com>
- *
- * 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.
- */
- #ifndef WINPR_CRT_STRING_H
- #define WINPR_CRT_STRING_H
- #include <wchar.h>
- #include <string.h>
- #include <stdarg.h>
- #include <winpr/winpr.h>
- #include <winpr/wtypes.h>
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- #ifndef _WIN32
- #define CSTR_LESS_THAN 1
- #define CSTR_EQUAL 2
- #define CSTR_GREATER_THAN 3
- #define CP_ACP 0
- #define CP_OEMCP 1
- #define CP_MACCP 2
- #define CP_THREAD_ACP 3
- #define CP_SYMBOL 42
- #define CP_UTF7 65000
- #define CP_UTF8 65001
- #define MB_PRECOMPOSED 0x00000001
- #define MB_COMPOSITE 0x00000002
- #define MB_USEGLYPHCHARS 0x00000004
- #define MB_ERR_INVALID_CHARS 0x00000008
- #define _TRUNCATE ((size_t)-1)
- WINPR_API char* _strdup(const char* strSource);
- WINPR_API WCHAR* _wcsdup(const WCHAR* strSource);
- WINPR_API int _stricmp(const char* string1, const char* string2);
- WINPR_API int _strnicmp(const char* string1, const char* string2, size_t count);
- WINPR_API int _wcscmp(const WCHAR* string1, const WCHAR* string2);
- WINPR_API int _wcsicmp(const WCHAR* string1, const WCHAR* string2);
- WINPR_API int _wcsnicmp(const WCHAR* string1, const WCHAR* string2, size_t count);
- WINPR_API int _wcsncmp(const WCHAR* string1, const WCHAR* string2, size_t count);
- WINPR_API size_t _wcslen(const WCHAR* str);
- WINPR_API size_t _wcsnlen(const WCHAR* str, size_t maxNumberOfElements);
- WINPR_API WCHAR* _wcschr(const WCHAR* str, WCHAR c);
- WINPR_API WCHAR* _wcsrchr(const WCHAR* str, WCHAR c);
- WINPR_API char* strtok_s(char* strToken, const char* strDelimit, char** context);
- WINPR_API WCHAR* wcstok_s(WCHAR* strToken, const WCHAR* strDelimit, WCHAR** context);
- #define stricmp _stricmp
- #define strnicmp _strnicmp
- #define strcpy_s(dst, size, src) strcpy(dst, src)
- #define strncpy_s(a, b, c, d) strncpy(a, c, d)
- #else
- #define _wcscmp wcscmp
- #define _wcslen wcslen
- #define _wcsnlen wcsnlen
- #define _wcschr wcschr
- #define _wcsrchr wcsrchr
- #endif
- #if !defined(_WIN32) || defined(_UWP)
- WINPR_API LPSTR CharUpperA(LPSTR lpsz);
- WINPR_API LPWSTR CharUpperW(LPWSTR lpsz);
- #ifdef UNICODE
- #define CharUpper CharUpperW
- #else
- #define CharUpper CharUpperA
- #endif
- WINPR_API DWORD CharUpperBuffA(LPSTR lpsz, DWORD cchLength);
- WINPR_API DWORD CharUpperBuffW(LPWSTR lpsz, DWORD cchLength);
- #ifdef UNICODE
- #define CharUpperBuff CharUpperBuffW
- #else
- #define CharUpperBuff CharUpperBuffA
- #endif
- WINPR_API LPSTR CharLowerA(LPSTR lpsz);
- WINPR_API LPWSTR CharLowerW(LPWSTR lpsz);
- #ifdef UNICODE
- #define CharLower CharLowerW
- #else
- #define CharLower CharLowerA
- #endif
- WINPR_API DWORD CharLowerBuffA(LPSTR lpsz, DWORD cchLength);
- WINPR_API DWORD CharLowerBuffW(LPWSTR lpsz, DWORD cchLength);
- #ifdef UNICODE
- #define CharLowerBuff CharLowerBuffW
- #else
- #define CharLowerBuff CharLowerBuffA
- #endif
- WINPR_API BOOL IsCharAlphaA(CHAR ch);
- WINPR_API BOOL IsCharAlphaW(WCHAR ch);
- #ifdef UNICODE
- #define IsCharAlpha IsCharAlphaW
- #else
- #define IsCharAlpha IsCharAlphaA
- #endif
- WINPR_API BOOL IsCharAlphaNumericA(CHAR ch);
- WINPR_API BOOL IsCharAlphaNumericW(WCHAR ch);
- #ifdef UNICODE
- #define IsCharAlphaNumeric IsCharAlphaNumericW
- #else
- #define IsCharAlphaNumeric IsCharAlphaNumericA
- #endif
- WINPR_API BOOL IsCharUpperA(CHAR ch);
- WINPR_API BOOL IsCharUpperW(WCHAR ch);
- #ifdef UNICODE
- #define IsCharUpper IsCharUpperW
- #else
- #define IsCharUpper IsCharUpperA
- #endif
- WINPR_API BOOL IsCharLowerA(CHAR ch);
- WINPR_API BOOL IsCharLowerW(WCHAR ch);
- #ifdef UNICODE
- #define IsCharLower IsCharLowerW
- #else
- #define IsCharLower IsCharLowerA
- #endif
- WINPR_API int lstrlenA(LPCSTR lpString);
- WINPR_API int lstrlenW(LPCWSTR lpString);
- #ifdef UNICODE
- #define lstrlen lstrlenW
- #else
- #define lstrlen lstrlenA
- #endif
- WINPR_API int lstrcmpA(LPCSTR lpString1, LPCSTR lpString2);
- WINPR_API int lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2);
- #ifdef UNICODE
- #define lstrcmp lstrcmpW
- #else
- #define lstrcmp lstrcmpA
- #endif
- #endif
- #ifndef _WIN32
- #define sprintf_s snprintf
- #define _snprintf snprintf
- #define _vsnprintf vsnprintf
- #define _scprintf(...) snprintf(NULL, 0, __VA_ARGS__)
- #if 0
- #define _vscprintf(...) vsnprintf(NULL, 0, __VA_ARGS__)
- #else
- WINPR_API int _vscprintf(const char* format, va_list pargs);
- #endif
- WINPR_API int _memicmp(const void* first, const void* last, unsigned int count);
- WINPR_API VOID OutputDebugStringA(LPCSTR lpOutputString);
- WINPR_API VOID OutputDebugStringW(LPCSTR lpOutputString);
- WINPR_API int _vscwprintf(const WCHAR* format, va_list arglist);
- WINPR_API int _scwprintf(const WCHAR* format, ...);
-
- //TODO: check its validity.
- WINPR_API int _vsnprintf_s(char* dst, size_t sz_in_byte, size_t max_count, const char* format, va_list arglist);
- //TODO: check its validity.
- WINPR_API int _vsnwprintf_s(WCHAR* dst, size_t sz_in_byte, size_t max_count, const WCHAR* format, va_list arglist);
- //TODO: check its validity.
- WINPR_API int wvsprintfA(LPSTR, LPCSTR, va_list arglist);
- //TODO: check its validity.
- WINPR_API int wvsprintfW(LPWSTR, LPCWSTR, va_list arglist);
- #ifdef UNICODE
- #define wvsprintf wvsprintfW
- #else
- #define wvsprintf wvsprintfA
- #endif
- WINPR_API int wsprintfA(LPSTR, LPCSTR, ...);
- #define fprintf_s fprintf
- #define swprintf_s swprintf
- #define sscanf_s sscanf
- #ifdef UNICODE
- #define OutputDebugString OutputDebugStringW
- #else
- #define OutputDebugString OutputDebugStringA
- #endif
- /* Unicode Conversion */
- WINPR_API int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
- int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
- WINPR_API int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr,
- int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte,
- LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar);
- #endif
- /* Extended API */
- WINPR_API int ConvertToUnicode(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
- int cbMultiByte, LPWSTR* lpWideCharStr, int cchWideChar);
- WINPR_API int ConvertFromUnicode(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr,
- int cchWideChar, LPSTR* lpMultiByteStr, int cbMultiByte,
- LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar);
- WINPR_API void ByteSwapUnicode(WCHAR* wstr, int length);
- WINPR_API int ConvertLineEndingToLF(char* str, int size);
- WINPR_API char* ConvertLineEndingToCRLF(const char* str, int* size);
- WINPR_API char* StrSep(char** stringp, const char* delim);
- WINPR_API INT64 GetLine(char** lineptr, size_t* size, FILE* stream);
- #ifdef __cplusplus
- }
- #endif
- #endif /* WINPR_CRT_STRING_H */
|