1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
// Copyright 2003 "Gilles Degottex"
// This file is part of "CppAddons"
// "CppAddons" 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 2.1 of the License, or
// (at your option) any later version.
//
// "CppAddons" 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 program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef _StringAddons_h_
#define _StringAddons_h_
#include <stdio.h>
#include <string>
#include <sstream>
#include <ctype.h>
#include <time.h>
namespace StringAddons
{
template<typename Type> std::string toString(Type i)
{
std::stringstream str;
str << i;
return str.str();
}
template<typename Type> void toString(std::string& s, Type i)
{
std::stringstream str;
str << i;
s = str.str();
}
inline std::string ereaseEmptyChars(const std::string& str)
{
std::string result;
for(unsigned int i=0; i<str.length(); i++)
if(!isspace(str[i]))
result += str[i];
return result;
}
template<typename T> inline std::string binValue(T& d)
{
char* data = (char*)&d;
std::string str;
for(int i=sizeof(T)-1; i>=0; i--)
{
for(int j=7; j>=0; j--)
{
if(data[i] & (0x01<<j)) str += "1";
else str += "0";
}
if(i>0) str += "'";
}
return str;
}
#ifdef WIN32
std::wstring toWide(const std::string& str);
std::string toAnsi(const std::wstring& str);
#endif
// Undoable Out
template<typename OstreamType> void undoable_out_clear(OstreamType& out, int n)
{
while(n-->0) out << "\b";
}
template<typename OstreamType> int undoable_out(OstreamType& out, const std::string& s, int n)
{
undoable_out_clear(out, n);
std::stringstream str;
str.precision(1);
str << s;
n = str.tellp();
out << str.str();
return n;
}
template<class OstreamType> int undoable_out_percent(OstreamType& out, float f, int n=0)
{
undoable_out_clear(out, n);
std::stringstream str;
str.precision(1);
str << std::fixed << f << "% " << std::flush;
n = str.tellp();
out << str.str();
return n;
}
/* //-----------------------------------------------------------------------------
// UNICODE support for converting between CHAR, TCHAR, and WCHAR strings
//-----------------------------------------------------------------------------
void ConvertGenericStringToAnsi( CHAR* strDestination, const TCHAR* tstrSource, int cchDestChar = -1 );
void ConvertGenericStringToWide( WCHAR* wstrDestination, const TCHAR* tstrSource, int cchDestChar = -1 );
void ConvertAnsiStringToGeneric( TCHAR* tstrDestination, const CHAR* strSource, int cchDestChar = -1 );
void ConvertWideStringToGeneric( TCHAR* tstrDestination, const WCHAR* wstrSource, int cchDestChar = -1 );
*/
}
#endif
|