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.

201 lines
4.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: cruntime.cxx
  7. //
  8. // Contents: Implementation of Cruntimes that we need since we
  9. // can't use MSVCRT and WIn95 doesn't implement the lstr*W
  10. // versions. (well, it implements them but they are just stubs)
  11. //
  12. //
  13. // Functions: Laylstrcmp
  14. // Laylstrcpy
  15. // Laylstrcpyn
  16. // Laylstrlen
  17. // Laylstrcat
  18. //
  19. // History: 20-Jun-96 SusiA Created
  20. //
  21. //----------------------------------------------------------------------------
  22. #pragma hdrstop
  23. #include <string.h>
  24. /***
  25. * Laylstrcmp - compare two wchar_t strings,
  26. * returning less than, equal to, or greater than
  27. *
  28. *Purpose:
  29. * wcscmp compares two wide-character strings and returns an integer
  30. * to indicate whether the first is less than the second, the two are
  31. * equal, or whether the first is greater than the second.
  32. *
  33. * Comparison is done wchar_t by wchar_t on an UNSIGNED basis, which is to
  34. * say that Null wchar_t(0) is less than any other character.
  35. *
  36. *Entry:
  37. * const wchar_t * src - string for left-hand side of comparison
  38. * const wchar_t * dst - string for right-hand side of comparison
  39. *
  40. *Exit:
  41. * returns -1 if src < dst
  42. * returns 0 if src == dst
  43. * returns +1 if src > dst
  44. *
  45. *Exceptions:
  46. *
  47. *******************************************************************************/
  48. int Laylstrcmp (
  49. const wchar_t * src,
  50. const wchar_t * dst
  51. )
  52. {
  53. int ret = 0 ;
  54. while( ! (ret = (int)(*src - *dst)) && *dst)
  55. ++src, ++dst;
  56. if ( ret < 0 )
  57. ret = -1 ;
  58. else if ( ret > 0 )
  59. ret = 1 ;
  60. return( ret );
  61. }
  62. /***
  63. *wchar_t *Laylstrcat(dst, src) - concatenate (append) one wchar_t string to another
  64. *
  65. *Purpose:
  66. * Concatenates src onto the end of dest. Assumes enough
  67. * space in dest.
  68. *
  69. *Entry:
  70. * wchar_t *dst - wchar_t string to which "src" is to be appended
  71. * const wchar_t *src - wchar_t string to be appended to the end of "dst"
  72. *
  73. *Exit:
  74. * The address of "dst"
  75. *
  76. *Exceptions:
  77. *
  78. *******************************************************************************/
  79. wchar_t * Laylstrcat (
  80. wchar_t * dst,
  81. const wchar_t * src
  82. )
  83. {
  84. wchar_t * cp = dst;
  85. while( *cp )
  86. cp++; /* find end of dst */
  87. while( *cp++ = *src++ ) ; /* Copy src to end of dst */
  88. return( dst ); /* return dst */
  89. }
  90. /***
  91. *wchar_t *Laylstrcpy(dst, src) - copy one wchar_t string over another
  92. *
  93. *Purpose:
  94. * Copies the wchar_t string src into the spot specified by
  95. * dest; assumes enough room.
  96. *
  97. *Entry:
  98. * wchar_t * dst - wchar_t string over which "src" is to be copied
  99. * const wchar_t * src - wchar_t string to be copied over "dst"
  100. *
  101. *Exit:
  102. * The address of "dst"
  103. *
  104. *Exceptions:
  105. *******************************************************************************/
  106. wchar_t * Laylstrcpy(wchar_t * dst, const wchar_t * src)
  107. {
  108. wchar_t * cp = dst;
  109. while( *cp++ = *src++ )
  110. ; /* Copy src over dst */
  111. return( dst );
  112. }
  113. /***
  114. *wchar_t *Laylstrcpyn(dest, source, count) - copy at most n wide characters
  115. *
  116. *Purpose:
  117. * Copies count characters from the source string to the
  118. * destination. If count is less than the length of source,
  119. * NO NULL CHARACTER is put onto the end of the copied string.
  120. * If count is greater than the length of sources, dest is padded
  121. * with null characters to length count (wide-characters).
  122. *
  123. *
  124. *Entry:
  125. * wchar_t *dest - pointer to destination
  126. * wchar_t *source - source string for copy
  127. * size_t count - max number of characters to copy
  128. *
  129. *Exit:
  130. * returns dest
  131. *
  132. *Exceptions:
  133. *
  134. *******************************************************************************/
  135. wchar_t * Laylstrcpyn (
  136. wchar_t * dest,
  137. const wchar_t * source,
  138. size_t count
  139. )
  140. {
  141. wchar_t *start = dest;
  142. while (count && (*dest++ = *source++)) /* copy string */
  143. count--;
  144. if (count) /* pad out with zeroes */
  145. while (--count)
  146. *dest++ = L'\0';
  147. return(start);
  148. }
  149. /***
  150. *Laylstrlen - return the length of a null-terminated wide-character string
  151. *
  152. *Purpose:
  153. * Finds the length in wchar_t's of the given string, not including
  154. * the final null wchar_t (wide-characters).
  155. *
  156. *Entry:
  157. * const wchar_t * wcs - string whose length is to be computed
  158. *
  159. *Exit:
  160. * length of the string "wcs", exclusive of the final null wchar_t
  161. *
  162. *Exceptions:
  163. *
  164. *******************************************************************************/
  165. size_t Laylstrlen (
  166. const wchar_t * wcs
  167. )
  168. {
  169. const wchar_t *eos = wcs;
  170. while( *eos++ ) ;
  171. return( (size_t)(eos - wcs - 1) );
  172. }