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.

81 lines
2.7 KiB

  1. /*---------------------------------------------------------------------------
  2. File: StrHelp.cpp
  3. Comments: Contains general string helper functions.
  4. REVISION LOG ENTRY
  5. Revision By: Paul Thompson
  6. Revised on 11/02/00
  7. ---------------------------------------------------------------------------
  8. */
  9. #ifdef USE_STDAFX
  10. #include "stdafx.h"
  11. #else
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #endif
  15. /*********************************************************************
  16. * *
  17. * Written by: Paul Thompson *
  18. * Date: 2 NOV 2000 *
  19. * *
  20. * This function is responsible for determining if a given string*
  21. * is found, in whole, in a given delimited string. The string *
  22. * delimitedr can be most any character except the NULL char ('\0'). *
  23. * By the term "in whole", we mean to say that the given string *
  24. * to find is not solely a substring of another string in the *
  25. * delimited string. *
  26. * *
  27. *********************************************************************/
  28. //BEGIN IsStringInDelimitedString
  29. BOOL //ret- TRUE=string found
  30. IsStringInDelimitedString(
  31. LPCWSTR sDelimitedString, // in- delimited string to search
  32. LPCWSTR sString, // in- string to search for
  33. WCHAR cDelimitingChar // in- delimiting character used in the delimited string
  34. )
  35. {
  36. /* local variables */
  37. BOOL bFound = FALSE;
  38. int len;
  39. WCHAR * pSub;
  40. /* function body */
  41. if ((!sDelimitedString) || (!sString))
  42. return FALSE;
  43. len = wcslen(sString);
  44. pSub = wcsstr(sDelimitedString, sString);
  45. while ((pSub != NULL) && (!bFound))
  46. {
  47. //if not the start of the string being searched
  48. if (pSub != sDelimitedString)
  49. {
  50. //and if not the end of the string
  51. if (*(pSub+len) != L'\0')
  52. {
  53. //and if before and after are delimiters, then found
  54. if ((*(pSub-1) == cDelimitingChar) && (*(pSub+len) == cDelimitingChar))
  55. bFound = TRUE;
  56. }
  57. //else if end of string see the preceeding char was a delimiter
  58. else if (*(pSub-1) == cDelimitingChar)
  59. bFound = TRUE; //if so, found
  60. }
  61. //else start of string and after is delimiter or end, found
  62. else if ((*(pSub+len) == cDelimitingChar) || (*(pSub+len) == L'\0'))
  63. bFound = TRUE;
  64. //if not found yet, continue to search
  65. if (!bFound)
  66. pSub = wcsstr(pSub+1, sString);
  67. }
  68. return bFound;
  69. }
  70. //END IsStringInDelimitedString