Espacios de nombres
Variantes
Acciones

std::mblen

De cppreference.com
< cpp‎ | string‎ | multibyte
 
 
 
Cadenas multibyte terminadas en nulo
Ancho / multibyte conversiones
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.
Tipos
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Definido en el archivo de encabezado <cstdlib>
int mblen(constchar* s, std::size_t n );
Determina el tamaño, en bytes, del carácter multibyte cuyo primer byte es apuntado por 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.
Si s es un puntero nulo, se restablece el estado de conversión global y determinar si las secuencias de desplazamiento se utilizan .
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.
Esta función es equivalente a la std::mbtowc((wchar_t*)0, s, n) llamada, salvo que el estado de conversión de std::mbtowc no se ve afectada .
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.

Contenido

[editar]Notas

Cada llamada a las actualizaciones de estado interno mblen la conversión global (un objeto estático de std::mbstate_t tipo, sólo se sabe que esta función). Si la codificación multibyte utiliza estados de cambio, se debe tener cuidado para evitar las exploraciones de rastreo o múltiples. En cualquier caso, varios subprocesos no debe llamar mblen sin sincronización: std::mbrlen lugar se puede utilizar .
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.

[editar]Parámetros

s -
puntero al carácter 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 -
limitar el número de bytes en s que puede ser examinado
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.

[editar]Valor de retorno

Si s no es un puntero nulo, devuelve el número de bytes que se contienen en el carácter multibyte o -1 si los primeros bytes que apunta s no forman un carácter multibyte válida o si 0s está apuntando a la charcter nulo '\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.
Si s es un puntero nulo, restablece su estado de conversión interna para representar el estado inicial de cambios y devoluciones si 0 la codificación multibyte actual no es dependiente del estado (no utiliza secuencias de turnos) o un valor distinto de cero si la codificación multibyte actual es dependiente del estado (utiliza secuencias de turnos) .
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.

[editar]Ejemplo

#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";}

Salida:

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

[editar]Ver también

Convierte el carácter multibyte siguiente a un carácter ancho.
(función)[editar]
devuelve el número de bytes en el siguiente carácter multibyte, estado dado
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.

(función)[editar]
close