std::mbsrtowcs
De cppreference.com
<metanoindex/>
<tbody> </tbody>| Definido no cabeçalho <cwchar>
|
||
std::size_t mbsrtowcs( wchar_t* dst, const char** src, std::size_t len, std::mbstate_t* ps ); |
||
Converte uma terminação nula sequência de caracteres multibyte, que começa no estado de conversão descrito por
*ps, a partir da matriz cujo primeiro elemento é apontado por *src à sua representação de caracteres de largura. Se dst não é nulo, os caracteres convertidos são armazenados nos elementos sucessivos da matriz wchar_t apontado por dst. Não mais do que len caracteres largos são escritos para a matriz destino.Original:
Converts a null-terminated multibyte character sequence, which begins in the conversion state described by
*ps, from the array whose first element is pointed to by *src to its wide character representation. If dst is not null, converted characters are stored in the successive elements of the wchar_t array pointed to by dst. No more than len wide characters are written to the destination array.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Cada personagem multibyte é convertido como se por uma chamada para std::mbrtowc. A conversão pára se:
Original:
Each multibyte character is converted as if by a call to std::mbrtowc. The conversion stops if:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- O caractere nulo multibyte foi convertido e armazenado.
srcestá definido para NULL e*psrepresenta o estado deslocamento inicial.Original:The multibyte null character was converted and stored.srcis set to NULL and*psrepresents the initial shift state.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Um personagem multibyte inválido (de acordo com o atual C locale) foi encontrado.
srcestá definido para apontar para o início do primeiro caractere multibyte não convertido.Original:An invalid multibyte character (according to the current C locale) was encountered.srcis set to point at the beginning of the first unconverted multibyte character.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - o próximo caractere de largura para ser armazenado exceder
len.srcé ajustado para apontar para o início do primeiro caractere multibyte não convertido. Esta condição não é verificado sedst==NULL.Original:the next wide character to be stored would exceedlen.srcis set to point at the beginning of the first unconverted multibyte character. This condition is not checked ifdst==NULL.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Parâmetros
| dst | - | ponteiro para matriz de caracteres de largura, onde os resultados serão armazenados
Original: pointer to wide character array where the results will be stored The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| src | - | ponteiro para ponteiro para o primeiro elemento de uma seqüência multibyte terminada em null
Original: pointer to pointer to the first element of a null-terminated multibyte string The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| len | - | número de caracteres largos disponíveis na matriz apontada por dst
Original: number of wide characters available in the array pointed to by dst The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| ps | - | ponteiro para o objeto de estado de conversão
Original: pointer to the conversion state object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Valor de retorno
Em caso de sucesso, retorna o número de caracteres de largura, excluindo o
L'\0' terminação, escrito para a matriz de caracteres.. Se dst==NULL, retorna o número de caracteres de largura que teria sido escrito dado comprimento ilimitado.Original:
On success, returns the number of wide characters, excluding the terminating
L'\0', written to the character array.. If dst==NULL, returns the number of wide characters that would have been written given unlimited length.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Em caso de erro de conversão (se caracteres multibyte inválido foi encontrado), retorna
static_cast<std::size_t>(-1), lojas EILSEQ em errno e deixa *ps em estado indeterminado.Original:
On conversion error (if invalid multibyte character was encountered), returns
static_cast<std::size_t>(-1), stores EILSEQ in errno, and leaves *ps in unspecified state.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Exemplo
#include <iostream>
#include <vector>
#include <clocale>
#include <cwchar>
void print_as_wide(const char* mbstr)
{
std::mbstate_t state = std::mbstate_t();
int len = 1 + std::mbsrtowcs(NULL, &mbstr, 0, &state);
std::vector<wchar_t> wstr(len);
std::mbsrtowcs(&wstr[0], &mbstr, wstr.size(), &state);
std::wcout << "Wide string: " << &wstr[0] << '\n'
<< "The length, including '\\0': " << wstr.size() << '\n';
}
int main()
{
std::setlocale(LC_ALL, "en_US.utf8");
const char* mbstr = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋"
// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
print_as_wide(mbstr);
}
Saída:
Wide string: zß水𝄋
The length, including '\0': 5
