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

  1. /***
  2. *mbsbtype.c - Return type of byte within a string (MBCS)
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Return type of byte within a string (MBCS)
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _MBCS
  12.  
  13. #include <mtdll.h>
  14. #include <cruntime.h>
  15. #include <mbdata.h>
  16. #include <mbstring.h>
  17. #include <mbctype.h>
  18.  
  19.  
  20. #define _MBBTYPE(p,c)   _mbbtype(p,c)
  21.  
  22. /***
  23. * _mbsbtype - Return type of byte within a string
  24. *
  25. *Purpose:
  26. *       Test byte within a string for MBCS char type.
  27. *       This function requires the start of the string because
  28. *       context must be taken into account.
  29. *
  30. *Entry:
  31. *       const unsigned char *string = pointer to string
  32. *       size_t len = position of the char in string
  33. *
  34. *Exit:
  35. *       returns one of the following values:
  36. *
  37. *       _MBC_LEAD      = if 1st byte of MBCS char
  38. *       _MBC_TRAIL     = if 2nd byte of MBCS char
  39. *       _MBC_SINGLE    = valid single byte char
  40. *
  41. *       _MBC_ILLEGAL   = if illegal char
  42. *
  43. *Exceptions:
  44. *       returns _MBC_ILLEGAL if len is bigger than string length
  45. *
  46. *******************************************************************************/
  47.  
  48. int __cdecl _mbsbtype(
  49.         const unsigned char *string,
  50.         size_t len
  51.         )
  52. {
  53.         int chartype;
  54.  
  55.         if ( _ISNOTMBCP )
  56.             return _MBC_SINGLE;
  57.  
  58.         _mlock(_MB_CP_LOCK);
  59.  
  60.         chartype = _MBC_ILLEGAL;
  61.         do {
  62.             if (*string == '\0')
  63.             {
  64.                 _munlock(_MB_CP_LOCK);
  65.                 return(_MBC_ILLEGAL);
  66.             }
  67.  
  68.             chartype = _MBBTYPE(*string++, chartype);
  69.  
  70.         }  while (len--);
  71.  
  72.         _munlock(_MB_CP_LOCK);
  73.         return(chartype);
  74. }
  75.  
  76. #endif  /* _MBCS */
  77.