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

  1. /***
  2. *ismbslead.c - True _ismbslead function
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Contains the function _ismbslead, which is a true context-sensitive
  8. *       MBCS lead-byte function.  While much less efficient than _ismbblead,
  9. *       it is also much more sophisticated, in that it determines whether a
  10. *       given sub-string pointer points to a lead byte or not, taking into
  11. *       account the context in the string.
  12. *
  13. *******************************************************************************/
  14.  
  15. #ifdef _MBCS
  16.  
  17. #include <mtdll.h>
  18. #include <cruntime.h>
  19. #include <stddef.h>
  20. #include <mbdata.h>
  21. #include <mbctype.h>
  22. #include <mbstring.h>
  23.  
  24.  
  25. /***
  26. * int _ismbslead(const unsigned char *string, const unsigned char *current);
  27. *
  28. *Purpose:
  29. *
  30. *       _ismbslead - Check, in context, for MBCS lead byte
  31. *
  32. *Entry:
  33. *       unsigned char *string   - ptr to start of string or previous known lead byte
  34. *       unsigned char *current  - ptr to position in string to be tested
  35. *
  36. *Exit:
  37. *       TRUE    : -1
  38. *       FALSE   : 0
  39. *
  40. *Exceptions:
  41. *
  42. *******************************************************************************/
  43.  
  44. int __cdecl _ismbslead(
  45.         const unsigned char *string,
  46.         const unsigned char *current
  47.         )
  48. {
  49.         if ( _ISNOTMBCP )
  50.             return 0;
  51.  
  52.         _mlock(_MB_CP_LOCK);
  53.  
  54.         while (string <= current && *string) {
  55.                 if (_ISLEADBYTE((*string))) {
  56.                         if (string++ == current)        /* check lead byte */
  57.                 {
  58.                     _munlock(_MB_CP_LOCK);
  59.                                 return -1;
  60.                 }
  61.                         if (!(*string))
  62.                 {
  63.                     _munlock(_MB_CP_LOCK);
  64.                                 return 0;
  65.                 }
  66.                 }
  67.                 ++string;
  68.         }
  69.  
  70.         _munlock(_MB_CP_LOCK);
  71.         return 0;
  72. }
  73.  
  74. #endif  /* _MBCS */
  75.