home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / mbsnccnt.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  64 lines

  1. /***
  2. *mbsnccnt.c - Return char count of MBCS string
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Return char count of MBCS string
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _MBCS
  12.  
  13. #include <mtdll.h>
  14. #include <cruntime.h>
  15. #include <mbdata.h>
  16. #include <mbctype.h>
  17. #include <mbstring.h>
  18.  
  19.  
  20. /***
  21. * _mbsnccnt - Return char count of MBCS string
  22. *
  23. *Purpose:
  24. *       Returns the number of chars between the start of the supplied
  25. *       string and the byte count supplied.  That is, this routine
  26. *       indicates how many chars are in the first "bcnt" bytes
  27. *       of the string.
  28. *
  29. *Entry:
  30. *       const unsigned char *string = pointer to string
  31. *       unsigned int bcnt = number of bytes to scan
  32. *
  33. *Exit:
  34. *       Returns number of chars between string and bcnt.
  35. *
  36. *       If the end of the string is encountered before bcnt chars were
  37. *       scanned, then the length of the string in chars is returned.
  38. *
  39. *Exceptions:
  40. *
  41. *******************************************************************************/
  42.  
  43. size_t __cdecl _mbsnccnt(
  44.     const unsigned char *string,
  45.     size_t bcnt
  46.     )
  47. {
  48.         unsigned int n;
  49.  
  50.         _mlock(_MB_CP_LOCK);
  51.  
  52.         for (n = 0; (bcnt-- && *string); n++, string++) {
  53.  
  54.                 if (_ISLEADBYTE(*string)) {
  55.                         if ( (!bcnt--) || (*++string == '\0'))
  56.                                 break;
  57.                 }
  58.         }
  59.  
  60.         _munlock(_MB_CP_LOCK);
  61.         return(n);
  62. }
  63. #endif  /* _MBCS */
  64.