|
//------------------------------------------------------------------------------
// $Workfile: StringUtils.h $
// $Header: $
//
// Copyright � 2008 SbjCat
// All rights reserved.
//
//
// *** Authors ***
// Steve Johnson
//
// $Revision: $
//
//-----------------------------------------------------------------------------
#pragma once
#include "StreamOps.h"
#include <sstream>
namespace SbjCore
{
namespace Utils
{
namespace STR
{
CString AFX_EXT_API VariantToStr(const _variant_t& var);
bool AFX_EXT_API StrToVariant(const CString& sVal, _variant_t& var);
int AFX_EXT_API Split(LPCTSTR lpsz, LPCTSTR lpszDeliminators, CStringArray& arrTokens);
// Template specific /////////////////////////////////////////////////////////////////////////
#pragma warning(disable:4701) // potentially uninitialized local variable 'tValue' used
/** StrToValue takes a string and uses std::stringstream to convert it to a ttype, where
ttype is any basic type or construct that implements the >> stream operator.
\param lpsz string representation of any basic type or construct that implements
the >> stream operator.
*/
template <class ttype> const ttype StrToValue(LPCTSTR lpsz)
{
USES_CONVERSION;
ttype tValue;
try
{
std::stringstream theStream2(T2CA(lpsz));
(void) theStream2.imbue(std::locale::classic());
theStream2 >> tValue;
}
catch (...)
{
ASSERT(FALSE);
}
return tValue;
}
/** ValueToStr takes a ttype and uses std::stringstream to convert it to a CString, where
ttype is any basic type or construct that implements the >> stream operator.
\param tValue any basic type or construct that implements the >> stream operator.
*/
template <class ttype> CString ValueToStr(const ttype& tValue)
{
USES_CONVERSION;
CString sVal;
try
{
std::stringstream theStream;
(void) theStream.imbue(std::locale::classic());
theStream << tValue;
sVal = A2CT(theStream.str().c_str());
}
catch (...)
{
ASSERT(FALSE);
}
return sVal;
}
}
}
}
//*** Modification History ***
// $Log: $
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Real name is Steve Johnson. Programming since 1979. Started on a Heathkit Micro with a DEC LSI-11 and UCSD Pascal. Moved to PCs & DOS as soon as Turbo Pascal became available. Did some Assembly, ISR, TSR etc. All this while working for a Manufacturing Co. for 8 years. Had my own solo Co. doing barcode labeling software for 4 years (terrible business man, all I wanted to do was code). Since then working for various software companies. Moved to Windows around the time of 3.1 with Borland C then C++. Then on to VC++ and MFC, and just about anything I could get my hands on or had to learn for my job, and been at it ever since. Of course recently I've been playing with .NET, ASP, C#, WPF etc.