std::mblen

Da cppreference.com.
< cpp‎ | string‎ | multibyte

 
 
Stringhe libreria
Null-stringhe terminate
Original:
Null-terminated strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Byte stringhe
Multibyte stringhe
Stringhe larghe
Classi
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string
char_traits
 
Stringhe multibyte null-terminated
Wide / multibyte conversioni
Original:
Wide/multibyte conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mbsinit
Tipi
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mbstate_t
 
Elemento definito nell'header <cstdlib>
int mblen(constchar* s, std::size_t n );
Determina la dimensione, in byte, del carattere multibyte il cui primo byte è puntato da s.
Original:
Determines the size, in bytes, of the multibyte character whose first byte is pointed to by s.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Se s è un puntatore nullo, ripristina lo stato di conversione globale e stabilire se le sequenze di spostamento vengono utilizzati.
Original:
If s is a null pointer, resets the global conversion state and determined whether shift sequences are used.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Questa funzione è equivalente alla std::mbtowc((wchar_t*)0, s, n) chiamata, tranne quello stato di conversione std::mbtowc è inalterato.
Original:
This function is equivalent to the call std::mbtowc((wchar_t*)0, s, n), except that conversion state of std::mbtowc is unaffected.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Indice

[modifica]Note

Ogni chiamata agli aggiornamenti mblen lo stato interno di conversione globale (un oggetto statico di std::mbstate_t tipo, noto solo a questa funzione). Se la codifica multibyte utilizza gli stati di spostamento, è necessario prestare attenzione al fine di evitare scansioni backtracking o multipli. In ogni caso, più thread non dovrebbe chiamare mblen senza sincronizzazione: std::mbrlen può essere utilizzato.
Original:
Each call to mblen updates the internal global conversion state (a static object of type std::mbstate_t, only known to this function). If the multibyte encoding uses shift states, care must be taken to avoid backtracking or multiple scans. In any case, multiple threads should not call mblen without synchronization: std::mbrlen may be used instead.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifica]Parametri

s -
puntatore al carattere multibyte
Original:
pointer to the multibyte character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
n -
limitare il numero di byte in s che può essere esaminato
Original:
limit on the number of bytes in s that can be examined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifica]Valore di ritorno

Se s non è un puntatore nullo, restituisce il numero di byte che sono contenute nel carattere multibyte o -1 se i primi byte puntato da s non costituiscono un carattere valido multibyte o 0s se è puntato verso il nulla charcter '\0'.
Original:
If s is not a null pointer, returns the number of bytes that are contained in the multibyte character or -1 if the first bytes pointed to by s do not form a valid multibyte character or 0 if s is pointing at the null charcter '\0'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Se s è un puntatore nullo, consente di ripristinare il suo stato conversione interna per rappresentare lo stato iniziale del cambio e 0 restituisce se la codifica multibyte corrente non è dipendente dallo stato (non utilizza sequenze di trasferimento) o un valore diverso da zero se la codifica multibyte corrente è dipendente dallo stato (utilizza sequenze di trasferimento).
Original:
If s is a null pointer, resets its internal conversion state to represent the initial shift state and returns 0 if the current multibyte encoding is not state-dependent (does not use shift sequences) or a non-zero value if the current multibyte encoding is state-dependent (uses shift sequences).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifica]Esempio

#include <clocale>#include <string>#include <iostream>#include <cstdlib>#include <stdexcept>   // the number of characters in a multibyte string is the sum of mblen()'s// note: the simpler approach is std::mbstowcs(NULL, s.c_str(), s.size())std::size_t strlen_mb(conststd::string& s){std::size_t result =0;constchar* ptr =&s[0];constchar* end = ptr + s.size(); std::mblen(NULL, 0);// reset the conversion statewhile(ptr < end){int next = std::mblen(ptr, end-ptr);if(next ==-1){throwstd::runtime_error("strlen_mb(): conversion error");} ptr += next;++result;}return result;}   int main(){// allow mblen() to work with UTF-8 multibyte encodingstd::setlocale(LC_ALL, "en_US.utf8");// UTF-8 narrow multibyte encodingstd::string str = u8"z\u00df\u6c34\U0001d10b";// or u8"zß水𝄋"// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";std::cout<< str <<" is "<< str.size()<<" bytes, but only "<< strlen_mb(str)<<" characters\n";}

Output:

zß水𝄋 is 10 bytes, but only 4 characters

[modifica]Vedi anche

converte il carattere successivo multibyte a carattere esteso
Original:
converts the next multibyte character to wide character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(funzione)[modifica]
restituisce il numero di byte nel carattere multibyte successivo, determinato stato
Original:
returns the number of bytes in the next multibyte character, given state
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(funzione)[modifica]
C documentation for mblen
close