Reactos
at master 64 lines 1.8 kB view raw
1// 2// ismbstr.cpp 3// 4// Copyright (c) Microsoft Corporation. All rights reserved. 5// 6// Defines _ismbstrail, which is the context-sensitive MBCS trail-byte function. 7// While much less efficient than _ismbbtrail, it is also much more sophisticated. 8// It determines whether a given sub-string pointer points to a trail byte or not, 9// taking into account the context of the string. 10// 11// These functions return -1 if the pointer points to a trail byte; 0 if it does 12// not. 13// 14// These functions are intended for use with single/double byte character sets (DBCS) 15// and are meaningless for UTF-8 which has more than just a lead/trail byte pair. 16// for UTF-8 these functions always return FALSE. 17// 18#ifndef _MBCS 19 #error This file should only be compiled with _MBCS defined 20#endif 21 22#define _ALLOW_OLD_VALIDATE_MACROS 23#include <corecrt_internal_mbstring.h> 24#include <locale.h> 25 26 27 28extern "C" int __cdecl _ismbstrail_l( 29 unsigned char const* string, 30 unsigned char const* current, 31 _locale_t const locale 32 ) 33{ 34 _VALIDATE_RETURN(string != nullptr, EINVAL, 0); 35 _VALIDATE_RETURN(current != nullptr, EINVAL, 0); 36 37 _LocaleUpdate locale_update(locale); 38 39 if (locale_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) 40 return 0; 41 42 while (string <= current && *string) 43 { 44 if (_ismbblead_l((*string), locale_update.GetLocaleT())) 45 { 46 if (++string == current) // check trail byte 47 return -1; 48 49 if (*string == 0) 50 return 0; 51 } 52 ++string; 53 } 54 55 return 0; 56} 57 58extern "C" int __cdecl _ismbstrail( 59 unsigned char const* const string, 60 unsigned char const* const current 61 ) 62{ 63 return _ismbstrail_l(string, current, nullptr); 64}