aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
cast_unicode.h File Reference

Unicode helper functions. More...

#include <iostream>
#include <locale>
#include <sstream>
#include <string>
#include <agrum/base/core/cast_unicode_inl.h>
Include dependency graph for cast_unicode.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::wstring widen (const std::string &str)
 Cast a std::string into a std::wstring.
std::string narrow (const std::wstring &str)
 Cast a std::wstring into a std::string.

Detailed Description

Unicode helper functions.

Author
Christophe GONZALES(_at_AMU) and Pierre-Henri WUILLEMIN(_at_LIP6)

Definition in file cast_unicode.h.

Function Documentation

◆ narrow()

std::string narrow ( const std::wstring & str)

Cast a std::wstring into a std::string.

Parameters
strThe std::wstring to cast.
Returns
Returns the std::string of str.

Definition at line 71 of file cast_unicode_inl.h.

71 {
72 std::ostringstream stm;
73 const std::ctype< char >& ctfacet = std::use_facet< std::ctype< char > >(stm.getloc());
74
75 for (std::size_t i = 0; i < str.size(); ++i) {
76 stm << ctfacet.narrow(str[i], 0);
77 }
78
79 return stm.str();
80}

Referenced by gum::ErrorsContainer::Error(), gum::ErrorsContainer::Exception(), and gum::ErrorsContainer::Warning().

Here is the caller graph for this function:

◆ widen()

std::wstring widen ( const std::string & str)

Cast a std::string into a std::wstring.

Parameters
strThe std::string to cast.
Returns
Returns the std::wstring of str.

Definition at line 60 of file cast_unicode_inl.h.

60 {
61 std::wostringstream wstm;
62 const std::ctype< wchar_t >& ctfacet = std::use_facet< std::ctype< wchar_t > >(wstm.getloc());
63
64 for (size_t i = 0; i < str.size(); ++i) {
65 wstm << ctfacet.widen(str[i]);
66 }
67
68 return wstm.str();
69}

Referenced by gum::prm::o3prm::O3prmReader< GUM_SCALAR >::errFilename().

Here is the caller graph for this function: