Leaked source code of windows server 2003
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.

285 lines
9.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // str.h - interface for string functions in str.c
  24. ////
  25. #ifndef __STR_H__
  26. #define __STR_H__
  27. #include "winlocal.h"
  28. #define STR_VERSION 0x00000100
  29. #include <tchar.h>
  30. #include <string.h>
  31. #include <ctype.h>
  32. ////
  33. // string macros
  34. ////
  35. #ifndef _WIN32
  36. #define CharPrev AnsiPrev
  37. #define CharNext AnsiNext
  38. #define CharLowerBuff AnsiLowerBuff
  39. #define CharUpperBuff AnsiUpperBuff
  40. #define CharLower AnsiLower
  41. #define CharUpper AnsiUpper
  42. #endif
  43. #ifndef NOLSTRING
  44. #define StrCat(string1, string2) lstrcat(string1, string2)
  45. #define StrCmp(string1, string2) lstrcmp(string1, string2)
  46. #define StrICmp(string1, string2) lstrcmpi(string1, string2)
  47. #define StrCpy(string1, string2) lstrcpy(string1, string2)
  48. #define StrLen(string) (UINT) lstrlen(string)
  49. #if (WINVER >= 0x030a)
  50. #define StrNCpy(string1, string2, count) lstrcpyn(string1, string2, (int) count)
  51. #else
  52. #define StrNCpy(string1, string2, count) _tcsncpy(_fmemset(string1, 0, count), string2, count - 1)
  53. #endif
  54. #define StrLwr(string) (CharLowerBuff(string, (UINT) lstrlen(string)), string)
  55. #define StrUpr(string) (CharUpperBuff(string, (UINT) lstrlen(string)), string)
  56. #define StrNextChr(string) CharNext(string)
  57. #define StrPrevChr(start, string) CharPrev(start, string)
  58. #else
  59. #define StrCat(string1, string2) _tcscat(string1, string2)
  60. #define StrCmp(string1, string2) _tcscmp(string1, string2)
  61. #define StrICmp(string1, string2) _tcsicmp(string1, string2)
  62. #define StrCpy(string1, string2) _tcscpy(string1, string2)
  63. #define StrLen(string) _tcslen(string)
  64. #define StrNCpy(string1, string2, count) _tcsncpy(_fmemset(string1, 0, count), string2, count - 1)
  65. #define StrLwr(string) _tcslwr(string)
  66. #define StrUpr(string) _tcsupr(string)
  67. #define StrNextChr(string) (*(string) == '\0' ? (string) : ((string) + 1))
  68. #define StrNextChr(string) _tcsinc(string)
  69. // #define StrNextChr(string) (*(string) == '\0' ? (string) : ((string) + 1))
  70. #define StrPrevChr(start, string) _tcsdec(start, string)
  71. // #define StrPrevChr(start, string) ((string > start) ? ((string) - 1) : (start))
  72. #endif
  73. #define StrChr(string, c) _tcschr(string, c)
  74. #define StrCSpn(string1, string2) _tcscspn(string1, string2)
  75. #define StrNCat(string1, string2, count) _tcsncat(string1, string2, count)
  76. #define StrNCmp(string1, string2, count) _tcsncmp(string1, string2, count)
  77. #define StrNICmp(string1, string2, count) _tcsnicmp(string1, string2, count)
  78. #define StrNSet(string, c, count) _tcsnset(string, c, count)
  79. #define StrPBrk(string1, string2) _tcspbrk(string1, string2)
  80. #define StrRChr(string, c) _tcsrchr(string, c)
  81. #define StrRev(string, c) _tcsrev(string, c)
  82. #define StrSet(string, c) _tcsset(string, c)
  83. #define StrSpn(string1, string2) _tcsspn(string1, string2)
  84. #define StrStr(string1, string2) _tcsstr(string1, string2)
  85. #define StrTok(string1, string2) _tcstok(string1, string2)
  86. ////
  87. // character type macros
  88. ////
  89. #ifndef NOLANGUAGE
  90. #define ChrIsAlpha(c) IsCharAlpha(c)
  91. #define ChrIsAlnum(c) IsCharAlphaNumeric(c)
  92. #define ChrIsUpper(c) IsCharUpper(c)
  93. #define ChrIsLower(c) IsCharLower(c)
  94. #define ChrToUpper(c) (TCHAR) CharUpper((LPTSTR) (DWORD_PTR)(c))
  95. #define ChrToLower(c) (TCHAR) CharLower((LPTSTR) (DWORD_PTR)(c))
  96. #else
  97. #define ChrIsAlpha(c) _istalpha(c)
  98. #define ChrIsAlnum(c) _istalnum(c)
  99. #define ChrIsUpper(c) _istupper(c)
  100. #define ChrIsLower(c) _istlower(c)
  101. #define ChrToUpper(c) _totupper(c)
  102. #define ChrToLower(c) _totlower(c)
  103. #endif
  104. #define ChrIsDigit(c) _istdigit(c)
  105. #define ChrIsHexDigit(c) _istxdigit(c)
  106. #define ChrIsSpace(c) _istspace(c)
  107. #define ChrIsPunct(c) _istpunct(c)
  108. #define ChrIsPrint(c) _istprint(c)
  109. #define ChrIsGraph(c) _istgraph(c)
  110. #define ChrIsCntrl(c) _istcntrl(c)
  111. #define ChrIsAscii(c) _istascii(c)
  112. #define ChrIsWordDelimiter(c) (ChrIsSpace(c) || ChrIsPunct(c))
  113. ////
  114. // string functions
  115. ////
  116. #ifdef __cplusplus
  117. extern "C" {
  118. #endif
  119. // StrItoA - convert int nValue to ascii digits, the result stored in lpszDest
  120. // <nValue> (i) integer to convert
  121. // <lpszDest> (o) buffer to copy result (max 17 bytes)
  122. // <nRadix> (i) conversion radix (base-2 through base-36)
  123. // return <lpszDest>
  124. //
  125. #ifdef NOTRACE
  126. #define StrItoA(nValue, lpszDest, nRadix) _itot(nValue, lpszDest, nRadix)
  127. #else
  128. LPTSTR DLLEXPORT WINAPI StrItoA(int nValue, LPTSTR lpszDest, int nRadix);
  129. #endif
  130. // StrLtoA - convert long nValue to ascii digits, the result stored in lpszDest
  131. // <nValue> (i) integer to convert
  132. // <lpszDest> (o) buffer to copy result (max 33 bytes)
  133. // <nRadix> (i) conversion radix (base-2 through base-36)
  134. // return lpszDest
  135. //
  136. #ifdef NOTRACE
  137. #define StrLtoA(nValue, szDest, nRadix) _ltot(nValue, szDest, nRadix)
  138. #else
  139. LPTSTR DLLEXPORT WINAPI StrLtoA(long nValue, LPTSTR lpszDest, int nRadix);
  140. #endif
  141. // StrAtoI - convert ascii digits to int
  142. // <lpszSrc> (i) string of digits to convert
  143. // return int
  144. //
  145. #ifdef NOTRACE
  146. #define StrAtoI(lpszSrc) _ttoi(lpszSrc)
  147. #else
  148. int DLLEXPORT WINAPI StrAtoI(LPCTSTR lpszSrc);
  149. #endif
  150. // StrAtoL - convert ascii digits to long
  151. // <lpszSrc> (i) string of digits to convert
  152. // return long
  153. //
  154. #ifdef NOTRACE
  155. #define StrAtoL(lpszSrc) _ttol(lpszSrc)
  156. #else
  157. long DLLEXPORT WINAPI StrAtoL(LPCTSTR lpszSrc);
  158. #endif
  159. // StrDup - create duplicate copy of specified string
  160. // <lpsz> (i) string to duplicate
  161. // return pointer to duplicate string (NULL if error)
  162. // NOTE: call StrDupFree to release allocated memory
  163. //
  164. #ifdef NOTRACE
  165. #define StrDup(string) _tcsdup(string)
  166. #else
  167. LPTSTR DLLEXPORT WINAPI StrDup(LPCTSTR lpsz);
  168. #endif
  169. // StrDupFree - free memory associated with duplicate string
  170. // <lpsz> (i) string returned by StrDup
  171. // return 0 if success
  172. //
  173. #ifdef NOTRACE
  174. #define StrDupFree(string) (free(string), 0)
  175. #else
  176. int DLLEXPORT WINAPI StrDupFree(LPTSTR lpsz);
  177. #endif
  178. // StrClean - copy up to n chars from string szSrc to string szDst,
  179. // except for leading and trailing white space
  180. // return szDst
  181. //
  182. LPTSTR DLLEXPORT WINAPI StrClean(LPTSTR szDst, LPCTSTR szSrc, size_t n);
  183. // StrGetLastChr - return last char in string s
  184. //
  185. TCHAR DLLEXPORT WINAPI StrGetLastChr(LPCTSTR s);
  186. // StrSetLastChr - replace last char in string s with c
  187. // return s
  188. //
  189. LPTSTR DLLEXPORT WINAPI StrSetLastChr(LPTSTR s, TCHAR c);
  190. // StrTrimChr - strip trailing c chars from string s
  191. // return s
  192. //
  193. LPTSTR DLLEXPORT WINAPI StrTrimChr(LPTSTR s, TCHAR c);
  194. // StrTrimChrLeading - strip leading c chars from string s
  195. // return s
  196. //
  197. LPTSTR DLLEXPORT WINAPI StrTrimChrLeading(LPTSTR s, TCHAR c);
  198. // StrTrimWhite - strip trailing white space from string s
  199. // return s
  200. //
  201. LPTSTR DLLEXPORT WINAPI StrTrimWhite(LPTSTR s);
  202. // StrTrimWhiteLeading - strip leading white space from string s
  203. // return s
  204. //
  205. LPTSTR DLLEXPORT WINAPI StrTrimWhiteLeading(LPTSTR s);
  206. // StrTrimQuotes - strip leading and trailing quotes from string s
  207. // return s
  208. //
  209. LPTSTR DLLEXPORT WINAPI StrTrimQuotes(LPTSTR s);
  210. // StrChrCat - concatenate char c to end of string s
  211. // return s
  212. //
  213. LPTSTR DLLEXPORT WINAPI StrChrCat(LPTSTR s, TCHAR c);
  214. // StrChrCatLeft - concatenate char c to front of string s
  215. // return s
  216. //
  217. LPTSTR DLLEXPORT WINAPI StrChrCatLeft(LPTSTR s, TCHAR c);
  218. // StrInsert - insert string szSrc in front of szDst
  219. // return szDst
  220. //
  221. LPTSTR DLLEXPORT WINAPI StrInsert(LPTSTR szDst, LPTSTR szSrc);
  222. // StrSetN - set first n chars of string s to char c, null terminate s
  223. // return s
  224. //
  225. LPTSTR DLLEXPORT WINAPI StrSetN(LPTSTR s, TCHAR c, size_t n);
  226. // StrCpyXChr - copy string szSrc to string szDst, except for c chars
  227. // return szDst
  228. //
  229. LPTSTR DLLEXPORT WINAPI StrCpyXChr(LPTSTR szDst, LPCTSTR szSrc, TCHAR c);
  230. // StrGetRowColumnCount - calculate number of lines and longest line in string
  231. // <lpszText> (i) string to examine
  232. // <lpnRows> (o) int pointer to receive line count
  233. // <lpnColumnsMax> (o) int pointer to receive size of longest line
  234. // return 0 if success
  235. //
  236. int DLLEXPORT WINAPI StrGetRowColumnCount(LPCTSTR lpszText, LPINT lpnRows, LPINT lpnColumnsMax);
  237. // StrGetRow - extract specified line from string
  238. // <lpszText> (i) string from which to extract line
  239. // <iRow> (i) index of line to extract (0 = first row, ...)
  240. // <lpszBuf> (o) buffer to copy line into
  241. // <sizBuf> (i) size of buffer
  242. // return 0 if success
  243. //
  244. int DLLEXPORT WINAPI StrGetRow(LPCTSTR lpszText, int iRow, LPTSTR lpszBuf, int sizBuf);
  245. #ifdef __cplusplus
  246. }
  247. #endif
  248. #endif // __STR_H__