ReactOS 0.4.16-dev-1097-g530d26a
mbsbtype.cpp
Go to the documentation of this file.
1/***
2*mbsbtype.c - Return type of byte within a string (MBCS)
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Return type of byte within a string (MBCS)
8*
9*******************************************************************************/
10#ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12#endif
13
15#include <locale.h>
16
17#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018
18
19/***
20* _mbsbtype - Return type of byte within a string
21*
22*Purpose:
23* Test byte within a string for MBCS char type.
24* This function requires the start of the string because
25* context must be taken into account.
26*
27*Entry:
28* const unsigned char *string = pointer to string
29* size_t len = position of the char in string
30*
31*Exit:
32* returns one of the following values:
33*
34* _MBC_LEAD = if 1st byte of MBCS char
35* _MBC_TRAIL = if 2nd byte of MBCS char
36* _MBC_SINGLE = valid single byte char
37*
38* _MBC_ILLEGAL = if illegal char
39*
40*WARNING:
41* This function was intended for SBCS/DBCS code pages. UTF-8 will always return _MBC_SINGLE
42* It is recommended that apps do not try to reverse engineer how encodings work.
43*
44*Exceptions:
45* Returns _MBC_ILLEGAL if char is invalid.
46* Calls invalid parameter if len is bigger than string length (and errno is set to EINVAL).
47* Input parameters are validated. Refer to the validation section of the function.
48*
49*******************************************************************************/
50
51extern "C" int __cdecl _mbsbtype_l(unsigned char const* string, size_t length, _locale_t const locale)
52{
53 _VALIDATE_RETURN(string != nullptr, EINVAL, _MBC_ILLEGAL);
54
55 _LocaleUpdate locale_update(locale);
56
57 if (locale_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
58 return _MBC_SINGLE;
59
60 int chartype = _MBC_ILLEGAL;
61
62 do
63 {
64 /* If the char at the position asked for is a '\0' we return
65 _MBC_ILLEGAL. But, If any char before the position asked for is
66 a '\0', then we call invalid_param */
67
68 if (length == 0 && *string == '\0')
69 return _MBC_ILLEGAL;
70
71 _VALIDATE_RETURN(*string != '\0', EINVAL, _MBC_ILLEGAL);
72
73 chartype = _mbbtype_l(*string++, chartype, locale_update.GetLocaleT());
74 } while (length--);
75
76 return chartype;
77}
78
79int __cdecl _mbsbtype(unsigned char const* const string, size_t const length)
80{
81 return _mbsbtype_l(string, length, nullptr);
82}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
Definition: _locale.h:75
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
_Check_return_ _CRTIMP int __cdecl _mbbtype_l(_In_ unsigned char _Ch, _In_ int _CType, _In_opt_ _locale_t _Locale)
int __cdecl _mbsbtype(unsigned char const *const string, size_t const length)
Definition: mbsbtype.cpp:79
int __cdecl _mbsbtype_l(unsigned char const *string, size_t length, _locale_t const locale)
Definition: mbsbtype.cpp:51
#define _MBC_SINGLE
Definition: msvcrt.h:823
#define _MBC_ILLEGAL
Definition: msvcrt.h:826