Namespaces
Variants

mbsinit

From cppreference.net
Défini dans l'en-tête <wchar.h>
int mbsinit ( const mbstate_t * ps ) ;
(depuis C95)

Si ps n'est pas un pointeur nul, la fonction mbsinit détermine si l'objet pointé de type mbstate_t décrit l'état de conversion initial.

Table des matières

Notes

Bien qu'un mbstate_t initialisé à zéro représente toujours l'état de conversion initial, il peut exister d'autres valeurs de mbstate_t qui représentent également l'état de conversion initial.

Paramètres

ps - pointeur vers l'objet mbstate_t à examiner

Valeur de retour

0 si ps n'est pas un pointeur nul et ne représente pas l'état de conversion initial, valeur non nulle sinon.

Exemple

#include <locale.h>
#include <string.h>
#include <stdio.h>
#include <wchar.h>
int main(void)
{
    // allow mbrlen() to work with UTF-8 multibyte encoding
    setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    const char* str = u8"水"; // or u8"\u6c34" or "\xe6\xb0\xb4"
    static mbstate_t mb; // zero-initialize
    (void)mbrlen(&str[0], 1, &mb);
    if (!mbsinit(&mb)) {
        printf("After processing the first 1 byte of %s,\n"
               "the conversion state is not initial\n\n", str);
    }
    (void)mbrlen(&str[1], strlen(str), &mb);
    if (mbsinit(&mb)) {
        printf("After processing the remaining 2 bytes of %s,\n"
               "the conversion state is initial conversion state\n", str);
    }
}

Sortie :

After processing the first 1 byte of 水,
the conversion state is not initial
After processing the remaining 2 bytes of 水,
the conversion state is initial conversion state

Références

  • Norme C17 (ISO/CEI 9899:2018) :
  • 7.29.6.2.1 La fonction mbsinit (p: 322)
  • Norme C11 (ISO/IEC 9899:2011) :
  • 7.29.6.2.1 La fonction mbsinit (p: 441-442)
  • Norme C99 (ISO/CEI 9899:1999) :
  • 7.24.6.2.1 La fonction mbsinit (p : 387-388)

Voir aussi

informations d'état de conversion nécessaires pour itérer sur les chaînes de caractères multioctets
(classe)
Documentation C++ pour mbsinit