Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::mbsinit(3)		      C++ Standard Libary	       std::mbsinit(3)

NAME
       std::mbsinit - std::mbsinit

Synopsis
	  Defined in header <cwchar>
	  int mbsinit( const std::mbstate_t* ps);

	  If ps	is not a null pointer, the mbsinit function determines whether
       the pointed-to
	  std::mbstate_t object	describes the initial conversion state.

Notes
	  Although  a  zero-initialized	 std::mbstate_t	 always	represents the
       initial conversion
	  state, there may be other values of std::mbstate_t that also	repre-
       sent the	initial
	  conversion state.

Parameters
	  ps - pointer to the std::mbstate_t object to examine

Return value
	  0  if	 ps  is	 not a null pointer and	does not represent the initial
       conversion
	  state, nonzero value otherwise.

Example
       // Run this code

	#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 = ""; // or	u8"\u6c34" or "\xe6\xb0\xb4"
	    std::mbstate_t mb =	std::mbstate_t();
	    (void)std::mbrlen(&str[0], 1, &mb);
	    if (!std::mbsinit(&mb)) {
		std::cout << "After processing the first 1 byte	of " <<	str
			  << " the conversion state is not initial\n";
	    }

	    (void)std::mbrlen(&str[1], str.size()-1, &mb);
	    if (std::mbsinit(&mb)) {
		std::cout << "After processing the remaining 2 bytes of	 "  <<
       str
			  <<  ",  the  conversion  state is initial conversion
       state\n";
	    }
	}

Output:
	After processing the first 1 byte of  the conversion state is not ini-
       tial
	After processing the remaining 2 bytes of , the	 conversion  state  is
       initial conversion state

See also
		    conversion	state  information necessary to	iterate	multi-
       byte character
	  mbstate_t strings
		    (class)

http://cppreference.com		  2022.07.31		       std::mbsinit(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::mbsinit&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help