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

  1. /***
  2. *mbbtype.c - Return type of byte based on previous byte (MBCS)
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Return type of byte based on previous byte (MBCS)
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _MBCS
  12.  
  13. #include <cruntime.h>
  14. #include <mbdata.h>
  15. #include <mbctype.h>
  16. #include <mbstring.h>
  17.  
  18. /***
  19. *int _mbbtype(c, ctype) - Return type of byte based on previous byte (MBCS)
  20. *
  21. *Purpose:
  22. *       Returns type of supplied byte.  This decision is context
  23. *       sensitive so a control test condition is supplied.  Normally,
  24. *       this is the type of the previous byte in the string.
  25. *
  26. *Entry:
  27. *       unsigned char c = character to be checked
  28. *       int ctype = control test condition (i.e., type of previous char)
  29. *
  30. *Exit:
  31. *       _MBC_LEAD      = if 1st byte of MBCS char
  32. *       _MBC_TRAIL     = if 2nd byte of MBCS char
  33. *       _MBC_SINGLE    = valid single byte char
  34. *
  35. *       _MBC_ILLEGAL   = if illegal char
  36. *
  37. *Exceptions:
  38. *
  39. *******************************************************************************/
  40.  
  41. int __cdecl _mbbtype(
  42.     unsigned char c,
  43.     int ctype
  44.     )
  45. {
  46.  
  47.         switch(ctype) {
  48.  
  49.         case(_MBC_LEAD):
  50.                 if (_ISTRAILBYTE(c))
  51.                         return(_MBC_TRAIL);
  52.                 else
  53.                         return(_MBC_ILLEGAL);
  54.  
  55.         case(_MBC_TRAIL):
  56.         case(_MBC_SINGLE):
  57.         case(_MBC_ILLEGAL):
  58.         default:
  59.                 if (_ISLEADBYTE(c))
  60.                         return(_MBC_LEAD);
  61.                 else if (_ismbbprint(c))
  62.                         return(_MBC_SINGLE);
  63.                 else
  64.                         return(_MBC_ILLEGAL);
  65.  
  66.  
  67.         }
  68.  
  69. }
  70.  
  71. #endif  /* _MBCS */
  72.