Leaked source code of windows server 2003
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.

89 lines
2.4 KiB

  1. /***
  2. *ismbstrail.c - True _ismbstrail function
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Contains the function _ismbstrail, which is a true context-sensitive
  8. * MBCS trail-byte function. While much less efficient than _ismbbtrail,
  9. * it is also much more sophisticated, in that it determines whether a
  10. * given sub-string pointer points to a trail byte or not, taking into
  11. * account the context in the string.
  12. *
  13. *Revision History:
  14. *
  15. * 08-03-93 KRS Ported from 16-bit tree.
  16. * 10-05-93 GJF Replaced _CRTAPI1 with __cdecl.
  17. * 04-15-93 CFW Add _MB_CP_LOCK.
  18. * 05-09-94 CFW Optimize for SBCS.
  19. * 05-19-94 CFW Enable non-Win32.
  20. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  21. * 04-02-98 GJF Implemented multithread support based on threadmbcinfo
  22. * structs
  23. *
  24. *******************************************************************************/
  25. #ifdef _MBCS
  26. #include <mtdll.h>
  27. #include <cruntime.h>
  28. #include <stddef.h>
  29. #include <mbdata.h>
  30. #include <mbctype.h>
  31. #include <mbstring.h>
  32. /***
  33. * int _ismbstrail(const unsigned char *string, const unsigned char *current);
  34. *
  35. *Purpose:
  36. *
  37. * _ismbstrail - Check, in context, for MBCS trail byte
  38. *
  39. *Entry:
  40. * unsigned char *string - ptr to start of string or previous known lead byte
  41. * unsigned char *current - ptr to position in string to be tested
  42. *
  43. *Exit:
  44. * TRUE : -1
  45. * FALSE : 0
  46. *
  47. *Exceptions:
  48. *
  49. *******************************************************************************/
  50. int __cdecl _ismbstrail(
  51. const unsigned char *string,
  52. const unsigned char *current
  53. )
  54. {
  55. #ifdef _MT
  56. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  57. if ( ptmbci != __ptmbcinfo )
  58. ptmbci = __updatetmbcinfo();
  59. if ( _ISNOTMBCP_MT(ptmbci) )
  60. #else
  61. if ( _ISNOTMBCP )
  62. #endif
  63. return 0;
  64. while ( string <= current && *string ) {
  65. #ifdef _MT
  66. if ( __ismbblead_mt(ptmbci, (*string)) ) {
  67. #else
  68. if ( _ismbblead((*string)) ) {
  69. #endif
  70. if (++string == current) /* check trail byte */
  71. return -1;
  72. if (!(*string))
  73. return 0;
  74. }
  75. ++string;
  76. }
  77. return 0;
  78. }
  79. #endif