aGrUM  0.16.0
cast_unicode_inl.h File Reference

Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr. More...

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

Go to the source code of this file.

Functions

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

Detailed Description

Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.

This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.

Unicode helper functions.

Author
Christophe GONZALES and Pierre-Henri WUILLEMIN

Definition in file cast_unicode_inl.h.

Function Documentation

◆ narrow()

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

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

52  {
53  std::ostringstream stm;
54  const std::ctype< char >& ctfacet =
55  std::use_facet< std::ctype< char > >(stm.getloc());
56 
57  for (std::size_t i = 0; i < str.size(); ++i) {
58  stm << ctfacet.narrow(str[i], 0);
59  }
60 
61  return stm.str();
62 }
+ Here is the caller graph for this function:

◆ widen()

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

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

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