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.

185 lines
5.4 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 1998-2000 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: fileutil.h
  6. //
  7. // Description:
  8. //
  9. // IU string utility library, providing functions available
  10. // only in CRT or SHLWAPI
  11. //
  12. //=======================================================================
  13. #ifndef __STRINGUTIL_H_INCLUDED__
  14. #include <ole2.h>
  15. #include <shlwapi.h>
  16. // ----------------------------------------------------------------------
  17. //
  18. // Public function StrChr() - same as shlwapi StrChr()
  19. // Searches a string for the first occurrence of a character that
  20. // matches the specified character. The comparison is case sensitive.
  21. //
  22. // Input:
  23. // lpStart - Address of the string to be searched
  24. // wMatch - Character to be used for comparison
  25. //
  26. // Return:
  27. // Returns the address of the first occurrence of the character in
  28. // the string if successful, or NULL otherwise.
  29. //
  30. // ----------------------------------------------------------------------
  31. LPCTSTR MyStrChr(LPCTSTR lpStart, const TCHAR wMatch);
  32. // ----------------------------------------------------------------------
  33. //
  34. // Public function StrChrI() - same as shlwapi StrChrI()
  35. // Searches a string for the first occurrence of a character that
  36. // matches the specified character. The comparison is case INsensitive.
  37. //
  38. // Input:
  39. // lpStart - Address of the string to be searched
  40. // wMatch - Character to be used for comparison
  41. //
  42. // Return:
  43. // Returns the address of the first occurrence of the character in
  44. // the string if successful, or NULL otherwise.
  45. //
  46. // ----------------------------------------------------------------------
  47. LPCTSTR MyStrChrI(LPCTSTR lpStart, const TCHAR wMatch);
  48. // ----------------------------------------------------------------------
  49. //
  50. // Public function StrRChr() - same as shlwapi StrRChr()
  51. // Searches a string for the last occurrence of a character that
  52. // matches the specified character. The comparison is case sensitive.
  53. //
  54. // Input:
  55. // lpStart - Address of the string to be searched
  56. // lpEnd - Address of the end of the string (NOT included in the search)
  57. // wMatch - Character to be used for comparison
  58. //
  59. // Return:
  60. // Returns the address of the last occurrence of the character in
  61. // the string if successful, or NULL otherwise.
  62. //
  63. // ----------------------------------------------------------------------
  64. LPCTSTR MyStrRChr(LPCTSTR lpStart, LPCTSTR lpEnd, const TCHAR wMatch);
  65. // ----------------------------------------------------------------------
  66. //
  67. // Private helper function to compare the contents of
  68. // two BSTRs
  69. //
  70. // ----------------------------------------------------------------------
  71. inline int CompareBSTRs(BSTR bstr1, BSTR bstr2)
  72. {
  73. if (NULL == bstr1)
  74. {
  75. if (NULL == bstr2)
  76. {
  77. // Consider them equal
  78. return 0;
  79. }
  80. else
  81. {
  82. // Consider bstr1 < bstr2
  83. return -1;
  84. }
  85. }
  86. else if (NULL == bstr2)
  87. {
  88. // bstr1 isn't NULL (already checked) so consider bstr1 > bstr 2
  89. return 1;
  90. }
  91. //
  92. // Neither bstr is NULL, so we'll do a SHLWAPI compare of the first
  93. // string in each BSTR
  94. //
  95. LPWSTR p1 = (LPWSTR)((LPOLESTR) bstr1);
  96. LPWSTR p2 = (LPWSTR)((LPOLESTR) bstr2);
  97. return StrCmpIW(p1, p2);
  98. };
  99. inline BOOL CompareBSTRsEqual(BSTR bstr1, BSTR bstr2)
  100. {
  101. return (CompareBSTRs(bstr1, bstr2) == 0);
  102. };
  103. // ----------------------------------------------------------------------
  104. //
  105. // Convert a long number content in bstr into long
  106. // if error, 0 returned.
  107. //
  108. // ----------------------------------------------------------------------
  109. LONG MyBSTR2L(BSTR bstrLongNumber);
  110. #define MyBSTR2UL(bstrULongNumber) (ULONG) MyBSTR2L(bstrULongNumber)
  111. // ----------------------------------------------------------------------
  112. //
  113. // Convert a a long number into bstr
  114. //
  115. // ----------------------------------------------------------------------
  116. BSTR MyL2BSTR(LONG lNumber);
  117. BSTR MyUL2BSTR(ULONG ulNumber);
  118. // ----------------------------------------------------------------------
  119. //
  120. // Compare a binary buffer with a string, where data in the string
  121. // has format:
  122. //
  123. // <String> ::= <Number> [<Space><String>]
  124. // <Space> ::= TCHAR(' ')
  125. // <Number> ::= 0x<HexValue>|x<HexValue><Decimal>
  126. // <Decimal> ::= +<DecimalValue>|-<DecimalValue>
  127. // <DecimalValue> ::= <DecimalDigit>|<DecimalDigit><DecimalValue>
  128. // <DecimalDegit> ::= 0|1|2|3|4|5|6|7|8|9
  129. // <HexValue> ::= <HexDigit>|<HexDigit><HexDigit>
  130. // <HexDigit> ::= <DecimalDigit>|A|B|C|D|E|F
  131. //
  132. // example of strings that this function recognize:
  133. // "12 0 45 0x1F"
  134. //
  135. // Return: similar to lstrcmp() API, each byte is compared
  136. // as unsigned short
  137. // if binary > string, +1
  138. // if binary = string, 0
  139. // if binary < string, -1
  140. //
  141. // Note: if a number in string is bigger than a byte can handle,
  142. // or not a valid number this funciton treats it as 0x0 when comparing.
  143. //
  144. // ----------------------------------------------------------------------
  145. int CmpBinaryToString(
  146. LPBYTE pBinaryBuffer, // buffer to contain binary data
  147. UINT nBinarySize, // number of bytes this binary has data
  148. LPCTSTR pstrValue // string contains data to compare
  149. );
  150. /*
  151. * FUNCTION: int atoh(char *ptr)
  152. *
  153. * PURPOSE: This function converts an hexadecimal string into it's decimal value.
  154. *
  155. * PARAMETERS:
  156. *
  157. * char *ptr: pointer to string to be converted
  158. *
  159. * RETURNS: The converted value.
  160. *
  161. * COMMENTS: Like atoi this function ends the conversion on the first innvalid
  162. * hex digit.
  163. *
  164. */
  165. int atoh(LPCSTR ptr);
  166. #define __STRINGUTIL_H_INCLUDED__
  167. #endif // __STRINGUTIL_H_INCLUDED__