Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
3.8 KiB

  1. #ifndef _STRUTIL_H_
  2. #define _STRUTIL_H_
  3. #include <nmutil.h>
  4. #include <stock.h>
  5. #include <wincrypt.h>
  6. INLINE BOOL
  7. IsEmptyStringA(LPCSTR pcsz)
  8. {
  9. return (NULL == pcsz) || ('\0' == *pcsz);
  10. }
  11. INLINE BOOL
  12. IsEmptyStringW(LPCWSTR pcwsz)
  13. {
  14. return (NULL == pcwsz) || (L'\0' == *pcwsz);
  15. }
  16. #if defined(UNICODE)
  17. #define IsEmptyString IsEmptyStringW
  18. #else // defined(UNICODE)
  19. #define IsEmptyString IsEmptyStringA
  20. #endif // defined(UNICODE)
  21. #define IS_EMPTY_STRING(s) (IsEmptyString(s))
  22. #define FEmptySz(psz) (IsEmptyString(psz))
  23. #define SetEmptySz(psz) (*(psz) = _T('\0'))
  24. // global helper functions for Unicode support in a DBCS environment
  25. int NMINTERNAL UnicodeCompare(PCWSTR s, PCWSTR t);
  26. PWSTR NMINTERNAL NewUnicodeString(PCWSTR wszText);
  27. BOOL NMINTERNAL UnicodeIsNumber(PCWSTR wszText);
  28. PWSTR NMINTERNAL DBCSToUnicode(UINT uCodePage, PCSTR szText);
  29. PSTR NMINTERNAL UnicodeToDBCS(UINT uCodePage, PCWSTR wszText);
  30. INLINE PWSTR AnsiToUnicode(PCSTR szText)
  31. {
  32. return DBCSToUnicode(CP_ACP, szText);
  33. }
  34. INLINE PWSTR OEMToUnicode(PCSTR szText)
  35. {
  36. return DBCSToUnicode(CP_OEMCP, szText);
  37. }
  38. INLINE PSTR UnicodeToAnsi(PCWSTR wszText)
  39. {
  40. return UnicodeToDBCS(CP_ACP, wszText);
  41. }
  42. INLINE PSTR UnicodeToOEM(PCWSTR wszText)
  43. {
  44. return UnicodeToDBCS(CP_OEMCP, wszText);
  45. }
  46. // Functions to convert between Quad Words (expressed as ULARGE_INTEGERs)
  47. // and ANSI strings.
  48. BOOL NMINTERNAL HexStringToQWordA(LPCSTR pcszString, ULARGE_INTEGER* pqw);
  49. int NMINTERNAL QWordToHexStringA(ULARGE_INTEGER qw, LPSTR pszString);
  50. // Function to convert from a hex string to a DWORD.
  51. DWORD NMINTERNAL DwFromHex(LPCTSTR pchHex);
  52. // CCHMAX_HEX_ULARGE_INTEGER - defines the minimum string buffer size needed
  53. // for the second parameter of QWordToHexStringA().
  54. #define CCHMAX_HEX_ULARGE_INTEGER 17 // 16 characters + n.t.
  55. #define CCH_HEX_DWORD 8
  56. #define CCH_HEX_QWORD 16
  57. #define BITS_PER_HEX_CHAR 4
  58. // Other Random string functions
  59. VOID NMINTERNAL GuidToSz(GUID * pguid, LPTSTR lpchDest);
  60. /* sizeof(GUID)*2 + 7 (includes NULL terminator) characters (see GuidToSz) */
  61. #define LENGTH_SZGUID_FORMATTED 39
  62. int WINAPI RtStrToInt(LPCTSTR lpSrc); // atoi()
  63. #define ATOI RtStrToInt
  64. #ifdef __cplusplus
  65. extern "C"{
  66. #endif
  67. UINT NMINTERNAL DecimalStringToUINT(LPCTSTR pcszString);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #ifdef __cplusplus
  72. extern "C"{
  73. #endif
  74. LPCTSTR NMINTERNAL _StrChr(LPCTSTR psz, TCHAR c);
  75. int NMINTERNAL _StrCmpN(LPCTSTR psz1, LPCTSTR psz2, UINT maxChars);
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. LPCTSTR NMINTERNAL _StrStr(LPCTSTR pcsz1, LPCTSTR pcsz2);
  80. LPCWSTR NMINTERNAL _StrStrW(LPCWSTR pcsz1, LPCWSTR pcsz2);
  81. LPSTR NMINTERNAL _StrPbrkA(LPCSTR pcszString, LPCSTR pcszSearch);
  82. LPWSTR NMINTERNAL _StrPbrkW(LPCWSTR pcszString, LPCWSTR pcszSearch);
  83. #if defined(UNICODE)
  84. #define _StrPbrk _StrPbrkW
  85. #else // defined(UNICODE)
  86. #define _StrPbrk _StrPbrkA
  87. #endif // defined(UNICODE)
  88. LPTSTR NMINTERNAL SzFindLastCh(LPTSTR lpsz, TCHAR ch);
  89. UINT NMINTERNAL TrimSz(PTCHAR psz);
  90. // Local LStrLenW function is unnecessary, since Windows 95 supports
  91. // lstrlenW natively
  92. #define LStrLenW lstrlenW
  93. // Map LStrCpyW to its Win32 equivalent for Unicode builds
  94. #if defined UNICODE
  95. #define LStrCpyW lstrcpyW
  96. #define LStrCpyNW lstrcpyn
  97. #else // defined UNICODE
  98. LPWSTR NMINTERNAL LStrCpyW(LPWSTR pszDest, LPWSTR pszSrc);
  99. LPWSTR NMINTERNAL LStrCpyNW(LPWSTR pszDest, LPCWSTR pszSrc, INT iMaxLength);
  100. #endif // defined UNICODE
  101. LPWSTR NMINTERNAL _StrLwrW(LPWSTR pwszSrc);
  102. #ifdef __cplusplus
  103. class CHash
  104. {
  105. public:
  106. CHash();
  107. ~CHash();
  108. DWORD GetHashedData(PBYTE pbData, DWORD cbData, void ** ppvHashedData);
  109. private:
  110. HCRYPTPROV m_hProv;
  111. HCRYPTHASH m_hHash;
  112. PBYTE m_pbHashedData;
  113. DWORD m_cbHashedData;
  114. BOOL m_fReady;
  115. };
  116. #endif
  117. DWORD NMINTERNAL HashPasswd(PBYTE pbPasswd, DWORD cbPasswd, void **ppvData);
  118. #endif // ndef STRUTIL_H