[ Web Proxy ]
URL:
Viewing: https://fr.cppreference.com/cpp/string/multibyte/mbrlen [Back]  [Original]

std::mbrlen cppreference.com
cppreference.com
Espaces de noms
Variantes

std::mbrlen

De cppreference.com

<metanoindex/>

 
 
Bibliothque de chanes de caractres
Chanes zro terminal
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.
Les chanes d'octets
Chaines multi-octets
Les chanes tendues
Classes
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
 
Chanes zro terminal multi-octets
Large / multi-octets conversions
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
Types
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
 
<tbody> </tbody>
Dclar dans l'en-tte <cwchar>
std::size_t mbrlen( const char* s, std::size_t n, std::mbstate_t* ps);
Dtermine la taille, en octets, du reste le caractre multi-octets dont le premier octet est point par s, tant donn l'tat actuel de conversion ps .
Original:
Determines the size, in bytes, of the remainder of the multibyte character whose first byte is pointed to by s, given the current conversion state ps.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cette fonction est quivalente la std::mbrtowc(nullptr, s, n, ps?ps:&internal) appel pour internal objets cachs std::mbstate_t type, sauf que le ps expression est value une seule fois .
Original:
This function is equivalent to the call std::mbrtowc(nullptr, s, n, ps?ps:&internal) for some hidden object internal of type std::mbstate_t, except that the expression ps is evaluated only once.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Paramtres

s -
pointeur sur un lment d'une chane de caractres multi-octets
Original:
pointer to an element of a multibyte character string
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
n -
limiter le nombre d'octets dans s qui peut tre examin
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.
ps -
pointeur vers la variable contenant l'tat de conversion
Original:
pointer to the variable holding the conversion state
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Retourne la valeur

0 si le n suivante ou moins d'octets complter le caractre nul .
Original:
0 if the next n or fewer bytes complete the null character.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Le nombre d'octets (entre 1 et n) qui compltent un caractre multi-octets valide
Original:
The number of bytes (between 1 and n) that complete a valid multibyte character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(size_t)-1 si erreur de codage survient
Original:
(size_t)-1 if encoding error occurs
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(size_t)-2 si les octets n prochaines font partie d'un caractre multi-octets peut-tre valable, ce qui est encore incomplte aprs avoir examin tous les octets n
Original:
(size_t)-2 if the next n bytes are part of a possibly valid multibyte character, which is still incomplete after examining all n bytes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Exemple

#include <clocale>
#include <string>
#include <iostream>
#include <cwchar>

int main()
{
    // allow mbrlen() to work with UTF-8 multibyte encoding
    std::setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    std::string str = u8""; // or u8"\u6c34" or "\xe6\xb0\xb4"
    std::mbstate_t mb = std::mbstate_t();
    int len1 = std::mbrlen(&str[0], 1, &mb);
    if(len1 == -2) {
        std::cout << "The first 1 byte of " << str
                  << " is an incomplete multibyte char (mbrlen returns -2)\n";
    }
    int len2 = std::mbrlen(&str[1], str.size()-1, &mb);
    std::cout << "The remaining " << str.size()-1 << " bytes of " << str
              << " hold " << len2 << " bytes of the multibyte character\n";
    std::cout << "Attempting to call mbrlen() in the middle of " << str
              << " while in initial shift state returns "
              << (int)mbrlen(&str[1], str.size(), &mb) << '\n';

}

Rsultat :

The first 1 byte of  is an incomplete multibyte char (mbrlen returns -2)
The remaining 2 bytes of  hold 2 bytes of the multibyte character
Attempting to call mbrlen() in the middle of  while in initial shift state returns -1

Voir aussi

convertit le caractre multi-octets suivante caractre large, tat donn
Original:
converts the next multibyte character to wide 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.

(fonction) [edit]
renvoie le nombre d'octets dans le prochain caractre multi-octets
Original:
returns the number of bytes in the next multibyte character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction) [edit]
[
virtuel
Original:
virtual
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
]
calcule la longueur de la chane Externt qui serait consomme par conversion en tampon Internt propose
Original:
calculates the length of the externT string that would be consumed by conversion into given internT buffer
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre virtuelle protge de std::codecvt) [edit]
C documentation for mbrlen

Web Proxy Viewer  |  New URL  |  Original Page