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.

116 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. strtail.c
  5. Abstract:
  6. Contains:
  7. strtail
  8. ReverseString
  9. Author:
  10. Richard L. Firth (rfirth) 04-Apr-1991
  11. Revision History:
  12. --*/
  13. #include "nticanon.h"
  14. //
  15. // prototypes
  16. //
  17. LPTSTR
  18. ReverseString(
  19. IN OUT LPTSTR String
  20. );
  21. //
  22. // routines
  23. //
  24. LPTSTR
  25. strtail(
  26. IN LPTSTR str1,
  27. IN LPTSTR str2
  28. )
  29. /*++
  30. Routine Description:
  31. strtail returns a pointer to the longest trailing substring within str1
  32. consisting of characters contained in the set pointed at by str2
  33. Arguments:
  34. str1 pointer to string in which to find longest trailing substring
  35. str2 pointer to string of characters commprising substring
  36. Return Value:
  37. pointer to longest trailing substring or end of string
  38. --*/
  39. {
  40. int index;
  41. //
  42. // reverse subject string
  43. // get index of first non-matching character in target string
  44. // re-reverse subject string
  45. //
  46. ReverseString(str1);
  47. index = STRSPN(str1, str2);
  48. ReverseString(str1);
  49. return str1+STRLEN(str1)-index;
  50. }
  51. LPTSTR
  52. ReverseString(
  53. IN OUT LPTSTR String
  54. )
  55. /*++
  56. Routine Description:
  57. Reverses a UNICODE string (LPWSTR)
  58. Arguments:
  59. String - to be reversed. Reverses string in place
  60. Return Value:
  61. pointer to String
  62. --*/
  63. {
  64. DWORD len = STRLEN(String);
  65. DWORD i = 0;
  66. DWORD j = len - 1;
  67. TCHAR tmp;
  68. len /= 2;
  69. while (len) {
  70. tmp = String[i];
  71. String[i] = String[j];
  72. String[j] = tmp;
  73. ++i;
  74. --j;
  75. --len;
  76. }
  77. return String;
  78. }