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.

1397 lines
35 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. strings.h
  5. Abstract:
  6. Declares the string utilities implemented in common\migutil.
  7. Author:
  8. Several
  9. Revision History:
  10. See SLM log
  11. --*/
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <tchar.h>
  16. #include <mbstring.h>
  17. #include <wchar.h>
  18. #pragma once
  19. //
  20. // Worker routines for faster SzMatch* functions
  21. //
  22. BOOL
  23. SzMemMatchA (
  24. IN PCSTR Buffer1,
  25. IN PCSTR Buffer2,
  26. IN SIZE_T ByteCount
  27. );
  28. BOOL
  29. SzMemMatchW (
  30. IN PCWSTR Buffer1,
  31. IN PCWSTR Buffer2,
  32. IN SIZE_T ByteCount
  33. );
  34. // SzNextCharA is _mbsinc with a check for a broken mbcs char
  35. PSTR
  36. SzNextCharA (
  37. IN PCSTR CurrentPointer
  38. );
  39. // Bug fix for C Runtime _tcsdec
  40. __inline
  41. PWSTR
  42. SzPrevCharW (
  43. IN PCWSTR Base,
  44. IN PCWSTR Pointer
  45. )
  46. {
  47. if (Base >= Pointer) {
  48. return NULL;
  49. }
  50. return (PWSTR) (Pointer - 1);
  51. }
  52. // Bug fix for C Runtime _tcsdec
  53. __inline
  54. PSTR
  55. SzPrevCharA (
  56. PCSTR Base,
  57. PCSTR Pointer
  58. )
  59. {
  60. if (Base >= Pointer) {
  61. return NULL;
  62. }
  63. return (PSTR) _mbsdec ((const unsigned char *) Base, (const unsigned char *) Pointer);
  64. }
  65. //
  66. // String sizing routines and unit conversion
  67. //
  68. #define SzLcharCountA(x) ((UINT)_mbslen(x))
  69. #define SzLcharCountW(x) ((UINT)wcslen(x))
  70. __inline
  71. PSTR
  72. SzLcharsToPointerA (
  73. PCSTR String,
  74. UINT Char
  75. )
  76. {
  77. while (Char > 0) {
  78. MYASSERT (*String != 0);
  79. Char--;
  80. String = SzNextCharA (String);
  81. }
  82. return (PSTR) String;
  83. }
  84. __inline
  85. PWSTR
  86. SzLcharsToPointerW (
  87. PCWSTR String,
  88. UINT Char
  89. )
  90. {
  91. #ifdef DEBUG
  92. UINT u;
  93. for (u = 0 ; u < Char ; u++) {
  94. MYASSERT (String[u] != 0);
  95. }
  96. #endif
  97. return (PWSTR) (&String[Char]);
  98. }
  99. __inline
  100. UINT
  101. SzLcharCountABA (
  102. IN PCSTR Start,
  103. IN PCSTR EndPlusOne
  104. )
  105. {
  106. register UINT count;
  107. count = 0;
  108. while (Start < EndPlusOne) {
  109. MYASSERT (*Start != 0);
  110. count++;
  111. Start = SzNextCharA (Start);
  112. }
  113. return count;
  114. }
  115. __inline
  116. UINT
  117. SzLcharCountABW (
  118. IN PCWSTR Start,
  119. IN PCWSTR EndPlusOne
  120. )
  121. {
  122. #ifdef DEBUG
  123. PCWSTR p;
  124. for (p = Start ; p < EndPlusOne ; p++) {
  125. MYASSERT (*p != 0);
  126. }
  127. #endif
  128. return EndPlusOne > Start ? (UINT)(EndPlusOne - Start) : 0;
  129. }
  130. __inline
  131. UINT
  132. SzLcharsInByteRangeA (
  133. IN PCSTR Start,
  134. IN UINT Bytes
  135. )
  136. {
  137. register UINT count;
  138. PCSTR endPlusOne = (PCSTR) ((PBYTE) Start + Bytes);
  139. count = 0;
  140. while (Start < endPlusOne) {
  141. count++;
  142. Start = SzNextCharA (Start);
  143. }
  144. return count;
  145. }
  146. __inline
  147. UINT
  148. SzLcharsInByteRangeW (
  149. IN PCWSTR Start,
  150. IN UINT Bytes
  151. )
  152. {
  153. PCWSTR endPlusOne = (PCWSTR) ((PBYTE) Start + Bytes);
  154. if (Start < endPlusOne) {
  155. //cast is OK, we don't expect pointers to be that far
  156. return (UINT)(endPlusOne - Start);
  157. }
  158. MYASSERT (FALSE);
  159. return 0;
  160. }
  161. __inline
  162. UINT
  163. SzLcharsToBytesA (
  164. IN PCSTR Start,
  165. IN UINT LogChars
  166. )
  167. {
  168. PCSTR endPlusOne;
  169. endPlusOne = SzLcharsToPointerA (Start, LogChars);
  170. //cast is OK, we don't expect pointers to be that far
  171. return (UINT)(endPlusOne - Start);
  172. }
  173. __inline
  174. UINT
  175. SzLcharsToBytesW (
  176. IN PCWSTR Start,
  177. IN UINT LogChars
  178. )
  179. {
  180. return LogChars * SIZEOF (WCHAR);
  181. }
  182. #define SzLcharsToTcharsA SzLcharsToBytesA
  183. __inline
  184. UINT
  185. SzLcharsToTcharsW (
  186. IN PCWSTR Start,
  187. IN UINT LogChars
  188. )
  189. {
  190. return LogChars;
  191. }
  192. #define SzByteCountA(x) ((UINT) strlen (x))
  193. #define SzByteCountW(x) ((UINT) wcslen (x) * SIZEOF(WCHAR))
  194. #define SzSizeA(str) ((UINT) SzByteCountA (str) + SIZEOF (CHAR))
  195. #define SzSizeW(str) ((UINT) SzByteCountW (str) + SIZEOF (WCHAR))
  196. __inline
  197. PSTR
  198. SzBytesToPointerA (
  199. PCSTR String,
  200. UINT BytePos
  201. )
  202. {
  203. return (PSTR)((ULONG_PTR) String + BytePos);
  204. }
  205. __inline
  206. PWSTR
  207. SzBytesToPointerW (
  208. PCWSTR String,
  209. UINT BytePos
  210. )
  211. {
  212. return (PWSTR)((ULONG_PTR) String + (BytePos & (~1)));
  213. }
  214. __inline
  215. UINT
  216. SzByteCountABA (
  217. IN PCSTR Start,
  218. IN PCSTR EndPlusOne
  219. )
  220. {
  221. #ifdef DEBUG
  222. PCSTR p;
  223. for (p = Start ; p < EndPlusOne ; p = SzNextCharA (p)) {
  224. MYASSERT (*p != 0);
  225. }
  226. #endif
  227. return EndPlusOne > Start ? (UINT)(EndPlusOne - Start) : 0;
  228. }
  229. __inline
  230. UINT
  231. SzByteCountABW (
  232. IN PCWSTR Start,
  233. IN PCWSTR EndPlusOne
  234. )
  235. {
  236. #ifdef DEBUG
  237. PCWSTR p;
  238. for (p = Start ; p < EndPlusOne ; p++) {
  239. MYASSERT (*p != 0);
  240. }
  241. #endif
  242. return EndPlusOne > Start ? (UINT)(EndPlusOne - Start) * SIZEOF (WCHAR) : 0;
  243. }
  244. __inline
  245. UINT
  246. SzBytesToLcharsA (
  247. IN PCSTR Start,
  248. IN UINT ByteCount
  249. )
  250. {
  251. PCSTR endPlusOne;
  252. endPlusOne = Start + ByteCount;
  253. return SzLcharCountABA (Start, endPlusOne);
  254. }
  255. __inline
  256. UINT
  257. SzBytesToLcharsW (
  258. IN PCWSTR Start,
  259. IN UINT ByteCount
  260. )
  261. {
  262. #ifdef DEBUG
  263. PCWSTR p;
  264. PCWSTR endPlusOne;
  265. endPlusOne = (PCWSTR) ((ULONG_PTR) Start + ByteCount);
  266. for (p = Start ; p < endPlusOne ; p++) {
  267. MYASSERT (*p != 0);
  268. }
  269. #endif
  270. return ByteCount / SIZEOF (WCHAR);
  271. }
  272. __inline
  273. UINT
  274. SzBytesToTcharsA (
  275. IN PCSTR Start,
  276. IN UINT ByteCount
  277. )
  278. {
  279. #ifdef DEBUG
  280. PCSTR p;
  281. PCSTR endPlusOne;
  282. endPlusOne = Start + ByteCount;
  283. for (p = Start ; p < endPlusOne ; p = SzNextCharA (p)) {
  284. MYASSERT (*p != 0);
  285. }
  286. #endif
  287. return ByteCount;
  288. }
  289. #define SzBytesToTcharsW SzBytesToLcharsW
  290. #define SzTcharCountA strlen
  291. #define SzTcharCountW wcslen
  292. __inline
  293. PSTR
  294. SzTcharsToPointerA (
  295. PCSTR String,
  296. UINT Tchars
  297. )
  298. {
  299. #ifdef DEBUG
  300. PCSTR p;
  301. PCSTR endPlusOne;
  302. endPlusOne = String + Tchars;
  303. for (p = String ; p < endPlusOne ; p = SzNextCharA (p)) {
  304. MYASSERT (*p != 0);
  305. }
  306. #endif
  307. return (PSTR) (String + Tchars);
  308. }
  309. __inline
  310. PWSTR
  311. SzTcharsToPointerW (
  312. PCWSTR String,
  313. UINT Tchars
  314. )
  315. {
  316. #ifdef DEBUG
  317. PCWSTR p;
  318. PCWSTR endPlusOne;
  319. endPlusOne = String + Tchars;
  320. for (p = String ; p < endPlusOne ; p++) {
  321. MYASSERT (*p != 0);
  322. }
  323. #endif
  324. return (PWSTR) (String + Tchars);
  325. }
  326. #define SzTcharCountABA SzByteCountABA
  327. __inline
  328. UINT
  329. SzTcharCountABW (
  330. IN PCWSTR Start,
  331. IN PCWSTR EndPlusOne
  332. )
  333. {
  334. #ifdef DEBUG
  335. PCWSTR p;
  336. for (p = Start ; p < EndPlusOne ; p++) {
  337. MYASSERT (*p != 0);
  338. }
  339. #endif
  340. return EndPlusOne > Start ? (UINT)(EndPlusOne - Start) : 0;
  341. }
  342. #define SzTcharsToLcharsA SzBytesToLcharsA
  343. __inline
  344. UINT
  345. SzTcharsToLcharsW (
  346. IN PCWSTR Start,
  347. IN UINT Tchars
  348. )
  349. {
  350. #ifdef DEBUG
  351. PCWSTR p;
  352. PCWSTR endPlusOne;
  353. endPlusOne = Start + Tchars;
  354. for (p = Start ; p < endPlusOne ; p++) {
  355. MYASSERT (*p != 0);
  356. }
  357. #endif
  358. return Tchars;
  359. }
  360. __inline
  361. UINT
  362. SzTcharsToBytesA (
  363. IN PCSTR Start,
  364. IN UINT Tchars
  365. )
  366. {
  367. #ifdef DEBUG
  368. PCSTR p;
  369. PCSTR endPlusOne;
  370. endPlusOne = Start + Tchars;
  371. for (p = Start ; p < endPlusOne ; p = SzNextCharA (p)) {
  372. MYASSERT (*p != 0);
  373. }
  374. #endif
  375. return Tchars;
  376. }
  377. __inline
  378. UINT
  379. SzTcharsToBytesW (
  380. IN PCWSTR Start,
  381. IN UINT Tchars
  382. )
  383. {
  384. #ifdef DEBUG
  385. PCWSTR p;
  386. PCWSTR endPlusOne;
  387. endPlusOne = Start + Tchars;
  388. for (p = Start ; p < endPlusOne ; p++) {
  389. MYASSERT (*p != 0);
  390. }
  391. #endif
  392. return Tchars * SIZEOF (WCHAR);
  393. }
  394. #define SzBufferCopyA(stackbuf,src) SzCopyBytesA(stackbuf,src,SIZEOF(stackbuf))
  395. #define SzBufferCopyW(stackbuf,src) SzCopyBytesW(stackbuf,src,SIZEOF(stackbuf))
  396. //
  397. // String comparison routines
  398. //
  399. #define SzCompareA _mbscmp
  400. #define SzCompareW wcscmp
  401. BOOL
  402. SzMatchA (
  403. IN PCSTR String1,
  404. IN PCSTR String2
  405. );
  406. #define SzMatchW(str1,str2) (wcscmp(str1,str2)==0)
  407. #define SzICompareA _mbsicmp
  408. #define SzICompareW _wcsicmp
  409. #define SzIMatchA(str1,str2) (_mbsicmp(str1,str2)==0)
  410. #define SzIMatchW(str1,str2) (_wcsicmp(str1,str2)==0)
  411. INT
  412. SzCompareBytesA (
  413. IN PCSTR String1,
  414. IN PCSTR String2,
  415. IN SIZE_T ByteCount
  416. );
  417. #define SzCompareBytesW(str1,str2,bytes) wcsncmp(str1,str2,(bytes)/sizeof(WCHAR))
  418. #define SzMatchBytesA(str1,str2,bytes) (SzMemMatchA (str1, str2, bytes))
  419. #define SzMatchBytesW(str1,str2,bytes) (SzMemMatchW (str1, str2, bytes))
  420. INT
  421. SzICompareBytesA (
  422. IN PCSTR String1,
  423. IN PCSTR String2,
  424. IN SIZE_T ByteCount
  425. );
  426. #define SzICompareBytesW(str1,str2,bytes) _wcsnicmp (str1, str2, (bytes) / sizeof(WCHAR))
  427. #define SzIMatchBytesA(str1,str2,bytes) (SzICompareBytesA (str1, str2, bytes) == 0)
  428. #define SzIMatchBytesW(str1,str2,bytes) (_wcsnicmp (str1, str2, (bytes) / sizeof(WCHAR)) == 0)
  429. #define SzCompareLcharsA(str1,str2,chars) _mbsncmp (str1, str2, chars)
  430. #define SzCompareLcharsW(str1,str2,chars) wcsncmp (str1, str2, chars)
  431. #define SzMatchLcharsA(str1,str2,chars) (_mbsncmp (str1,str2,chars) == 0)
  432. #define SzMatchLcharsW(str1,str2,chars) SzMemMatchW (str1, str2, (chars) * sizeof (WCHAR))
  433. #define SzICompareLcharsA(str1,str2,chars) _mbsnicmp (str1, str2, chars)
  434. #define SzICompareLcharsW(str1,str2,chars) _wcsnicmp (str1, str2, chars)
  435. #define SzIMatchLcharsA(str1,str2,chars) (_mbsnicmp (str1, str2, chars)==0)
  436. #define SzIMatchLcharsW(str1,str2,chars) (_wcsnicmp (str1, str2, chars)==0)
  437. #define SzCompareTcharsA(str1,str2,tchars) SzCompareBytesA (str1, str2, (tchars) / sizeof(CHAR))
  438. #define SzCompareTcharsW(str1,str2,tchars) wcsncmp (str1, str2, tchars)
  439. #define SzMatchTcharsA(str1,str2,tchars) SzMemMatchA (str1, str2, (tchars) * sizeof (CHAR))
  440. #define SzMatchTcharsW(str1,str2,tchars) SzMemMatchW (str1, str2, (tchars) * sizeof (WCHAR))
  441. #define SzICompareTcharsA(str1,str2,tchars) SzICompareBytesA (str1, str2, tchars)
  442. #define SzICompareTcharsW(str1,str2,tchars) _wcsnicmp (str1, str2, tchars)
  443. #define SzIMatchTcharsA(str1,str2,tchars) SzIMatchBytesA (str1, str2, tchars)
  444. #define SzIMatchTcharsW(str1,str2,tchars) (_wcsnicmp (str1, str2, tchars)==0)
  445. #define SzPrefixA(string,prefix) SzMatchTcharsA (string, prefix, SzTcharCountA (prefix))
  446. #define SzPrefixW(string,prefix) SzMatchTcharsW (string, prefix, SzTcharCountW (prefix))
  447. #define SzIPrefixA(string,prefix) SzIMatchTcharsA (string, prefix, SzTcharCountA (prefix))
  448. #define SzIPrefixW(string,prefix) SzIMatchTcharsW (string, prefix, SzTcharCountW (prefix))
  449. #define SzCompareABA(string1,start2,end2) SzCompareTcharsA (string1, start2, (end2) - (start2))
  450. #define SzCompareABW(string1,start2,end2) SzCompareTcharsW (string1, start2, (end2) - (start2))
  451. #define SzMatchABA(string1,start2,end2) SzMemMatchA (string1, start2, (end2) - (start2))
  452. #define SzMatchABW(string1,start2,end2) SzMemMatchW (string1, start2, (end2) - (start2))
  453. #define SzICompareABA(string1,start2,end2) SzICompareTcharsA (string1, start2, (end2) - (start2))
  454. #define SzICompareABW(string1,start2,end2) SzICompareTcharsW (string1, start2, (end2) - (start2))
  455. #define SzIMatchABA(string1,start2,end2) SzIMatchTcharsA (string1, start2, (end2) - (start2))
  456. #define SzIMatchABW(string1,start2,end2) SzIMatchTcharsW (string1, start2, (end2) - (start2))
  457. //
  458. // String copy routines -- they return the END of the string
  459. //
  460. PSTR
  461. SzCopyA (
  462. OUT PSTR Destination,
  463. IN PCSTR Source
  464. );
  465. PWSTR
  466. SzCopyW (
  467. OUT PWSTR Destination,
  468. IN PCWSTR Source
  469. );
  470. PSTR
  471. SzCopyBytesA (
  472. OUT PSTR Destination,
  473. IN PCSTR Source,
  474. IN UINT MaxBytesToCopyIncNul
  475. );
  476. PWSTR
  477. SzCopyBytesW (
  478. OUT PWSTR Destination,
  479. IN PCWSTR Source,
  480. IN UINT MaxBytesToCopyIncNul
  481. );
  482. PSTR
  483. SzCopyBytesABA (
  484. OUT PSTR Destination,
  485. IN PCSTR Start,
  486. IN PCSTR End,
  487. IN UINT MaxBytesToCopyIncNul
  488. );
  489. PWSTR
  490. SzCopyBytesABW (
  491. OUT PWSTR Destination,
  492. IN PCWSTR Start,
  493. IN PCWSTR End,
  494. IN UINT MaxBytesToCopyIncNul
  495. );
  496. #define SzCopyLcharsA(str1,str2,chars) SzCopyBytesA(str1,str2,SzLcharsToBytesA(str2,chars))
  497. #define SzCopyLcharsW(str1,str2,chars) SzCopyBytesW(str1,str2,SzLcharsToBytesW(str2,chars))
  498. #define SzCopyTcharsA(str1,str2,tchars) SzCopyBytesA(str1,str2,tchars * sizeof (CHAR))
  499. #define SzCopyTcharsW(str1,str2,tchars) SzCopyBytesW(str1,str2,tchars * sizeof (WCHAR))
  500. #define SzCopyABA(dest,stra,strb) SzCopyBytesA((dest),(stra),((UINT)((ULONG_PTR)(strb)-(ULONG_PTR)(stra))+(UINT)SIZEOF(CHAR)))
  501. #define SzCopyABW(dest,stra,strb) SzCopyBytesW((dest),(stra),((UINT)((ULONG_PTR)(strb)-(ULONG_PTR)(stra))+(UINT)SIZEOF(WCHAR)))
  502. //
  503. // String cat routines -- they return the END of the string
  504. //
  505. PSTR
  506. SzCatA (
  507. OUT PSTR Destination,
  508. IN PCSTR Source
  509. );
  510. PWSTR
  511. SzCatW (
  512. OUT PWSTR Destination,
  513. IN PCWSTR Source
  514. );
  515. //
  516. // Character search routines
  517. //
  518. // note the use of strchr, not _mbschr, is critical
  519. #define SzGetEndA(s) strchr(s,0)
  520. #define SzGetEndW(s) wcschr(s,0)
  521. __inline
  522. UINT
  523. MszSizeA (
  524. PCSTR MultiSz
  525. )
  526. {
  527. PCSTR Base;
  528. Base = MultiSz;
  529. while (*MultiSz) {
  530. MultiSz = SzGetEndA (MultiSz) + 1;
  531. }
  532. MultiSz++;
  533. return (UINT)((ULONG_PTR) MultiSz - (ULONG_PTR) Base);
  534. }
  535. __inline
  536. UINT
  537. MszSizeW (
  538. PCWSTR MultiSz
  539. )
  540. {
  541. PCWSTR base;
  542. base = MultiSz;
  543. while (*MultiSz) {
  544. MultiSz = SzGetEndW (MultiSz) + 1;
  545. }
  546. MultiSz++;
  547. return (UINT)((ULONG_PTR) MultiSz - (ULONG_PTR) base);
  548. }
  549. __inline
  550. UINT
  551. MszTcharCountA (
  552. PCSTR MultiSz
  553. )
  554. {
  555. PCSTR end = MultiSz;
  556. while (*end) {
  557. do {
  558. end = SzNextCharA (end);
  559. } while (*end);
  560. end++;
  561. }
  562. end++;
  563. return (UINT) (end - MultiSz);
  564. }
  565. __inline
  566. UINT
  567. MszTcharCountW (
  568. PCWSTR MultiSz
  569. )
  570. {
  571. PCWSTR end = MultiSz;
  572. while (*end) {
  573. do {
  574. end++;
  575. } while (*end);
  576. end++;
  577. }
  578. end++;
  579. return (UINT) (end - MultiSz);
  580. }
  581. PSTR
  582. SzFindPrevCharA (
  583. IN PCSTR StartStr,
  584. IN PCSTR CurrPtr,
  585. IN MBCHAR SearchChar
  586. );
  587. PWSTR
  588. SzFindPrevCharW (
  589. IN PCWSTR StartStr,
  590. IN PCWSTR CurrPtr,
  591. IN WCHAR SearchChar
  592. );
  593. // pointer to string conversion, returns eos
  594. PSTR
  595. SzUnsignedToHexA (
  596. IN ULONG_PTR Number,
  597. OUT PSTR String
  598. );
  599. PWSTR
  600. SzUnsignedToHexW (
  601. IN ULONG_PTR Number,
  602. OUT PWSTR String
  603. );
  604. PSTR
  605. SzUnsignedToDecA (
  606. IN ULONG_PTR Number,
  607. OUT PSTR String
  608. );
  609. PWSTR
  610. SzUnsignedToDecW (
  611. IN ULONG_PTR Number,
  612. OUT PWSTR String
  613. );
  614. PSTR
  615. SzSignedToDecA (
  616. IN LONG_PTR Number,
  617. OUT PSTR String
  618. );
  619. PWSTR
  620. SzSignedToDecW (
  621. IN LONG_PTR Number,
  622. OUT PWSTR String
  623. );
  624. //
  625. // All conversion routines that return values support both decimal and hex
  626. // (even the signed routines).
  627. //
  628. ULONG
  629. SzToNumberA (
  630. IN PCSTR String,
  631. OUT PCSTR *EndOfNumber OPTIONAL
  632. );
  633. ULONG
  634. SzToNumberW (
  635. IN PCWSTR String,
  636. OUT PCWSTR *EndOfNumber OPTIONAL
  637. );
  638. ULONGLONG
  639. SzToULongLongA (
  640. IN PCSTR String,
  641. OUT PCSTR *EndOfNumber OPTIONAL
  642. );
  643. ULONGLONG
  644. SzToULongLongW (
  645. IN PCWSTR String,
  646. OUT PCWSTR *EndOfNumber OPTIONAL
  647. );
  648. LONGLONG
  649. SzToLongLongA (
  650. IN PCSTR String,
  651. OUT PCSTR *EndOfNumber OPTIONAL
  652. );
  653. LONGLONG
  654. SzToLongLongW (
  655. IN PCWSTR String,
  656. OUT PCWSTR *EndOfNumber OPTIONAL
  657. );
  658. // determines if an entire string is printable chars
  659. BOOL
  660. SzIsPrintA (
  661. IN PCSTR String
  662. );
  663. BOOL
  664. SzIsPrintW (
  665. IN PCWSTR String
  666. );
  667. //
  668. // String-in-string search routines
  669. //
  670. // you could use _mbsstr or wcsstr, but for convention sake, these defines are provided
  671. #define SzFindSubStringA(String1, String2) _mbsstr (String1, String2)
  672. #define SzFindSubStringW(String1, String2) wcsstr (String1, String2)
  673. PCSTR
  674. SzIFindSubStringA (
  675. IN PCSTR FullString,
  676. IN PCSTR SubString
  677. );
  678. PCWSTR
  679. SzIFindSubStringW (
  680. IN PCWSTR FullString,
  681. IN PCWSTR SubString
  682. );
  683. //
  684. // Character copy routines
  685. //
  686. PSTR
  687. SzCopyNextCharA (
  688. OUT PSTR Dest,
  689. IN PCSTR Source
  690. );
  691. // Most people use *dest++ = *source++, but for completeness, this fn is provided.
  692. // Maybe you need the separate return value.
  693. __inline
  694. PWSTR
  695. SzCopyNextCharW (
  696. OUT PWSTR Dest,
  697. IN PCWSTR Source
  698. )
  699. {
  700. *Dest++ = *Source;
  701. return Dest;
  702. }
  703. // trims off last character and returns a pointer to the end of string;
  704. // returns NULL pointer if last character was not found
  705. PSTR
  706. SzTrimLastCharA (
  707. IN OUT PSTR String,
  708. IN MBCHAR LogChar
  709. );
  710. PWSTR
  711. SzTrimLastCharW (
  712. IN OUT PWSTR String,
  713. IN WCHAR LogChar
  714. );
  715. // Removes a trailing backslash, if it exists
  716. #define SzRemoveWackAtEndA(str) SzTrimLastCharA(str,'\\')
  717. #define SzRemoveWackAtEndW(str) SzTrimLastCharW(str,L'\\')
  718. // always appends a wack
  719. PSTR
  720. SzAppendWackA (
  721. IN OUT PSTR String
  722. );
  723. PWSTR
  724. SzAppendWackW (
  725. IN OUT PWSTR String
  726. );
  727. PCSTR
  728. SzConcatenatePathsA (
  729. IN OUT PSTR PathBuffer,
  730. IN PCSTR PathSuffix, OPTIONAL
  731. IN UINT BufferTchars
  732. );
  733. PCWSTR
  734. SzConcatenatePathsW (
  735. IN OUT PWSTR PathBuffer,
  736. IN PCWSTR PathSuffix, OPTIONAL
  737. IN UINT BufferTchars
  738. );
  739. //
  740. // File strings
  741. //
  742. // Routine to extract the file from a path, never returns NULL
  743. PCSTR
  744. SzGetFileNameFromPathA (
  745. IN PCSTR Path
  746. );
  747. PCWSTR
  748. SzGetFileNameFromPathW (
  749. IN PCWSTR Path
  750. );
  751. //
  752. // SzGetFileExtensionFromPath extracts the file extension from a path, returns
  753. // NULL if no extension exists
  754. //
  755. PCSTR
  756. SzGetFileExtensionFromPathA (
  757. IN PCSTR Path
  758. );
  759. PCWSTR
  760. SzGetFileExtensionFromPathW (
  761. IN PCWSTR Path
  762. );
  763. //
  764. // Routine to extract the file extension from a path, including the dot, or the
  765. // end of the string if no extension exists
  766. //
  767. PCSTR
  768. SzGetDotExtensionFromPathA (
  769. IN PCSTR Path
  770. );
  771. PCWSTR
  772. SzGetDotExtensionFromPathW (
  773. IN PCWSTR Path
  774. );
  775. __inline
  776. PCSTR
  777. SzFindLastWackA (
  778. IN PCSTR Str
  779. )
  780. {
  781. return (PSTR) _mbsrchr ((const unsigned char *) Str, '\\');
  782. }
  783. __inline
  784. PCWSTR
  785. SzFindLastWackW (
  786. IN PCWSTR Str
  787. )
  788. {
  789. return wcsrchr (Str, L'\\');
  790. }
  791. // Returns a pointer to the next non-space character (uses isspace)
  792. PCSTR
  793. SzSkipSpaceA (
  794. IN PCSTR String
  795. );
  796. PCWSTR
  797. SzSkipSpaceW (
  798. IN PCWSTR String
  799. );
  800. // Returns a pointer to the first space character at the end of a string,
  801. // or a pointer to the terminating nul if no space exists at the end of the
  802. // string. (Used for trimming space.)
  803. PCSTR
  804. SzSkipSpaceRA (
  805. IN PCSTR BaseString,
  806. IN PCSTR String OPTIONAL // can be any char along BaseString
  807. );
  808. PCWSTR
  809. SzSkipSpaceRW (
  810. IN PCWSTR BaseString,
  811. IN PCWSTR String OPTIONAL // can be any char along BaseString
  812. );
  813. // Truncates a string after the last non-whitepace character & returns the end
  814. PSTR
  815. SzTruncateTrailingSpaceA (
  816. IN OUT PSTR String
  817. );
  818. PWSTR
  819. SzTruncateTrailingSpaceW (
  820. IN OUT PWSTR String
  821. );
  822. // Character counters
  823. UINT
  824. SzCountInstancesOfLcharA (
  825. IN PCSTR String,
  826. IN MBCHAR LogChar
  827. );
  828. UINT
  829. SzCountInstancesOfLcharW (
  830. IN PCWSTR String,
  831. IN WCHAR LogChar
  832. );
  833. UINT
  834. SzICountInstancesOfLcharA (
  835. IN PCSTR String,
  836. IN MBCHAR LogChar
  837. );
  838. UINT
  839. SzICountInstancesOfLcharW (
  840. IN PCWSTR String,
  841. IN WCHAR LogChar
  842. );
  843. //
  844. // Sub String Replacement functions.
  845. //
  846. BOOL
  847. SzReplaceA (
  848. IN OUT PSTR Buffer,
  849. IN SIZE_T MaxSize,
  850. IN PSTR ReplaceStartPos,
  851. IN PSTR ReplaceEndPos,
  852. IN PCSTR NewString
  853. );
  854. BOOL
  855. SzReplaceW (
  856. IN OUT PWSTR Buffer,
  857. IN SIZE_T MaxSize,
  858. IN PWSTR ReplaceStartPos,
  859. IN PWSTR ReplaceEndPos,
  860. IN PCWSTR NewString
  861. );
  862. UINT
  863. SzCountInstancesOfSubStringA (
  864. IN PCSTR SourceString,
  865. IN PCSTR SearchString
  866. );
  867. UINT
  868. SzCountInstancesOfSubStringW (
  869. IN PCWSTR SourceString,
  870. IN PCWSTR SearchString
  871. );
  872. UINT
  873. SzICountInstancesOfSubStringA (
  874. IN PCSTR SourceString,
  875. IN PCSTR SearchString
  876. );
  877. UINT
  878. SzICountInstancesOfSubStringW (
  879. IN PCWSTR SourceString,
  880. IN PCWSTR SearchString
  881. );
  882. typedef struct {
  883. PCSTR Buffer;
  884. PCSTR CurrentString;
  885. } MULTISZ_ENUMA, *PMULTISZ_ENUMA;
  886. typedef struct {
  887. PCWSTR Buffer;
  888. PCWSTR CurrentString;
  889. } MULTISZ_ENUMW, *PMULTISZ_ENUMW;
  890. BOOL
  891. MszEnumNextA (
  892. IN OUT PMULTISZ_ENUMA MultiSzEnum
  893. );
  894. BOOL
  895. MszEnumNextW (
  896. IN OUT PMULTISZ_ENUMW MultiSzEnum
  897. );
  898. BOOL
  899. MszEnumFirstA (
  900. OUT PMULTISZ_ENUMA MultiSzEnum,
  901. IN PCSTR MultiSzStr
  902. );
  903. BOOL
  904. MszEnumFirstW (
  905. OUT PMULTISZ_ENUMW MultiSzEnum,
  906. IN PCWSTR MultiSzStr
  907. );
  908. PCSTR
  909. MszFindStringA (
  910. IN PCSTR MultiSz,
  911. IN PCSTR String
  912. );
  913. PCWSTR
  914. MszFindStringW (
  915. IN PCWSTR MultiSz,
  916. IN PCWSTR String
  917. );
  918. PCSTR
  919. MszIFindStringA (
  920. IN PCSTR MultiSz,
  921. IN PCSTR String
  922. );
  923. PCWSTR
  924. MszIFindStringW (
  925. IN PCWSTR MultiSz,
  926. IN PCWSTR String
  927. );
  928. //
  929. // TCHAR mappings
  930. //
  931. #ifdef UNICODE
  932. // units of logical characters
  933. #define SzLcharCount SzLcharCountW
  934. #define SzLcharCountAB SzLcharCountABW
  935. #define SzLcharsToPointer SzLcharsToPointerW
  936. #define SzLcharsInByteRange SzLcharsInByteRangeW
  937. #define SzLcharsToBytes SzLcharsToBytesW
  938. #define SzLcharsToTchars SzLcharsToTcharsW
  939. // units of bytes
  940. #define SzByteCount SzByteCountW
  941. #define SzByteCountAB SzByteCountABW
  942. #define SzSize SzSizeW
  943. #define SzBytesToPointer SzBytesToPointerW
  944. #define SzBytesToLchars SzBytesToLcharsW
  945. #define SzBytesToTchars SzBytesToTcharsW
  946. // units of TCHARs
  947. #define SzTcharCount SzTcharCountW
  948. #define SzTcharCountAB SzTcharCountABW
  949. #define SzTcharsToPointer SzTcharsToPointerW
  950. #define SzTcharsToLchars SzTcharsToLcharsW
  951. #define SzTcharsToBytes SzTcharsToBytesW
  952. // multi-sz
  953. #define MszSize MszSizeW
  954. #define MszTcharCount MszTcharCountW
  955. #define MULTISZ_ENUM MULTISZ_ENUMW
  956. #define MszEnumFirst MszEnumFirstW
  957. #define MszEnumNext MszEnumNextW
  958. #define MszFindString MszFindStringW
  959. #define MszIFindString MszIFindStringW
  960. // copy routines
  961. #define SzBufferCopy SzBufferCopyW
  962. #define SzCopy SzCopyW
  963. #define SzCopyBytes SzCopyBytesW
  964. #define SzCopyLchars SzCopyLcharsW
  965. #define SzCopyTchars SzCopyTcharsW
  966. #define SzCopyAB SzCopyABW
  967. #define SzCat SzCatW
  968. // compare routines
  969. #define SzCompare SzCompareW
  970. #define SzMatch SzMatchW
  971. #define SzICompare SzICompareW
  972. #define SzIMatch SzIMatchW
  973. #define SzCompareBytes SzCompareBytesW
  974. #define SzMatchBytes SzMatchBytesW
  975. #define SzICompareBytes SzICompareBytesW
  976. #define SzIMatchBytes SzIMatchBytesW
  977. #define SzCompareLchars SzCompareLcharsW
  978. #define SzMatchLchars SzMatchLcharsW
  979. #define SzICompareLchars SzICompareLcharsW
  980. #define SzIMatchLchars SzIMatchLcharsW
  981. #define SzCompareTchars SzCompareTcharsW
  982. #define SzMatchTchars SzMatchTcharsW
  983. #define SzICompareTchars SzICompareTcharsW
  984. #define SzIMatchTchars SzIMatchTcharsW
  985. #define SzCompareAB SzCompareABW
  986. #define SzMatchAB SzMatchABW
  987. #define SzICompareAB SzICompareABW
  988. #define SzIMatchAB SzIMatchABW
  989. #define SzPrefix SzPrefixW
  990. #define SzIPrefix SzIPrefixW
  991. // char copy routines
  992. #define SzCopyNextChar SzCopyNextCharW
  993. #define SzReplaceChar SzReplaceCharW
  994. #define SzTrimLastChar SzTrimLastCharW
  995. // search routines
  996. #define SzGetEnd SzGetEndW
  997. #define SzFindPrevChar SzFindPrevCharW
  998. #define SzIsPrint SzIsPrintW
  999. #define SzFindSubString SzFindSubStringW
  1000. #define SzIFindSubString SzIFindSubStringW
  1001. #define SzSkipSpace SzSkipSpaceW
  1002. #define SzSkipSpaceR SzSkipSpaceRW
  1003. #define SzCountInstancesOfLchar SzCountInstancesOfLcharW
  1004. #define SzICountInstancesOfLchar SzICountInstancesOfLcharW
  1005. #define SzCountInstancesOfSubString SzCountInstancesOfSubStringW
  1006. #define SzICountInstancesOfSubString SzICountInstancesOfSubStringW
  1007. // search-replace routines
  1008. #define SzTruncateTrailingSpace SzTruncateTrailingSpaceW
  1009. #define SzReplace SzReplaceW
  1010. // numeric conversion
  1011. #define SzToNumber SzToNumberW
  1012. #define SzToULongLong SzToULongLongW
  1013. #define SzToLongLong SzToLongLongW
  1014. #define SzUnsignedToHex SzUnsignedToHexW
  1015. #define SzUnsignedToDec SzUnsignedToDecW
  1016. #define SzSignedToDec SzSignedToDecW
  1017. // path routines
  1018. #define SzAppendWack SzAppendWackW
  1019. #define SzConcatenatePaths SzConcatenatePathsW
  1020. #define SzAppendDosWack SzAppendDosWackW
  1021. #define SzAppendUncWack SzAppendUncWackW
  1022. #define SzAppendPathWack SzAppendPathWackW
  1023. #define SzRemoveWackAtEnd SzRemoveWackAtEndW
  1024. #define SzGetFileNameFromPath SzGetFileNameFromPathW
  1025. #define SzGetFileExtensionFromPath SzGetFileExtensionFromPathW
  1026. #define SzGetDotExtensionFromPath SzGetDotExtensionFromPathW
  1027. #define SzFindLastWack SzFindLastWackW
  1028. #else
  1029. // units of logical characters
  1030. #define SzLcharCount SzLcharCountA
  1031. #define SzLcharCountAB SzLcharCountABA
  1032. #define SzLcharsToPointer SzLcharsToPointerA
  1033. #define SzLcharsInByteRange SzLcharsInByteRangeA
  1034. #define SzLcharsToBytes SzLcharsToBytesA
  1035. #define SzLcharsToTchars SzLcharsToTcharsA
  1036. // units of bytes
  1037. #define SzByteCount SzByteCountA
  1038. #define SzByteCountAB SzByteCountABA
  1039. #define SzSize SzSizeA
  1040. #define SzBytesToPointer SzBytesToPointerA
  1041. #define SzBytesToLchars SzBytesToLcharsA
  1042. #define SzBytesToTchars SzBytesToTcharsA
  1043. // units of TCHARs
  1044. #define SzTcharCount SzTcharCountA
  1045. #define SzTcharCountAB SzTcharCountABA
  1046. #define SzTcharsToPointer SzTcharsToPointerA
  1047. #define SzTcharsToLchars SzTcharsToLcharsA
  1048. #define SzTcharsToBytes SzTcharsToBytesA
  1049. // multi-sz
  1050. #define MszSize MszSizeA
  1051. #define MszTcharCount MszTcharCountA
  1052. #define MULTISZ_ENUM MULTISZ_ENUMA
  1053. #define MszEnumFirst MszEnumFirstA
  1054. #define MszEnumNext MszEnumNextA
  1055. #define MszFindString MszFindStringA
  1056. #define MszIFindString MszIFindStringA
  1057. // copy routines
  1058. #define SzBufferCopy SzBufferCopyA
  1059. #define SzCopy SzCopyA
  1060. #define SzCopyBytes SzCopyBytesA
  1061. #define SzCopyLchars SzCopyLcharsA
  1062. #define SzCopyTchars SzCopyTcharsA
  1063. #define SzCopyAB SzCopyABA
  1064. #define SzCat SzCatA
  1065. // compare routines
  1066. #define SzCompare SzCompareA
  1067. #define SzMatch SzMatchA
  1068. #define SzICompare SzICompareA
  1069. #define SzIMatch SzIMatchA
  1070. #define SzCompareBytes SzCompareBytesA
  1071. #define SzMatchBytes SzMatchBytesA
  1072. #define SzICompareBytes SzICompareBytesA
  1073. #define SzIMatchBytes SzIMatchBytesA
  1074. #define SzCompareLchars SzCompareLcharsA
  1075. #define SzMatchLchars SzMatchLcharsA
  1076. #define SzICompareLchars SzICompareLcharsA
  1077. #define SzIMatchLchars SzIMatchLcharsA
  1078. #define SzCompareTchars SzCompareTcharsA
  1079. #define SzMatchTchars SzMatchTcharsA
  1080. #define SzICompareTchars SzICompareTcharsA
  1081. #define SzIMatchTchars SzIMatchTcharsA
  1082. #define SzCompareAB SzCompareABA
  1083. #define SzMatchAB SzMatchABA
  1084. #define SzICompareAB SzICompareABA
  1085. #define SzIMatchAB SzIMatchABA
  1086. #define SzPrefix SzPrefixA
  1087. #define SzIPrefix SzIPrefixA
  1088. // char copy routines
  1089. #define SzCopyNextChar SzCopyNextCharA
  1090. #define SzReplaceChar SzReplaceCharA
  1091. #define SzTrimLastChar SzTrimLastCharA
  1092. // search routines
  1093. #define SzGetEnd SzGetEndA
  1094. #define SzFindPrevChar SzFindPrevCharA
  1095. #define SzIsPrint SzIsPrintA
  1096. #define SzFindSubString SzFindSubStringA
  1097. #define SzIFindSubString SzIFindSubStringA
  1098. #define SzSkipSpace SzSkipSpaceA
  1099. #define SzSkipSpaceR SzSkipSpaceRA
  1100. #define SzCountInstancesOfLchar SzCountInstancesOfLcharA
  1101. #define SzICountInstancesOfLchar SzICountInstancesOfLcharA
  1102. #define SzCountInstancesOfSubString SzCountInstancesOfSubStringA
  1103. #define SzICountInstancesOfSubString SzICountInstancesOfSubStringA
  1104. // search-replace routines
  1105. #define SzTruncateTrailingSpace SzTruncateTrailingSpaceA
  1106. #define SzReplace SzReplaceA
  1107. // numeric conversion
  1108. #define SzToNumber SzToNumberA
  1109. #define SzToULongLong SzToULongLongA
  1110. #define SzToLongLong SzToLongLongA
  1111. #define SzUnsignedToHex SzUnsignedToHexA
  1112. #define SzUnsignedToDec SzUnsignedToDecA
  1113. #define SzSignedToDec SzSignedToDecA
  1114. // path routines
  1115. #define SzAppendWack SzAppendWackA
  1116. #define SzConcatenatePaths SzConcatenatePathsA
  1117. #define SzAppendDosWack SzAppendDosWackA
  1118. #define SzAppendUncWack SzAppendUncWackA
  1119. #define SzAppendPathWack SzAppendPathWackA
  1120. #define SzRemoveWackAtEnd SzRemoveWackAtEndA
  1121. #define SzGetFileNameFromPath SzGetFileNameFromPathA
  1122. #define SzGetFileExtensionFromPath SzGetFileExtensionFromPathA
  1123. #define SzGetDotExtensionFromPath SzGetDotExtensionFromPathA
  1124. #define SzFindLastWack SzFindLastWackA
  1125. #endif
  1126. #ifdef __cplusplus
  1127. }
  1128. #endif