Source code of Windows XP (NT5)
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.

100 lines
2.5 KiB

  1. /***
  2. *ismbslead.c - True _ismbslead function
  3. *
  4. * Copyright (c) 1985-2001, 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. *Revision History:
  14. * 08-03-93 KRS Ported from 16-bit tree.
  15. * 10-05-93 GJF Replaced _CRTAPI1 with __cdecl.
  16. * 04-15-93 CFW Add _MB_CP_LOCK.
  17. * 05-09-94 CFW Optimize for SBCS.
  18. * 05-19-94 CFW Enable non-Win32.
  19. * 09-11-97 GJF Replaced __mbcodepage == 0 with _ISNOTMBCP.
  20. * 04-15-98 GJF Implemented multithread support based on threadmbcinfo
  21. * structs
  22. *
  23. *******************************************************************************/
  24. #ifdef _MBCS
  25. #include <mtdll.h>
  26. #include <cruntime.h>
  27. #include <stddef.h>
  28. #include <mbdata.h>
  29. #include <mbctype.h>
  30. #include <mbstring.h>
  31. /***
  32. * int _ismbslead(const unsigned char *string, const unsigned char *current);
  33. *
  34. *Purpose:
  35. *
  36. * _ismbslead - Check, in context, for MBCS lead byte
  37. *
  38. *Entry:
  39. * unsigned char *string - ptr to start of string or previous known lead byte
  40. * unsigned char *current - ptr to position in string to be tested
  41. *
  42. *Exit:
  43. * TRUE : -1
  44. * FALSE : 0
  45. *
  46. *Exceptions:
  47. *
  48. *******************************************************************************/
  49. int __cdecl _ismbslead(
  50. const unsigned char *string,
  51. const unsigned char *current
  52. )
  53. {
  54. #ifdef _MT
  55. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  56. if ( ptmbci != __ptmbcinfo )
  57. ptmbci = __updatetmbcinfo();
  58. return __ismbslead_mt(ptmbci, string, current);
  59. }
  60. int __cdecl __ismbslead_mt(
  61. pthreadmbcinfo ptmbci,
  62. const unsigned char *string,
  63. const unsigned char *current
  64. )
  65. {
  66. #endif
  67. #ifdef _MT
  68. if ( _ISNOTMBCP_MT(ptmbci) )
  69. #else
  70. if ( _ISNOTMBCP )
  71. #endif
  72. return 0;
  73. while (string <= current && *string) {
  74. #ifdef _MT
  75. if ( __ismbblead_mt(ptmbci, (*string)) ) {
  76. #else
  77. if ( _ismbblead((*string)) ) {
  78. #endif
  79. if (string++ == current) /* check lead byte */
  80. return -1;
  81. if (!(*string))
  82. return 0;
  83. }
  84. ++string;
  85. }
  86. return 0;
  87. }
  88. #endif