1 /*** 2 *ismbslead.c - True _ismbslead function 3 * 4 * Copyright (c) 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 #ifndef _MBCS 15 #error This file should only be compiled with _MBCS defined 16 #endif 17 18 #include <corecrt_internal_mbstring.h> 19 #include <locale.h> 20 21 22 /*** 23 * int _ismbslead(const unsigned char *string, const unsigned char *current); 24 * 25 *Purpose: 26 * 27 * _ismbslead - Check, in context, for MBCS lead byte 28 * 29 *Entry: 30 * unsigned char *string - ptr to start of string or previous known lead byte 31 * unsigned char *current - ptr to position in string to be tested 32 * 33 *Exit: 34 * TRUE : -1 35 * FALSE : 0 36 * 37 *Exceptions: 38 * Input parameters are validated. Refer to the validation section of the function. 39 * 40 *******************************************************************************/ 41 42 extern "C" int __cdecl _ismbslead_l( 43 const unsigned char *string, 44 const unsigned char *current, 45 _locale_t plocinfo 46 ) 47 { 48 /* validation section */ 49 _VALIDATE_RETURN(string != nullptr, EINVAL, 0); 50 _VALIDATE_RETURN(current != nullptr, EINVAL, 0); 51 52 _LocaleUpdate _loc_update(plocinfo); 53 54 if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) 55 return 0; 56 57 while (string <= current && *string) { 58 if ( _ismbblead_l((*string), _loc_update.GetLocaleT()) ) { 59 if (string++ == current) /* check lead byte */ 60 return -1; 61 if (!(*string)) 62 return 0; 63 } 64 ++string; 65 } 66 67 return 0; 68 } 69 70 extern "C" int (__cdecl _ismbslead)( 71 const unsigned char *string, 72 const unsigned char *current 73 ) 74 { 75 return _ismbslead_l(string, current, nullptr); 76 } 77