ReactOS 0.4.16-dev-732-g2d1144a
GetStringTypeA.cpp
Go to the documentation of this file.
1/***
2*a_str.c - A version of GetStringType.
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Use either GetStringTypeA or GetStringTypeW depending on which is
8* unstubbed.
9*
10*******************************************************************************/
11
12#include <corecrt_internal.h>
13#include <locale.h>
14
15/***
16*int __cdecl __acrt_GetStringTypeA - Get type information about an ANSI string.
17*
18*Purpose:
19* Internal support function. Assumes info in ANSI string format. Tries
20* to use NLS API call GetStringTypeA if available and uses GetStringTypeW
21* if it must. If neither are available it fails and returns FALSE.
22*
23*Entry:
24* DWORD dwInfoType - see NT\Chicago docs
25* PCCH lpSrcStr - char (byte) string for which character types
26* are requested
27* int cchSrc - char (byte) count of lpSrcStr (including nullptr
28* if any)
29* LPWORD lpCharType - word array to receive character type information
30* (must be twice the size of lpSrcStr)
31* int code_page - for MB/WC conversion. If 0, use __lc_codepage
32* BOOL bError - TRUE if MB_ERR_INVALID_CHARS set on call to
33* MultiByteToWideChar when GetStringTypeW used.
34*
35*Exit:
36* Success: TRUE
37* Failure: FALSE
38*
39*Exceptions:
40*
41*******************************************************************************/
42
44 _locale_t const locale,
45 DWORD const info_type,
46 LPCSTR const string,
47 int const string_size_in_bytes,
48 unsigned short* const char_type,
49 int const code_page,
50 BOOL const error
51 )
52{
53 _LocaleUpdate locale_update(locale);
54
55 // Convert string and return the requested information. Note that
56 // we are converting to a wide character string so there is not a
57 // one-to-one correspondence between number of multibyte chars in the
58 // input string and the number of wide chars in the buffer. However,
59 // there had *better be* a one-to-one correspondence between the
60 // number of multibyte characters and the number of WORDs in the
61 // return buffer.
62
63 // Use __lc_codepage for conversion if code_page not specified:
64 int const actual_code_page = code_page != 0
65 ? code_page
66 : locale_update.GetLocaleT()->locinfo->_public._locale_lc_codepage;
67
68 // Find out how big a buffer we need:
69 int const required_extent = __acrt_MultiByteToWideChar(
70 actual_code_page,
72 string,
73 string_size_in_bytes,
74 nullptr,
75 0);
76
77 if (required_extent == 0)
78 return FALSE;
79
80 // Allocate enough space for the wide character string:
81 __crt_scoped_stack_ptr<wchar_t> buffer(_malloca_crt_t(wchar_t, required_extent));
82 if (buffer.get() == nullptr)
83 return FALSE;
84
85 memset(buffer.get(), 0, sizeof(wchar_t) * required_extent);
86
87 // Do the conversion:
88 int const actual_extent = __acrt_MultiByteToWideChar(
89 actual_code_page,
91 string,
92 string_size_in_bytes,
93 buffer.get(),
94 required_extent);
95
96 if (actual_extent == 0)
97 return FALSE;
98
99 return GetStringTypeW(info_type, buffer.get(), actual_extent, char_type);
100}
BOOL __cdecl __acrt_GetStringTypeA(_locale_t const locale, DWORD const info_type, LPCSTR const string, int const string_size_in_bytes, unsigned short *const char_type, int const code_page, BOOL const error)
#define __cdecl
Definition: accygwin.h:79
Definition: _locale.h:75
_Out_opt_ UINT * code_page
#define FALSE
Definition: types.h:117
BOOL WINAPI GetStringTypeW(DWORD type, LPCWSTR src, INT count, LPWORD chartype)
Definition: locale.c:3095
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
#define MB_ERR_INVALID_CHARS
Definition: unicode.h:41
#define error(str)
Definition: mkdosfs.c:1605
#define memset(x, y, z)
Definition: compat.h:39
#define MB_PRECOMPOSED
Definition: winnls.h:283
const char * LPCSTR
Definition: xmlstorage.h:183