glibmm 2.80.0
Public Member Functions | List of all members
Glib::IConv Class Reference

Thin iconv() wrapper. More...

#include <glibmm/convert.h>

Public Member Functions

 IConv (const std::string & to_codeset, const std::string & from_codeset)
 Open new conversion descriptor. More...
 
 IConv (const IConv &)=delete
 
IConvoperator= (const IConv &)=delete
 
 IConv (GIConv gobject)
 
 ~IConv ()
 Close conversion descriptor. More...
 
std::size_t iconv (char ** inbuf, gsize * inbytes_left, char ** outbuf, gsize * outbytes_left)
 Same as the standard UNIX routine iconv(), but may be implemented via libiconv on UNIX flavors that lack a native implementation. More...
 
void reset ()
 Reset conversion descriptor to initial state. More...
 
std::string convert (const std::string & str)
 Convert from one encoding to another. More...
 
GIConv gobj ()
 

Detailed Description

Thin iconv() wrapper.

glibmm provides Glib::convert() and Glib::locale_to_utf8() which are likely more convenient than the raw iconv wrappers. However, creating an IConv object once and using the convert() method could be useful when converting multiple times between the same charsets.

Constructor & Destructor Documentation

◆ IConv() [1/3]

Glib::IConv::IConv ( const std::string to_codeset,
const std::string from_codeset 
)

Open new conversion descriptor.

Parameters
to_codesetDestination codeset.
from_codesetSource codeset.
Exceptions
Glib::ConvertError

◆ IConv() [2/3]

Glib::IConv::IConv ( const IConv )
delete

◆ IConv() [3/3]

Glib::IConv::IConv ( GIConv  gobject)
explicit

◆ ~IConv()

Glib::IConv::~IConv ( )

Close conversion descriptor.

Member Function Documentation

◆ convert()

std::string Glib::IConv::convert ( const std::string str)

Convert from one encoding to another.

Parameters
strThe string to convert.
Returns
The converted string.
Exceptions
Glib::ConvertError

◆ gobj()

GIConv Glib::IConv::gobj ( )
inline

◆ iconv()

std::size_t Glib::IConv::iconv ( char **  inbuf,
gsize *  inbytes_left,
char **  outbuf,
gsize *  outbytes_left 
)

Same as the standard UNIX routine iconv(), but may be implemented via libiconv on UNIX flavors that lack a native implementation.

glibmm provides Glib::convert() and Glib::locale_to_utf8() which are likely more convenient than the raw iconv wrappers.

Parameters
inbufBytes to convert.
inbytes_leftIn/out parameter, bytes remaining to convert in inbuf.
outbufConverted output bytes.
outbytes_leftIn/out parameter, bytes available to fill in outbuf.
Returns
Count of non-reversible conversions, or static_cast<std::size_t>(-1) on error.

◆ operator=()

IConv & Glib::IConv::operator= ( const IConv )
delete

◆ reset()

void Glib::IConv::reset ( )

Reset conversion descriptor to initial state.

Same as iconv(0, 0, 0, 0), but implemented slightly differently in order to work on Sun Solaris <= 7. It's also more obvious so you're encouraged to use it.