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.

177 lines
4.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1997
  6. //
  7. // File: tfschar.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "tfschar.h"
  12. /*!--------------------------------------------------------------------------
  13. StrCpyAFromW
  14. -
  15. Author: KennT
  16. ---------------------------------------------------------------------------*/
  17. TFSCORE_API(LPSTR) StrCpyAFromW(LPSTR psz, LPCWSTR pswz)
  18. {
  19. USES_CONVERSION;
  20. return StrCpyA(psz, W2CA(pswz));
  21. }
  22. /*!--------------------------------------------------------------------------
  23. StrCpyWFromA
  24. -
  25. Author: KennT
  26. ---------------------------------------------------------------------------*/
  27. TFSCORE_API(LPWSTR) StrCpyWFromA(LPWSTR pswz, LPCSTR psz)
  28. {
  29. USES_CONVERSION;
  30. return StrCpyW(pswz, A2CW(psz));
  31. }
  32. /*!--------------------------------------------------------------------------
  33. StrnCpyAFromW
  34. -
  35. Author: KennT
  36. ---------------------------------------------------------------------------*/
  37. TFSCORE_API(LPSTR) StrnCpyAFromW(LPSTR psz, LPCWSTR pswz, int iMax)
  38. {
  39. USES_CONVERSION;
  40. return StrnCpyA(psz, W2CA(pswz), iMax);
  41. }
  42. /*!--------------------------------------------------------------------------
  43. StrnCpyWFromA
  44. -
  45. Author: KennT
  46. ---------------------------------------------------------------------------*/
  47. TFSCORE_API(LPWSTR) StrnCpyWFromA(LPWSTR pswz, LPCSTR psz, int iMax)
  48. {
  49. USES_CONVERSION;
  50. return StrnCpyW(pswz, A2CW(psz), iMax);
  51. }
  52. /*!--------------------------------------------------------------------------
  53. StrDupA
  54. -
  55. Author: KennT
  56. ---------------------------------------------------------------------------*/
  57. TFSCORE_API(LPSTR) StrDupA( LPCSTR psz )
  58. {
  59. // Multiply by 2 to account for DBCS strings
  60. LPSTR pszcpy = new char[CbStrLenA(psz)*2];
  61. return StrCpyA(pszcpy, psz);
  62. }
  63. /*!--------------------------------------------------------------------------
  64. StrDupW
  65. -
  66. Author: KennT
  67. ---------------------------------------------------------------------------*/
  68. TFSCORE_API(LPWSTR) StrDupW( LPCWSTR pswz )
  69. {
  70. LPWSTR pswzcpy = new WCHAR[CbStrLenW(pswz)];
  71. return StrCpyW(pswzcpy, pswz);
  72. }
  73. /*!--------------------------------------------------------------------------
  74. StrDupAFromW
  75. -
  76. Author: KennT
  77. ---------------------------------------------------------------------------*/
  78. TFSCORE_API(LPSTR) StrDupAFromW( LPCWSTR pwsz )
  79. {
  80. USES_CONVERSION;
  81. return StrDupA( W2CA(pwsz) );
  82. }
  83. /*!--------------------------------------------------------------------------
  84. StrDupWFromA
  85. -
  86. Author: KennT
  87. ---------------------------------------------------------------------------*/
  88. TFSCORE_API(LPWSTR) StrDupWFromA( LPCSTR psz )
  89. {
  90. USES_CONVERSION;
  91. return StrDupW( A2CW(psz) );
  92. }
  93. /*!--------------------------------------------------------------------------
  94. StrnCmpA
  95. -
  96. Author: KennT
  97. ---------------------------------------------------------------------------*/
  98. TFSCORE_API(int) StrnCmpA(LPCSTR psz1, LPCSTR psz2, int nLen)
  99. {
  100. USES_CONVERSION;
  101. // It's easier to convert it to a wide string than do the
  102. // conversion. (it's a pain having to deal with DBCS characters).
  103. return StrnCmpW(A2CW(psz1), A2CW(psz2), nLen);
  104. }
  105. /*!--------------------------------------------------------------------------
  106. StrnCmpW
  107. -
  108. Author: KennT
  109. ---------------------------------------------------------------------------*/
  110. TFSCORE_API(int) StrnCmpW(LPCWSTR pswz1, LPCWSTR pswz2, int nLen)
  111. {
  112. WCHAR *pswz1Temp = AllocaStrDupW(pswz1);
  113. WCHAR *pswz2Temp = AllocaStrDupW(pswz2);
  114. if (pswz1Temp && StrLenW(pswz1Temp) > nLen)
  115. pswz1Temp[nLen] = 0;
  116. if (pswz2Temp && StrLenW(pswz2Temp) > nLen)
  117. pswz2Temp[nLen] = 0;
  118. return StrCmpW(pswz1Temp, pswz2Temp);
  119. }
  120. /*!--------------------------------------------------------------------------
  121. StrniCmpA
  122. -
  123. Author: KennT
  124. ---------------------------------------------------------------------------*/
  125. TFSCORE_API(int) StrniCmpA(LPCSTR psz1, LPCSTR psz2, int nLen)
  126. {
  127. CHAR *psz1Temp = AllocaStrDupA(psz1);
  128. CHAR *psz2Temp = AllocaStrDupA(psz2);
  129. if (psz1Temp)
  130. CharUpperBuffA(psz1Temp, StrLenA(psz1Temp));
  131. if (psz2Temp)
  132. CharUpperBuffA(psz2Temp, StrLenA(psz2Temp));
  133. return StrnCmpA(psz1Temp, psz2Temp, nLen);
  134. }
  135. /*!--------------------------------------------------------------------------
  136. StrniCmpW
  137. -
  138. Author: KennT
  139. ---------------------------------------------------------------------------*/
  140. TFSCORE_API(int) StrniCmpW(LPCWSTR pswz1, LPCWSTR pswz2, int nLen)
  141. {
  142. WCHAR *pswz1Temp = AllocaStrDupW(pswz1);
  143. WCHAR *pswz2Temp = AllocaStrDupW(pswz2);
  144. if (pswz1Temp)
  145. CharUpperBuffW(pswz1Temp, StrLenW(pswz1Temp));
  146. if (pswz2Temp)
  147. CharUpperBuffW(pswz2Temp, StrLenW(pswz2Temp));
  148. return StrnCmpW(pswz1Temp, pswz2Temp, nLen);
  149. }