1 // Copyright 2003 "Gilles Degottex"
3 // This file is part of "CppAddons"
5 // "CppAddons" is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or
8 // (at your option) any later version.
10 // "CppAddons" is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef _StringAddons_h_
21 #define _StringAddons_h_
31 namespace StringAddons
33 template<typename Type> std::string toString(Type i)
35 std::stringstream str;
39 template<typename Type> void toString(std::string& s, Type i)
41 std::stringstream str;
46 inline std::string ereaseEmptyChars(const std::string& str)
50 for(unsigned int i=0; i<str.length(); i++)
57 template<typename T> inline std::string binValue(T& d)
59 char* data = (char*)&d;
63 for(int i=sizeof(T)-1; i>=0; i--)
65 for(int j=7; j>=0; j--)
67 if(data[i] & (0x01<<j)) str += "1";
78 std::wstring toWide(const std::string& str);
79 std::string toAnsi(const std::wstring& str);
83 template<typename OstreamType> void undoable_out_clear(OstreamType& out, int n)
85 while(n-->0) out << "\b";
87 template<typename OstreamType> int undoable_out(OstreamType& out, const std::string& s, int n)
89 undoable_out_clear(out, n);
90 std::stringstream str;
97 template<class OstreamType> int undoable_out_percent(OstreamType& out, float f, int n=0)
99 undoable_out_clear(out, n);
100 std::stringstream str;
102 str << std::fixed << f << "% " << std::flush;
108 /* //-----------------------------------------------------------------------------
109 // UNICODE support for converting between CHAR, TCHAR, and WCHAR strings
110 //-----------------------------------------------------------------------------
111 void ConvertGenericStringToAnsi( CHAR* strDestination, const TCHAR* tstrSource, int cchDestChar = -1 );
112 void ConvertGenericStringToWide( WCHAR* wstrDestination, const TCHAR* tstrSource, int cchDestChar = -1 );
113 void ConvertAnsiStringToGeneric( TCHAR* tstrDestination, const CHAR* strSource, int cchDestChar = -1 );
114 void ConvertWideStringToGeneric( TCHAR* tstrDestination, const WCHAR* wstrSource, int cchDestChar = -1 );