aGrUM  0.14.2
cast_unicode.h File Reference

Unicode helper functions. More...

#include <iostream>
#include <locale>
#include <sstream>
#include <string>
#include <agrum/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. More...
 
std::string narrow (const std::wstring &str)
 Cast a std::wstring into a std::string. More...
 

Detailed Description

Unicode helper functions.

Author
Christophe GONZALES and Pierre-Henri WUILLEMIN

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 50 of file cast_unicode_inl.h.

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

50  {
51  std::ostringstream stm;
52  const std::ctype< char >& ctfacet =
53  std::use_facet< std::ctype< char > >(stm.getloc());
54 
55  for (std::size_t i = 0; i < str.size(); ++i) {
56  stm << ctfacet.narrow(str[i], 0);
57  }
58 
59  return stm.str();
60 }
+ 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 38 of file cast_unicode_inl.h.

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

38  {
39  std::wostringstream wstm;
40  const std::ctype< wchar_t >& ctfacet =
41  std::use_facet< std::ctype< wchar_t > >(wstm.getloc());
42 
43  for (size_t i = 0; i < str.size(); ++i) {
44  wstm << ctfacet.widen(str[i]);
45  }
46 
47  return wstm.str();
48 }
+ Here is the caller graph for this function: