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.

97 lines
2.6 KiB

  1. /***
  2. * mbschr.c - Search MBCS string for character
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Search MBCS string for a character
  8. *
  9. *Revision History:
  10. * 11-19-92 KRS Ported from 16-bit sources.
  11. * 05-12-93 KRS Fix handling of c=='\0'.
  12. * 08-20-93 CFW Change param type to int, use new style param declarators.
  13. * 10-05-93 GJF Replaced _CRTAPI1 with __cdecl.
  14. * 04-15-93 CFW Add _MB_CP_LOCK.
  15. * 05-09-94 CFW Optimize for SBCS.
  16. * 05-19-94 CFW Enable non-Win32.
  17. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  18. * 04-06-98 GJF Revised multithread support based on threadmbcinfo
  19. * structs
  20. *
  21. *******************************************************************************/
  22. #ifdef _MBCS
  23. #include <mtdll.h>
  24. #include <cruntime.h>
  25. #include <string.h>
  26. #include <mbdata.h>
  27. #include <mbctype.h>
  28. #include <mbstring.h>
  29. #include <stddef.h>
  30. /***
  31. * _mbschr - Search MBCS string for character
  32. *
  33. *Purpose:
  34. * Search the given string for the specified character.
  35. * MBCS characters are handled correctly.
  36. *
  37. *Entry:
  38. * unsigned char *string = string to search
  39. * int c = character to search for
  40. *
  41. *Exit:
  42. * returns a pointer to the first occurence of the specified char
  43. * within the string.
  44. *
  45. * returns NULL if the character is not found n the string.
  46. *
  47. *Exceptions:
  48. *
  49. *******************************************************************************/
  50. unsigned char * __cdecl _mbschr(
  51. const unsigned char *string,
  52. unsigned int c
  53. )
  54. {
  55. unsigned short cc;
  56. #ifdef _MT
  57. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  58. if ( ptmbci != __ptmbcinfo )
  59. ptmbci = __updatetmbcinfo();
  60. if ( _ISNOTMBCP_MT(ptmbci) )
  61. #else
  62. if ( _ISNOTMBCP )
  63. #endif
  64. return strchr(string, c);
  65. for (; (cc = *string); string++)
  66. {
  67. #ifdef _MT
  68. if ( __ismbblead_mt(ptmbci, cc) )
  69. #else
  70. if ( _ismbblead(cc) )
  71. #endif
  72. {
  73. if (*++string == '\0')
  74. return NULL; /* error */
  75. if ( c == (unsigned int)((cc << 8) | *string) ) /* DBCS match */
  76. return (unsigned char *)(string - 1);
  77. }
  78. else if (c == (unsigned int)cc)
  79. break; /* SBCS match */
  80. }
  81. if (c == (unsigned int)cc) /* check for SBCS match--handles NUL char */
  82. return (unsigned char *)(string);
  83. return NULL;
  84. }
  85. #endif /* _MBCS */