ReactOS 0.4.16-dev-959-g2ec3a19
mblen.cpp File Reference
Include dependency graph for mblen.cpp:

Go to the source code of this file.

Functions

static int __cdecl _mblen_internal (char const *const string, size_t const max_count, __crt_cached_ptd_host &ptd)
 
int __cdecl _mblen_l (char const *const string, size_t const max_count, _locale_t const locale)
 
int __cdecl mblen (char const *const string, size_t const max_count)
 

Function Documentation

◆ _mblen_internal()

static int __cdecl _mblen_internal ( char const *const  string,
size_t const  max_count,
__crt_cached_ptd_host &  ptd 
)
static

Definition at line 19 of file mblen.cpp.

24{
26 if (!string || *string == '\0' || max_count == 0)
27 {
28 internal_state = {};
29 return 0;
30 }
31
32 _locale_t const locale = ptd.get_locale();
33
34 if (locale->locinfo->_public._locale_lc_codepage == CP_UTF8)
35 {
36 int result = static_cast<int>(__mbrtowc_utf8(nullptr, string, max_count, &internal_state, ptd));
37 if (result < 0)
38 {
39 result = -1;
40 }
41 return result;
42 }
43
45 locale->locinfo->_public._locale_mb_cur_max == 1 ||
46 locale->locinfo->_public._locale_mb_cur_max == 2);
47
48 if (_isleadbyte_fast_internal(static_cast<unsigned char>(*string), locale))
49 {
50 _ASSERTE(locale->locinfo->_public._locale_lc_codepage != CP_UTF8 && L"UTF-8 isn't supported in this _mblen_l function yet!!!");
51
52 // If this is a lead byte, then the codepage better be a multibyte codepage
53 _ASSERTE(locale->locinfo->_public._locale_mb_cur_max > 1);
54
55 // Multi-byte character; verify that it is valid:
56 if (locale->locinfo->_public._locale_mb_cur_max <= 1)
57 {
58 return -1;
59 }
60
61 if (max_count > INT_MAX || static_cast<int>(max_count) < locale->locinfo->_public._locale_mb_cur_max)
62 {
63 return -1;
64 }
65
66 int const status = __acrt_MultiByteToWideChar(
67 locale->locinfo->_public._locale_lc_codepage,
69 string,
70 locale->locinfo->_public._locale_mb_cur_max,
71 nullptr,
72 0);
73
74 if (status == 0)
75 {
76 return -1;
77 }
78
79 return locale->locinfo->_public._locale_mb_cur_max;
80 }
81 else
82 {
83 // Single byte character; verify that it is valid:
84 // CP_ACP is known to be valid for all values
85 if (locale->locinfo->_public._locale_lc_codepage != CP_ACP)
86 {
87 int const status = __acrt_MultiByteToWideChar(
88 locale->locinfo->_public._locale_lc_codepage,
90 string,
91 1,
92 nullptr,
93 0);
94
95 if (status == 0)
96 {
97 return -1;
98 }
99 }
100
101 return sizeof(char);
102 }
103}
Definition: _locale.h:75
_Check_return_ __forceinline unsigned short __cdecl _isleadbyte_fast_internal(_In_ unsigned char const c, _In_ _locale_t const locale)
#define _ASSERTE(expr)
Definition: crtdbg.h:114
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
Definition: cvt.cpp:355
#define CP_ACP
Definition: compat.h:109
unsigned char
Definition: typeof.h:29
Character const *const size_t const max_count
Definition: fullpath.cpp:66
GLuint64EXT * result
Definition: glext.h:11304
#define MB_ERR_INVALID_CHARS
Definition: unicode.h:41
#define INT_MAX
Definition: intsafe.h:150
size_t __cdecl __mbrtowc_utf8(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps, __crt_cached_ptd_host &ptd)
#define L(x)
Definition: ntvdm.h:50
#define CP_UTF8
Definition: nls.h:20
Definition: ps.c:97
#define MB_PRECOMPOSED
Definition: winnls.h:283

Referenced by _mblen_l(), and mblen().

◆ _mblen_l()

int __cdecl _mblen_l ( char const *const  string,
size_t const  max_count,
_locale_t const  locale 
)

Definition at line 105 of file mblen.cpp.

110{
111 __crt_cached_ptd_host ptd(locale);
112 return _mblen_internal(string, max_count, ptd);
113}
static int __cdecl _mblen_internal(char const *const string, size_t const max_count, __crt_cached_ptd_host &ptd)
Definition: mblen.cpp:19

◆ mblen()

int __cdecl mblen ( char const *const  string,
size_t const  max_count 
)

Definition at line 117 of file mblen.cpp.

121{
122 __crt_cached_ptd_host ptd;
123 return _mblen_internal(string, max_count, ptd);
124}