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.

77 lines
2.0 KiB

  1. /***
  2. *mbsnccnt.c - Return char count of MBCS string
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Return char count of MBCS string
  8. *
  9. *Revision History:
  10. * 11-19-92 KRS Ported from 16-bit sources.
  11. * 10-05-93 GJF Replaced _CRTAPI1 with __cdecl.
  12. * 04-15-93 CFW Add _MB_CP_LOCK.
  13. * 05-19-94 CFW Enable non-Win32.
  14. * 04-15-98 GJF Revised multithread support based on threadmbcinfo
  15. * structs
  16. *
  17. *******************************************************************************/
  18. #ifdef _MBCS
  19. #include <mtdll.h>
  20. #include <cruntime.h>
  21. #include <mbdata.h>
  22. #include <mbctype.h>
  23. #include <mbstring.h>
  24. /***
  25. * _mbsnccnt - Return char count of MBCS string
  26. *
  27. *Purpose:
  28. * Returns the number of chars between the start of the supplied
  29. * string and the byte count supplied. That is, this routine
  30. * indicates how many chars are in the first "bcnt" bytes
  31. * of the string.
  32. *
  33. *Entry:
  34. * const unsigned char *string = pointer to string
  35. * unsigned int bcnt = number of bytes to scan
  36. *
  37. *Exit:
  38. * Returns number of chars between string and bcnt.
  39. *
  40. * If the end of the string is encountered before bcnt chars were
  41. * scanned, then the length of the string in chars is returned.
  42. *
  43. *Exceptions:
  44. *
  45. *******************************************************************************/
  46. size_t __cdecl _mbsnccnt(
  47. const unsigned char *string,
  48. size_t bcnt
  49. )
  50. {
  51. unsigned int n;
  52. #ifdef _MT
  53. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  54. if ( ptmbci != __ptmbcinfo )
  55. ptmbci = __updatetmbcinfo();
  56. #endif
  57. for (n = 0; (bcnt-- && *string); n++, string++) {
  58. #ifdef _MT
  59. if ( __ismbblead_mt(ptmbci, *string) ) {
  60. #else
  61. if ( _ismbblead(*string) ) {
  62. #endif
  63. if ( (!bcnt--) || (*++string == '\0'))
  64. break;
  65. }
  66. }
  67. return(n);
  68. }
  69. #endif /* _MBCS */