  | 
   INI File Class 
   Submitted by  |   
  
  
Here is a very simple way to use *.ini file : A CIniFile class.
A CIniFile object can load/save *.ini files and supports
all features you may need when using *.ini files.
I found that very usefull (and the teams i'm working with also think so)
  
A will be happy to have your comments about the way i am coding.
I am also looking for tips in order to make this class better (more safe and faster).
  
Antoine Villepreux (france)
 | 
 
 
 
Currently browsing [inifile.zip] (62,782 bytes) - [Cpp version/CIniFile.cpp] - (42,442 bytes)
 
 
//-----------------------------------------------------------------------------
// File name    : CIniFile.cpp
// Author       : AV (Antoine Villepreux)
// date         : 20/11/2000
// Description  : CIniFile class implementation
//              : Easy IniFile object management
//-----------------------------------------------------------------------------
  //-----------------------------------------------------------------------------
// Macros
//-----------------------------------------------------------------------------
#define	M_MODULE_BGN
#define	M_MODULE_END
  #define	M_INCLUDES_BGN
#define	M_INCLUDES_END
  #define	M_INIFILE_FN_BGN
#define	M_INIFILE_FN_END
  //-----------------------------------------------------------------------------
M_MODULE_BGN("CIniFile.cpp")
  //-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
M_INCLUDES_BGN("CIniFile.cpp")
  	#include "Common.h"
	#include "CIniFile.h"
//	#include "CCrypto.h"
	#include "float.h"
	#include "limits.h"
  M_INCLUDES_END("CIniFile.cpp")
  //-----------------------------------------------------------------------------
#ifdef  _DEBUG_NEW
#undef  new
#define new DEBUG_NEW
#undef  THIS_FILE
#define THIS_FILE __FILE__
#endif
  //-----------------------------------------------------------------------------
// Error constants
//-----------------------------------------------------------------------------
const CStdString CIniFile::ms_strError = "CINIFILE_ERROR_READING_KEY_OR_SECTION";
const int        CIniFile::ms_iError   = INT_MAX;
const float      CIniFile::ms_fError   = FLT_MAX;
  const CStdString CIniFile::ms_strErrorMsg[CIniFile::E_INI_ERROR_MESSAGES::E_ERROR_MESSAGES_COUNT] = 
{
      "Error: Unable to open ini file",
    "Error: Unable to save ini file",
    "Error: Unable to locate specified section",
    "Error: Unable to locate specified key",
    "Warning: unknown extension" ,
	"Warning: end string delimiter not found"
};
  //-----------------------------------------------------------------------------
// Internal shortcuts constants
//-----------------------------------------------------------------------------
const CStdString CIniFile::ms_strComment  [CIniFile::E_INI_COMMENTS  ::E_COMMENTS_COUNT  ] = { ";"   , "//", "/*", "\t\t" };
const CStdString CIniFile::ms_strType     [CIniFile::E_INI_TYPES     ::E_TYPES_COUNT     ] = { "%d"  , "%f", "%s"         };
const CStdString CIniFile::ms_strMarkup   [CIniFile::E_INI_MARKUPS   ::E_MARKUPS_COUNT   ] = { "["   , "]" , "="          };
const CStdString CIniFile::ms_strTrim     [CIniFile::E_INI_TRIM      ::E_TRIM_COUNT      ] = { " "   , "\t"               };
const CStdString CIniFile::ms_strExtension[CIniFile::E_INI_EXTENSIONS::E_EXTENSIONS_COUNT] = { ".ini", ".crk"             };
  const CStdString CIniFile::ms_strStringDelimiter = "\"";
  //-----------------------------------------------------------------------------
// Various defines
//-----------------------------------------------------------------------------
  #ifdef	TO_BOOL
#undef	TO_BOOL
#endif
#define	TO_BOOL(i)		(((i)==0)?false:true)
  #ifdef	TO_INT
#undef	TO_INT
#endif
#define TO_INT(b)		(((b))?1:0)
  #define BREAKPOINT		_asm int 3
  //-----------------------------------------------------------------------------
// CIniFile Implementation
//-----------------------------------------------------------------------------
  //-----------------------------------------------------------------------------
// Name        : CIniFile::CIniFile()
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Construct empty IniFile object
//-----------------------------------------------------------------------------
CIniFile::CIniFile()
{
M_INIFILE_FN_BGN(CIniFile::CIniFile())
  	SetReadableExtension (ms_strExtension[E_INI_EXTENSIONS::E_READABLE ]);
    SetEncryptedExtension(ms_strExtension[E_INI_EXTENSIONS::E_ENCRYPTED]);
  	m_bFastRead = false;
  M_INIFILE_FN_END
}
  //-----------------------------------------------------------------------------
// Name        : CIniFile::CIniFile(const CFilename & strFilename, bool bFastRead)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Construct IniFile object based on given file
//             : Optionnal fast read may be used if file doesn't contain any
//             : trailing spaces nor tabs
//-----------------------------------------------------------------------------
CIniFile::CIniFile(const CFilename & strFilename, bool bFastRead)
{
M_INIFILE_FN_BGN(CIniFile::CIniFile(const CFilename & strFilename))
  	SetReadableExtension (ms_strExtension[E_INI_EXTENSIONS::E_READABLE ]);
    SetEncryptedExtension(ms_strExtension[E_INI_EXTENSIONS::E_ENCRYPTED]);
  	Load(strFilename, bFastRead);
  M_INIFILE_FN_END
}
  //-----------------------------------------------------------------------------
// Name        : CIniFile::~CIniFile()
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Destruct IniFile object
//-----------------------------------------------------------------------------
CIniFile::~CIniFile()
{
M_INIFILE_FN_BGN(CIniFile::~CIniFile(bool bSave))
  #ifdef INI_SAVE_ON_EXIT
  	Save(m_strPath);
  #endif
  M_INIFILE_FN_END
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::Load(const CStdString& strFilename, bool bFastRead)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Load ini file from disk or from previous specified file
//             : Optionnal fast read may be used if file doesn't contain any
//             : trailing spaces nor tabs
//-----------------------------------------------------------------------------
bool CIniFile::Load(const CStdString& strFilename, bool bFastRead)
{
M_INIFILE_FN_BGN(bool CIniFile::Load(const CStdString& strFilename))
  	m_bFastRead = bFastRead;
  	if (strFilename != "") 
	{
		m_strPath = strFilename;
	}
  	// Try reading readable ini file
      if (m_strPath.GetLength() > m_strReadableExtension.GetLength())
    if (!m_strReadableExtension.CompareNoCase(m_strPath.Right(m_strReadableExtension.GetLength())))
    {
		// If *.ini doesn't exist change extension to crypted extension and try again
          if (LoadReadableFile(m_strPath, true)) 
		{
			return true;
		}
		else
		{
			m_strPath = m_strPath.Left(m_strPath.GetLength() - m_strReadableExtension.GetLength()) + m_strEncryptedExtension;
		}
    }
  	// Try reading crypted ini file
    
    if (m_strPath.GetLength() > m_strEncryptedExtension.GetLength())
    if (!m_strEncryptedExtension.CompareNoCase(m_strPath.Right(m_strEncryptedExtension.GetLength())))
    {
        return LoadReadableFile(m_strPath, false);
    }
  	// No recognized extension found
	// Try reading readable ini file
      m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_UNKNOWN_EXTENSION];
      if (LoadReadableFile())
	{
		return true;
	}
	else
	{
		m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_READ];
  		#ifdef WIN32
			CStdString strMsg = m_strPath + " file not found !";
			::MessageBox(NULL,strMsg, m_strLastError, MB_OK);
		#endif
  		BREAKPOINT;
  	#ifdef INI_USE_EXEPTIONS
  		throw(strMsg.c_str());
  	#endif
  		return false;
	}
  M_INIFILE_FN_END
  	return false;
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::LoadReadableFile(const CStdString& strFilename, bool bIsReadable)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Internal function - file loading
//-----------------------------------------------------------------------------
bool CIniFile::LoadReadableFile(const CStdString& strFilename, bool bIsReadable)
{
M_INIFILE_FN_BGN(bool CIniFile::LoadReadableFile(const CStdString& strFilename, bool bIsReadable))
  	if (strFilename != "") m_strPath = strFilename;
  	// Open stream
  	std::ifstream inifile;
	inifile.open(m_strPath);
  	if (inifile.fail())
	{
        m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_READ];
		return false;
	}
  	// Open stream Ok, parse file lines
  	CStdString strLine, strSection, strKey, strValue;
  	while (GetLine(inifile, strLine))
	{
		if (! bIsReadable) 
		{
			Decrypt(strLine);
		}
  		if (!m_bFastRead)
		{
			ManageComments(&strLine);
		}
  		if (strLine != "")
		{
            if (	strLine[0]						== (ms_strMarkup[E_INI_MARKUPS::E_SECTION_BEGIN])[0] && 
					strLine[strLine.GetLength()-1]	== (ms_strMarkup[E_INI_MARKUPS::E_SECTION_END]  )[0]	)
			{
				// Section found
  				strSection = strLine;
  				strSection.TrimLeft (ms_strMarkup[E_INI_MARKUPS::E_SECTION_BEGIN]);
				strSection.TrimRight(ms_strMarkup[E_INI_MARKUPS::E_SECTION_END]);
  				if (!m_bFastRead)
				{
					CleanString(&strSection);
				}
			}
			else
			{
				// Key found
  				strKey   = strLine.Left (strLine.Find(ms_strMarkup[E_INI_MARKUPS::E_KEY]));
				strValue = strLine.Right(strLine.GetLength()-strKey.GetLength()-1);
  				if (!m_bFastRead)
				{
					CleanString(&strKey);
					CleanString(&strValue);
				}
  				strValue.TrimLeft(ms_strMarkup[E_INI_MARKUPS::E_KEY]);
				
				SetValue(strSection, strKey, strValue);
			}
		}
	}
  	inifile.close();
  	return true;
  M_INIFILE_FN_END
  	return false;	
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::Save(const CStdString& strFilename)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Save IniFile object to disk with specified filename
//-----------------------------------------------------------------------------
bool CIniFile::Save(const CStdString& strFilename)
{
M_INIFILE_FN_BGN(bool CIniFile::Save(const CStdString& strFilename))
  	if (strFilename != "") m_strPath = strFilename;
      if (m_strPath.GetLength() > m_strReadableExtension.GetLength())
    if (!m_strReadableExtension.CompareNoCase(m_strPath.Right(m_strReadableExtension.GetLength())))
    {
        return SaveReadableFile();
    }
    
    if (m_strPath.GetLength() > m_strEncryptedExtension.GetLength())
    if (!m_strEncryptedExtension.CompareNoCase(m_strPath.Right(m_strEncryptedExtension.GetLength())))
    {
        return SaveEncryptedFile();
    }
      m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_UNKNOWN_EXTENSION];
      SaveReadableFile();
  	return false;
  M_INIFILE_FN_END
  	return false;
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SaveReadableFile(const CStdString& strFilename)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : internal function - save readable file to disk
//-----------------------------------------------------------------------------
bool CIniFile::SaveReadableFile(const CStdString& strFilename)
{
M_INIFILE_FN_BGN(bool CIniFile::SaveReadableFile(const CStdString& strFilename))
  	if (strFilename != "") m_strPath = strFilename;
  	std::ofstream inifile;
	inifile.open(m_strPath);
  	for(m_itSection=m_data.begin(); m_itSection!=m_data.end(); m_itSection++)
	{
		inifile	<< "\n" << ms_strMarkup[E_INI_MARKUPS::E_SECTION_BEGIN] << (*m_itSection).first << ms_strMarkup[E_INI_MARKUPS::E_SECTION_END] << "\n";
  		for(m_itKey=((*m_itSection).second).begin(); m_itKey!=((*m_itSection).second).end(); m_itKey++)
		{
			inifile	<< (*m_itKey).first << ms_strMarkup[E_INI_MARKUPS::E_KEY] << (*m_itKey).second << "\n";
		}
	}
  	inifile.close();
  	return true;
  M_INIFILE_FN_END
  	return false;
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SaveEncryptedFile(const CStdString& strFilename)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : internal function - save crypted file to disk
//-----------------------------------------------------------------------------
bool CIniFile::SaveEncryptedFile(const CStdString& strFilename)
{
M_INIFILE_FN_BGN(bool CIniFile::SaveEncryptedFile(const CStdString& strFilename))
  	if (strFilename != "") m_strPath = strFilename;
  	std::ofstream inifile;
	inifile.open(m_strPath);
  	for(m_itSection=m_data.begin(); m_itSection!=m_data.end(); m_itSection++)
	{
		inifile	<< "\n" << Encrypt(ms_strMarkup[E_INI_MARKUPS::E_SECTION_BEGIN]) << Encrypt((*m_itSection).first) << Encrypt(ms_strMarkup[E_INI_MARKUPS::E_SECTION_END]) << "\n";
  		for(m_itKey=((*m_itSection).second).begin(); m_itKey!=((*m_itSection).second).end(); m_itKey++)
		{
			inifile	<< Encrypt((*m_itKey).first) << Encrypt(ms_strMarkup[E_INI_MARKUPS::E_KEY]) << Encrypt((*m_itKey).second) << "\n";
		}
	}
  	inifile.close();
  	return true;
  M_INIFILE_FN_END
  	return false;
}
  //-----------------------------------------------------------------------------
// Name        : void CIniFile::Reset()
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Reset IniFile object - clears all sections and keys
//-----------------------------------------------------------------------------
void CIniFile::Reset()
{
M_INIFILE_FN_BGN(void CIniFile::Reset())
  	for(m_itSection=m_data.begin(); m_itSection!=m_data.end(); m_itSection++)
	{
		((*m_itSection).second).clear();
	}
  	m_data.clear();
  M_INIFILE_FN_END
}
  //-----------------------------------------------------------------------------
// Name        : unsigned int CIniFile::GetSectionCount()
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get number of sections
//-----------------------------------------------------------------------------
unsigned int CIniFile::GetSectionCount()
{
M_INIFILE_FN_BGN(unsigned int CIniFile::GetSectionCount())
  	return m_data.size();
  M_INIFILE_FN_END
  	return 0;
}
  //-----------------------------------------------------------------------------
// Name        : unsigned int CIniFile::GetKeyCount(const CStdString& strSection)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get number of keys in specified section
//-----------------------------------------------------------------------------
unsigned int CIniFile::GetKeyCount(const CStdString& strSection)
{
M_INIFILE_FN_BGN(unsigned int CIniFile::GetKeyCount(const CStdString& strSection))
  	return m_data[strSection].size();
  M_INIFILE_FN_END
  	return 0;	
}
  //-----------------------------------------------------------------------------
// Name        : unsigned int CIniFile::GetKeyCount(unsigned int iSection)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get number of keys in i-th section
//-----------------------------------------------------------------------------
unsigned int CIniFile::GetKeyCount(unsigned int iSection)
{
M_INIFILE_FN_BGN(unsigned int CIniFile::GetKeyCount(unsigned int iSection))
  	m_itSection = m_data.begin();
	std::advance(m_itSection, iSection);
  	return (*m_itSection).second.size();
  M_INIFILE_FN_END
  	return 0;	
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::GetSection(unsigned int iSection)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get name of i-th section
//-----------------------------------------------------------------------------
CStdString CIniFile::GetSection(unsigned int iSection)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetSection(unsigned int iSection))
  	m_itSection = m_data.begin();
	std::advance(m_itSection, iSection);
  	return (*m_itSection).first;
  M_INIFILE_FN_END
  	return ms_strError;
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::GetKey(unsigned int iSection, unsigned int iKey)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get name of i-th key from i-th section
//-----------------------------------------------------------------------------
CStdString CIniFile::GetKey(unsigned int iSection, unsigned int iKey)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetKey(unsigned int iSection, unsigned int iKey))
  	m_itSection = m_data.begin();
	std::advance(m_itSection, iSection);
  	m_itKey = (*m_itSection).second.begin();
	std::advance(m_itKey, iKey);
  	return (*m_itKey).first;
  M_INIFILE_FN_END
  	return ms_strError;
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::GetKey(const CStdString& strSection, unsigned int iKey)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get name of i-th key from specified section
//-----------------------------------------------------------------------------
CStdString CIniFile::GetKey(const CStdString& strSection, unsigned int iKey)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetKey(unsigned int iSection, unsigned int iKey))
  	m_itKey = m_data[strSection].begin();
	std::advance(m_itKey, iKey);
  	return (*m_itKey).first;
  M_INIFILE_FN_END
  	return ms_strError;
}
  //-----------------------------------------------------------------------------
// Name        : int CIniFile::GetSection(const CStdString& strSection)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get id of specified section
//-----------------------------------------------------------------------------
int CIniFile::GetSection(const CStdString& strSection)
{
M_FN_BGN(int CIniFile::GetSection(const CStdString& strSection))
  	int iCurrentSection = 0;
  	for(m_itSection=m_data.begin(); m_itSection!=m_data.end(); m_itSection++)
	{
		if ((*m_itSection).first == strSection)
		{
			return iCurrentSection;
		}
  		iCurrentSection++;
	}
  	return -1;
  M_FN_END
  	return -1;
}
  //-----------------------------------------------------------------------------
// Name        : int CIniFile::GetKey(const CStdString& strSection, const CStdString& strKey)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get id of specified key from specified section
//-----------------------------------------------------------------------------
int CIniFile::GetKey(const CStdString& strSection, const CStdString& strKey)
{
M_FN_BGN(int CIniFile::GetKey(const CStdString& strKey);)
  	int iCurrentKey = 0;
  	for(m_itKey=m_data[strSection].begin(); m_itKey!=m_data[strSection].end(); m_itKey++)
	{
		if ((*m_itKey).first == strKey)
		{
			return iCurrentKey;
		}
  		iCurrentKey++;
	}
  	return -1;
  M_FN_END
  	return -1;
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::GetValue(const CStdString& strSection, const CStdString& strKey)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get string value from specified section/key
//-----------------------------------------------------------------------------
CStdString CIniFile::GetValue(const CStdString& strSection, const CStdString& strKey)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetValue(const CStdString& strSection, const CStdString& strKey))
  	if (!m_bFastRead)
	{
		if (m_data.find(strSection) == m_data.end())
		{
			m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_FIND_SECTION];
		}
		else if (m_data[strSection].find(strKey) == m_data[strSection].end())
		{
			m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_FIND_KEY];
		}
		else
		{
			return m_data[strSection][strKey];
		}
  		#ifdef WIN32
			::MessageBox(NULL, m_strLastError, m_strPath, MB_ICONWARNING);
		#endif
  		#ifdef INI_USE_EXEPTIONS
			throw(ms_strError.c_str());
		#endif
  		return ms_strError;
	}
  	return m_data[strSection][strKey];
  M_INIFILE_FN_END
  	return ms_strError;
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::GetValueS(const CStdString& strSection, const CStdString& strKey)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get string value from specified section/key
//-----------------------------------------------------------------------------
CStdString CIniFile::GetValueS(const CStdString& strSection, const CStdString& strKey)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetValueS(const CStdString& strSection, const CStdString& strKey))
  	return GetValue(strSection,strKey);
  M_INIFILE_FN_END
  	return ms_strError;
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::GetValue(const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get string value from specified section/key and return default value if section or key not found
//-----------------------------------------------------------------------------
CStdString CIniFile::GetValue(const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetValue(const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault))
  	if (!m_bFastRead)
	{
		if ( (m_data.find(strSection) == m_data.end()) ||
			 (m_data[strSection].find(strKey) == m_data[strSection].end()) )
		{
			return strDefault;
		}
	}
  	return GetValue(strSection,strKey);
  M_INIFILE_FN_END
  	return strDefault;
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::GetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get string value from specified section/key and return default value if section or key not found
//-----------------------------------------------------------------------------
CStdString CIniFile::GetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault))
  	return GetValue(strSection,strKey,strDefault);
  M_INIFILE_FN_END
  	return strDefault;
}
  //-----------------------------------------------------------------------------
// Name        : int CIniFile::GetValueI(const CStdString& strSection, const CStdString& strKey)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get integer value from specified section/key
//-----------------------------------------------------------------------------
int CIniFile::GetValueI(const CStdString& strSection, const CStdString& strKey)
{
M_INIFILE_FN_BGN(int CIniFile::GetValueI(const CStdString& strSection, const CStdString& strKey))
  	return atoi(GetValue(strSection,strKey).c_str());
  M_INIFILE_FN_END
  	return ms_iError;
}
  //-----------------------------------------------------------------------------
// Name        : int CIniFile::GetValueI(const CStdString& strSection, const CStdString& strKey, const int & iDefault)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get integer value from specified section/key and return default value if section or key not found
//-----------------------------------------------------------------------------
int CIniFile::GetValueI(const CStdString& strSection, const CStdString& strKey, const int & iDefault)
{
M_INIFILE_FN_BGN(int CIniFile::GetValueI(const CStdString& strSection, const CStdString& strKey, const int & iDefault))
  	CStdString strDefault;
	strDefault.Format(ms_strType[CIniFile::E_INI_TYPES::E_INTEGER], iDefault);
  	return atoi(GetValue(strSection,strKey,strDefault).c_str());
  M_INIFILE_FN_END
  	return iDefault;
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::GetValueB(const CStdString& strSection, const CStdString& strKey)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get boolean value from specified section/key
//-----------------------------------------------------------------------------
bool CIniFile::GetValueB(const CStdString& strSection, const CStdString& strKey)
{
M_INIFILE_FN_BGN(bool CIniFile::GetValueB(const CStdString& strSection, const CStdString& strKey))
  	return TO_BOOL(GetValueI(strSection,strKey));
  M_INIFILE_FN_END
  	return TO_BOOL(ms_iError);
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::GetValueB(const CStdString& strSection, const CStdString& strKey, const bool & bDefault)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get boolean value from specified section/key and return default value if section or key not found
//-----------------------------------------------------------------------------
bool CIniFile::GetValueB(const CStdString& strSection, const CStdString& strKey, const bool & bDefault)
{
M_INIFILE_FN_BGN(bool CIniFile::GetValueB(const CStdString& strSection, const CStdString& strKey, const bool & bDefault))
  	return TO_BOOL(GetValueI(strSection,strKey,TO_INT(bDefault)));
  M_INIFILE_FN_END
  	return TO_BOOL(bDefault);
}
  //-----------------------------------------------------------------------------
// Name        : float CIniFile::GetValueF(const CStdString& strSection, const CStdString& strKey)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get floating point value from specified section/key
//-----------------------------------------------------------------------------
float CIniFile::GetValueF(const CStdString& strSection, const CStdString& strKey)
{
M_INIFILE_FN_BGN(float CIniFile::GetValueF(const CStdString& strSection, const CStdString& strKey))
  	return (float)atof(GetValue(strSection,strKey).c_str());
  M_INIFILE_FN_END
  	return ms_fError;
}
  //-----------------------------------------------------------------------------
// Name        : float CIniFile::GetValueF(const CStdString& strSection, const CStdString& strKey, const float & fDefault)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get floating point value from specified section/key and return default value if section or key not found
//-----------------------------------------------------------------------------
float CIniFile::GetValueF(const CStdString& strSection, const CStdString& strKey, const float & fDefault)
{
M_INIFILE_FN_BGN(float CIniFile::GetValueF(const CStdString& strSection, const CStdString& strKey, const float & fDefault))
  	CStdString strDefault;
	strDefault.Format(ms_strType[CIniFile::E_INI_TYPES::E_FLOAT], fDefault);
  	return (float)atof(GetValue(strSection,strKey,strDefault).c_str());
  M_INIFILE_FN_END
  	return fDefault;
}
  //-----------------------------------------------------------------------------
// Name        : void CIniFile::SetReadableExtension(const CStdString& ext)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Change readable exension
//-----------------------------------------------------------------------------
void CIniFile::SetReadableExtension(const CStdString& ext)
{
M_INIFILE_FN_BGN(void CIniFile::SetReadableExtension(const CStdString& ext))
  	m_strReadableExtension = ext;
  M_INIFILE_FN_END
}
  //-----------------------------------------------------------------------------
// Name        : void CIniFile::SetEncryptedExtension(const CStdString& ext)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Change crypted exension
//-----------------------------------------------------------------------------
void CIniFile::SetEncryptedExtension(const CStdString& ext)
{
M_INIFILE_FN_BGN(void CIniFile::SetEncryptedExtension(const CStdString& ext))
  	m_strEncryptedExtension = ext;
  M_INIFILE_FN_END
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::GetLastErrorMessage()
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Get last error message
//-----------------------------------------------------------------------------
CStdString CIniFile::GetLastErrorMessage()
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetLastErrorMessage())
  	return m_strLastError;
  M_INIFILE_FN_END
  	return "error in error handling !";
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const CStdString& value, bool bCreate)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Set string value to specified section/key. Possibility to create section/key if doesn't exist
//-----------------------------------------------------------------------------
bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const CStdString& value, bool bCreate)
{
M_INIFILE_FN_BGN(bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const CStdString& value, bool bCreate))
  	if (m_data.find(strSection) == m_data.end())
	{
		if (!bCreate)
		{
			return false;
		}
  		m_data.insert(CSection::value_type(strSection,CKey()));
	}
  	if (m_data[strSection].find(strKey)	== m_data[strSection].end())
	{
		if (!bCreate)
		{
			return false;
		}
  		m_data[strSection].insert(CKey::value_type(strKey,""));
	}
  	m_data[strSection][strKey] = value;
	
	return true;
  M_INIFILE_FN_END
  	return false; 
  }
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& value, bool create)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Set string value to specified section/key. Possibility to create section/key if doesn't exist
//-----------------------------------------------------------------------------
bool CIniFile::SetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& value, bool create)
{
M_INIFILE_FN_BGN(bool CIniFile::SetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& value, bool create))
  	SetValue(strSection, strKey, value, create);
	
	return true;
  M_INIFILE_FN_END
  	return false; 
  }
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const int & value, bool create)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Set integer value to specified section/key. Possibility to create section/key if doesn't exist
//-----------------------------------------------------------------------------
bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const int & value, bool create)
{
M_INIFILE_FN_BGN(bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const int & value, bool create))
  	return SetValueI(strSection, strKey, value, create);
  M_INIFILE_FN_END
  	return false; 
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const bool & value, bool create)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Set boolean value to specified section/key. Possibility to create section/key if doesn't exist
//-----------------------------------------------------------------------------
bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const bool & value, bool create)
{
M_INIFILE_FN_BGN(bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const bool & value, bool create))
  	return SetValueB(strSection, strKey, value, create);
  M_INIFILE_FN_END
  	return false; 
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const float & value, bool create)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Set floating point value to specified section/key. Possibility to create section/key if doesn't exist
//-----------------------------------------------------------------------------
bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const float & value, bool create)
{
M_INIFILE_FN_BGN(bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const float & value, bool create))
  	return SetValueF(strSection, strKey, value, create);
  M_INIFILE_FN_END
  	return false; 
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SetValueI(const CStdString& strSection, const CStdString& strKey, const int & value, bool create)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Set integer value to specified section/key. Possibility to create section/key if doesn't exist
//-----------------------------------------------------------------------------
bool CIniFile::SetValueI(const CStdString& strSection, const CStdString& strKey, const int & value, bool create)
{
M_INIFILE_FN_BGN(bool CIniFile::SetValueI(const CStdString& strSection, const CStdString& strKey, const int & value, bool create))
  	CStdString temp;
	temp.Format(ms_strType[E_INI_TYPES::E_INTEGER],value);
	return SetValue(strSection, strKey, temp, create);
  M_INIFILE_FN_END
  	return false; 
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SetValueB(const CStdString& strSection, const CStdString& strKey, const bool & value, bool create)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description :Set boolean value to specified section/key. Possibility to create section/key if doesn't exist
//-----------------------------------------------------------------------------
bool CIniFile::SetValueB(const CStdString& strSection, const CStdString& strKey, const bool & value, bool create)
{
M_INIFILE_FN_BGN(bool CIniFile::SetValueI(const CStdString& strSection, const CStdString& strKey, const bool & value, bool create))
  	CStdString temp;
	temp.Format(ms_strType[E_INI_TYPES::E_INTEGER],TO_INT(value));
	return SetValue(strSection, strKey, temp, create);
  M_INIFILE_FN_END
  	return false; 
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::SetValueF(const CStdString& strSection, const CStdString& strKey, const float & value, bool create)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Set floating point value to specified section/key. Possibility to create section/key if doesn't exist
//-----------------------------------------------------------------------------
bool CIniFile::SetValueF(const CStdString& strSection, const CStdString& strKey, const float & value, bool create)
{
M_INIFILE_FN_BGN(bool CIniFile::SetValueF(const CStdString& strSection, const CStdString& strKey, const float & value, bool create))
  	CStdString temp;
	temp.Format(ms_strType[E_INI_TYPES::E_FLOAT],value);
	return SetValue(strSection, strKey, temp, create);
  M_INIFILE_FN_END
  	return false; 
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::Delete(const CStdString& strSection, const CStdString& strKey)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Delete section/key
//-----------------------------------------------------------------------------
bool CIniFile::Delete(const CStdString& strSection, const CStdString& strKey)
{
M_INIFILE_FN_BGN(bool CIniFile::Delete(const CStdString& strSection, const CStdString& strKey))
  	m_data[strSection].erase(strKey);
  	return true;
  M_INIFILE_FN_END
  	return false; 
}
  //-----------------------------------------------------------------------------
// Name        : bool CIniFile::Delete(const CStdString& strSection)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : Delete section
//-----------------------------------------------------------------------------
bool CIniFile::Delete(const CStdString& strSection)
{
M_INIFILE_FN_BGN(bool CIniFile::Delete(const CStdString& strSection))
  	m_data.erase(strSection);
  	return true;
  M_INIFILE_FN_END
  	return false; 
}
  //-----------------------------------------------------------------------------
// Name        : std::istream & CIniFile::GetLine(std::istream & is, CStdString& str)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : internal function - get line from stream
//-----------------------------------------------------------------------------
std::istream & CIniFile::GetLine(std::istream & is, CStdString& str)
{
M_INIFILE_FN_BGN(std::istream & CIniFile::GetLine(std::istream & is, CStdString& str))
  	char buf[INI_LINE_MAX_LENGTH];
	is.getline(buf, INI_LINE_MAX_LENGTH);
	str = buf;
	return is;
  M_INIFILE_FN_END
  	return is;
}
  //-----------------------------------------------------------------------------
// Name        : void CIniFile::CleanString(CStdString * pString)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : internal function - clean given string (removes trailing characters)
//-----------------------------------------------------------------------------
void CIniFile::CleanString(CStdString * pString)
{
M_INIFILE_FN_BGN(void CIniFile::CleanString(CStdString * pString))
  	int iOldLength = pString->GetLength();
  	do for(unsigned int iTrim=0; iTrim<E_INI_TRIM::E_TRIM_COUNT; iTrim++)
	{
		iOldLength = pString->GetLength();
  		pString->TrimLeft (ms_strTrim[iTrim]);
		pString->TrimRight(ms_strTrim[iTrim]);
	}
	while(pString->GetLength() != iOldLength);
  	pString->TrimLeft (ms_strStringDelimiter);
	pString->TrimRight(ms_strStringDelimiter);
  M_INIFILE_FN_END
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::ManageComments(CStdString * pString)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : internal function - removes (and retrieve) comment from string
//-----------------------------------------------------------------------------
CStdString CIniFile::ManageComments(CStdString * pString)
{
M_INIFILE_FN_BGN(CStdString CIniFile::ManageComments(CStdString * pString))
  	// First, look for string delimiters
  	int iDelimiterBegin = pString->Find       (ms_strStringDelimiter[0]);
	int iDelimiterEnd   = pString->ReverseFind(ms_strStringDelimiter[0]);
  	if (iDelimiterEnd < iDelimiterBegin)
	{
		m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_END_DELIMITER];
	}
  	// then manage comments
  	CStdString strComment = "";
  	int iPrevPos, iPos, iLength=pString->GetLength();
  	iPrevPos = pString->Find(ms_strComment[E_INI_COMMENTS::E_0]);
	if ((iPrevPos<0)||((iPrevPos>iDelimiterBegin)&&(iPrevPos<iDelimiterEnd))) iPrevPos = iLength;
  	iPos = pString->Find(ms_strComment[E_INI_COMMENTS::E_1]);
	if ((iPos<0)||((iPos>iDelimiterBegin)&&(iPos<iDelimiterEnd))) iPos = iLength;
  	iPos = (iPrevPos<iPos) ? iPrevPos : iPos;
  	iPrevPos = pString->Find(ms_strComment[E_INI_COMMENTS::E_2]);
	if ((iPrevPos<0)||((iPrevPos>iDelimiterBegin)&&(iPrevPos<iDelimiterEnd))) iPrevPos = iLength;
  	iPos = (iPrevPos<iPos) ? iPrevPos : iPos;
  	if (iPos>=0)
	{
		 strComment = pString->Right(iLength-iPos);
		*pString    = pString->Left (iPos);
  		 pString->TrimRight();
		 pString->TrimRight(ms_strComment[E_INI_COMMENTS::E_SPACING]);
	}
  	return strComment;
  M_INIFILE_FN_END
  	return "";
}
  //-----------------------------------------------------------------------------
// Name        : void CIniFile::Decrypt(CStdString& str)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : internal function - decrypt string (uses CCrypto)
//-----------------------------------------------------------------------------
void CIniFile::Decrypt(CStdString& str)
{
M_INIFILE_FN_BGN(void CIniFile::Decrypt(CStdString& str))
  //	CCrypto::Decrypt(&str);
  M_INIFILE_FN_END
}
  //-----------------------------------------------------------------------------
// Name        : CStdString CIniFile::Encrypt(const CStdString& str)
// Author      : AV (Antoine Villepreux)
// Date        : 20/11/2000
// Description : internal function - encrypt string (uses CCrypto)
//-----------------------------------------------------------------------------
CStdString CIniFile::Encrypt(const CStdString& str)
{
M_INIFILE_FN_BGN(CStdString CIniFile::Encrypt(const CStdString& str))
  	CStdString strTmp = str;
  //	CCrypto::Encrypt(&strTmp);
  	return strTmp;
  M_INIFILE_FN_END
	
	return "";
}
  //-----------------------------------------------------------------------------
  M_MODULE_END("CIniFile.cpp")
   |  
  
 | 
 
  
Currently browsing [inifile.zip] (62,782 bytes) - [Cpp version/CIniFile.h] - (7,482 bytes)
 
 
//------------------------------------------------------------------------------
// File name   : CIniFile.h
// Author      : Microïds - Antoine Villepreux
// Description : CIniFile class definition
// Purpose     : Easy *.ini files management
//------------------------------------------------------------------------------
#ifndef CINIFILE_H
#define CINIFILE_H
  //------------------------------------------------------------------------------
// Precompiler options
//------------------------------------------------------------------------------
#define	INI_USE_EXEPTIONS
#define	INI_CASE_INENSITIVE
#undef	INI_SAVE_ON_EXIT
  //------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include <map>
#include <fstream>
#include "CStdString.h"
  //------------------------------------------------------------------------------
// CIniFile defines
//------------------------------------------------------------------------------
#define INI_LINE_MAX_LENGTH 1024
  //------------------------------------------------------------------------------
// CFilename definition
//------------------------------------------------------------------------------
#define CFilename CStdString
  //------------------------------------------------------------------------------
// CIniFile definition
//------------------------------------------------------------------------------
class CIniFile
{
public:
	// created in memory, no load from disk
	CIniFile();
	CIniFile(const CFilename &, bool bFastRead = false);
	virtual ~CIniFile();
      // I/O - extension sensitive
	bool Load(const CFilename & filename = "", bool bFastRead = false);
	bool Save(const CFilename & filename = "");
      // Clear all
	void Reset();
  	// Errors that 'GetValue' functions may return if key or section doesn't exist
	static const CStdString ms_strError;
	static const int        ms_iError;
	static const float      ms_fError;
  	// Get/Set values
	CStdString GetValue (const CStdString& strSection, const CStdString& strKey); // #ifdef INI_USE_EXEPTIONS throw CStdString
	CStdString GetValueS(const CStdString& strSection, const CStdString& strKey);
	int        GetValueI(const CStdString& strSection, const CStdString& strKey); 
	bool       GetValueB(const CStdString& strSection, const CStdString& strKey);
	float      GetValueF(const CStdString& strSection, const CStdString& strKey);
  	// No error but default value returned if section/key doesn't exists - use at your own risk
	CStdString GetValue (const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault); 
	CStdString GetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault); 
	int        GetValueI(const CStdString& strSection, const CStdString& strKey, const int       & iDefault  ); 
	bool       GetValueB(const CStdString& strSection, const CStdString& strKey, const bool      & bDefault  ); 
	float      GetValueF(const CStdString& strSection, const CStdString& strKey, const float     & fDefault  ); 
  	// beware!! 'Save' After Setting values (to save to disk)
	bool SetValue (const CStdString& strSection, const CStdString& strKey, const CStdString& strValue, bool bCreate=true);
	bool SetValue (const CStdString& strSection, const CStdString& strKey, const int       & iValue,   bool bCreate=true);
	bool SetValue (const CStdString& strSection, const CStdString& strKey, const bool      & bValue,   bool bCreate=true);
	bool SetValue (const CStdString& strSection, const CStdString& strKey, const float     & fValue,   bool bCreate=true);
	
	bool SetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& strValue, bool bCreate=true);
	bool SetValueI(const CStdString& strSection, const CStdString& strKey, const int       & iValue,   bool bCreate=true);
	bool SetValueB(const CStdString& strSection, const CStdString& strKey, const bool      & bValue,   bool bCreate=true);
	bool SetValueF(const CStdString& strSection, const CStdString& strKey, const float     & fValue,   bool bCreate=true);
  	// Sections/Keys Deletion/Retrieval
	
    bool Delete(const CStdString& strSection);
	bool Delete(const CStdString& strSection, const CStdString& strKey);
  	unsigned int GetSectionCount();
	unsigned int GetKeyCount(unsigned int      iSection);
	unsigned int GetKeyCount(const CStdString& strSection);
  	CStdString GetSection(unsigned int      iSection);
	CStdString GetKey    (unsigned int      iSection,   unsigned int iKey);
	CStdString GetKey    (const CStdString& strSection, unsigned int iKey);
  	int GetSection(const CStdString& strSection);
	int GetKey    (const CStdString& strSection, const CStdString& strKey);
	
    // Extensions
    void SetReadableExtension (const CStdString&);
    void SetEncryptedExtension(const CStdString&);
  	// Error messages
    CStdString GetLastErrorMessage();
  //------------------------------------------------------------------------------
// Private
//------------------------------------------------------------------------------
protected:
      enum E_INI_ERROR_MESSAGES
    {
        E_READ = 0,
        E_WRITE,
        E_FIND_SECTION,
        E_FIND_KEY,
        E_UNKNOWN_EXTENSION,
		E_END_DELIMITER,
        E_ERROR_MESSAGES_COUNT,
    };
      enum E_INI_COMMENTS
    {
        E_0 = 0,
        E_1,
        E_2,
        E_SPACING,
        E_COMMENTS_COUNT
    };
      enum E_INI_TYPES
    {
        E_INTEGER = 0,
        E_FLOAT,
        E_STRING,
        E_TYPES_COUNT
    };
      enum E_INI_MARKUPS
    {
        E_SECTION_BEGIN = 0,
        E_SECTION_END,
        E_KEY,
        E_MARKUPS_COUNT
    };
  	enum E_INI_TRIM
    {
        E_TRIM_0 = 0,
        E_TRIM_1,
        E_TRIM_COUNT
    };
  	enum E_INI_EXTENSIONS
    {
        E_READABLE = 0,
        E_ENCRYPTED,
        E_EXTENSIONS_COUNT
    };
  private:
  	// Constants
	static const CStdString ms_strErrorMsg	[];
	static const CStdString ms_strComment	[];
	static const CStdString ms_strType		[];
	static const CStdString ms_strMarkup	[];
	static const CStdString ms_strTrim		[];
	static const CStdString ms_strExtension	[];
	static const CStdString ms_strStringDelimiter;
  	// Data
	typedef std::map<CStdString, CStdString>	CKey;
	typedef std::map<CStdString, CKey>			CSection;
  	CSection m_data;
  	CSection::iterator	m_itSection;
	CKey::iterator		m_itKey;
  	// File
	CStdString m_strPath;
	std::istream & GetLine(std::istream&, CStdString&);
  	bool LoadReadableFile (const CFilename& strFilename = "", bool bIsReadable = true);
	bool SaveReadableFile (const CFilename& strFilename = "");
	bool SaveEncryptedFile(const CFilename& strFilename = "");
  	// String format
	CStdString ManageComments(CStdString*);
	void CleanString(CStdString*);
      // Encryption
    CStdString m_strEncryptedExtension;
    CStdString m_strReadableExtension;
  	void Decrypt(CStdString&);
	CStdString Encrypt(const CStdString&);
      // Various
	CStdString m_strLastError;
	bool m_bFastRead;
};
  //------------------------------------------------------------------------------
// Inline functions
//------------------------------------------------------------------------------
#endif // CIniFile
   |  
  
 | 
 
  
Currently browsing [inifile.zip] (62,782 bytes) - [Cpp version/CStdString.h] - (83,238 bytes)
 
 // =============================================================================
//  FILE:  StdString.h
//  AUTHOR:	Joe O'Leary (with outside help noted in comments)
//  REMARKS:
//		This header file declares the CStdStr template.  This template derives
//		the Standard C++ Library basic_string<> template and add to it the
//		the following conveniences:
//			- The full MFC CString set of functions (including implicit cast)
//			- writing to/reading from COM IStream interfaces
//			- Functional objects for use in STL algorithms
//
//		From this template, we intstantiate two classes:  CStdStringA and
//		CStdStringW.  The name "CStdString" is just a #define of one of these,
//		based upone the _UNICODE macro setting
//
//		This header also declares our own version of the MFC/ATL UNICODE-MBCS
//		conversion macros.  Our version looks exactly like the Microsoft's to
//		facilitate portability.
//
//	NOTE:
//		If you you use this in an MFC or ATL build, you should include either
//		afx.h or atlbase.h first, as appropriate.
//
//	PEOPLE WHO HAVE CONTRIBUTED TO THIS CLASS:
//
//		Several people have helped me iron out problems and othewise improve
//		this class.  OK, this is a long list but in my own defense, this code
//		has undergone two major rewrites.  Many of the improvements became
//		necessary after I rewrote the code as a template.  Others helped me
//		improve the CString facade.
//
//		Anyway, these people are (in chronological order):
//
//			- Pete the Plumber (???)
//			- Julian Selman
//			- Chris (of Melbsys)
//			- Dave Plummer
//			- John C Sipos
//			- Chris Sells
//			- Nigel Nunn
//			- Fan Xia
//			- Matthew Williams
//			- Carl Engman
//			- Mark Zeren
//			- Craig Watson
//			- Rich Zuris
//			- Karim Ratib
//			- Chris Conti
//			- Baptiste Lepilleur
//			- Greg Pickles
//			- Jim Cline
//			- Jeff Kohn
//			- Todd Heckel
//			- Ullrich Pollähne
//			- Joe Vitaterna
//			- Joe Woodbury
//
//	REVISION HISTORY
//
//	  2000-JUL-11 - Joe Woodbury noted that the CString::Find docs don't match
//					what the CString::Find code really ends up doing.   I was
//					trying to match the docs.  Now I match the CString code
//				  - Joe also caught me truncating strings for GetBuffer() calls
//					when the supplied length was less than the current length.
//
//	  2000-MAY-25 - Better support for STLPORT's Standard library distribution
//				  - Got rid of the NSP macro - it interfered with Koenig lookup
//				  - Thanks to Joe Woodbury for catching a TrimLeft() bug that
//					I introduced in January.  Empty strings were not getting
//					trimmed
//
//	  2000-APR-17 - Thanks to Joe Vitaterna for pointing out that ReverseFind
//					is supposed to be a const function.
//
//	  2000-MAR-07 - Thanks to Ullrich Pollähne for catching a range bug in one
//					of the overloads of assign.
//
//    2000-FEB-01 - You can now use CStdString on the Mac with CodeWarrior!
//					Thanks to Todd Heckel for helping out with this.
//
//	  2000-JAN-23 - Thanks to Jim Cline for pointing out how I could make the
//					Trim() function more efficient.
//				  - Thanks to Jeff Kohn for prompting me to find and fix a typo
//					in one of the addition operators that takes _bstr_t.
//				  - Got rid of the .CPP file -  you only need StdString.h now!
//
//	  1999-DEC-22 - Thanks to Greg Pickles for helping me identify a problem
//					with my implementation of CStdString::FormatV in which
//					resulting string might not be properly NULL terminated.
//
//	  1999-DEC-06 - Chris Conti pointed yet another basic_string<> assignment
//					bug that MS has not fixed.  CStdString did nothing to fix
//					it either but it does now!  The bug was: create a string
//					longer than 31 characters, get a pointer to it (via c_str())
//					and then assign that pointer to the original string object.
//					The resulting string would be empty.  Not with CStdString!
//
//	  1999-OCT-06 - BufferSet was erasing the string even when it was merely
//					supposed to shrink it.  Fixed.  Thanks to Chris Conti.
//				  - Some of the Q172398 fixes were not checking for assignment-
//					to-self.  Fixed.  Thanks to Baptiste Lepilleur.
//
//	  1999-AUG-20 - Improved Load() function to be more efficient by using 
//					SizeOfResource().  Thanks to Rich Zuris for this.
//				  - Corrected resource ID constructor, again thanks to Rich.
//				  - Fixed a bug that occurred with UNICODE characters above
//					the first 255 ANSI ones.  Thanks to Craig Watson. 
//				  - Added missing overloads of TrimLeft() and TrimRight().
//					Thanks to Karim Ratib for pointing them out
//
//	  1999-JUL-21 - Made all calls to GetBuf() with no args check length first.
//
//	  1999-JUL-10 - Improved MFC/ATL independence of conversion macros
//				  - Added SS_NO_REFCOUNT macro to allow you to disable any
//					reference-counting your basic_string<> impl. may do.
//				  - Improved ReleaseBuffer() to be as forgiving as CString.
//					Thanks for Fan Xia for helping me find this and to
//					Matthew Williams for pointing it out directly.
//
//	  1999-JUL-06 - Thanks to Nigel Nunn for catching a very sneaky bug in
//					ToLower/ToUpper.  They should call GetBuf() instead of
//					data() in order to ensure the changed string buffer is not
//					reference-counted (in those implementations that refcount).
//
//	  1999-JUL-01 - Added a true CString facade.  Now you can use CStdString as
//					a drop-in replacement for CString.  If you find this useful,
//					you can thank Chris Sells for finally convincing me to give
//					in and implement it.
//				  - Changed operators << and >> (for MFC CArchive) to serialize
//					EXACTLY as CString's do.  So now you can send a CString out
//					to a CArchive and later read it in as a CStdString.   I have
//					no idea why you would want to do this but you can. 
//
//	  1999-JUN-21 - Changed the CStdString class into the CStdStr template.
//				  - Fixed FormatV() to correctly decrement the loop counter.
//					This was harmless bug but a bug nevertheless.  Thanks to
//					Chris (of Melbsys) for pointing it out
//				  - Changed Format() to try a normal stack-based array before
//					using to _alloca().
//				  - Updated the text conversion macros to properly use code
//					pages and to fit in better in MFC/ATL builds.  In other
//					words, I copied Microsoft's conversion stuff again. 
//				  - Added equivalents of CString::GetBuffer, GetBufferSetLength
//				  - new sscpy() replacement of CStdString::CopyString()
//				  - a Trim() function that combines TrimRight() and TrimLeft().
//
//	  1999-MAR-13 - Corrected the "NotSpace" functional object to use _istpace()
//					instead of _isspace()   Thanks to Dave Plummer for this.
//
//	  1999-FEB-26 - Removed errant line (left over from testing) that #defined
//					_MFC_VER.  Thanks to John C Sipos for noticing this.
//
//	  1999-FEB-03 - Fixed a bug in a rarely-used overload of operator+() that
//					caused infinite recursion and stack overflow
//				  - Added member functions to simplify the process of
//					persisting CStdStrings to/from DCOM IStream interfaces 
//				  - Added functional objects (e.g. StdStringLessNoCase) that
//					allow CStdStrings to be used as keys STL map objects with
//					case-insensitive comparison 
//				  - Added array indexing operators (i.e. operator[]).  I
//					originally assumed that these were unnecessary and would be
//					inherited from basic_string.  However, without them, Visual
//					C++ complains about ambiguous overloads when you try to use
//					them.  Thanks to Julian Selman to pointing this out. 
//
//	  1998-FEB-?? - Added overloads of assign() function to completely account
//					for Q172398 bug.  Thanks to "Pete the Plumber" for this
//
//	  1998-FEB-?? - Initial submission
//
// COPYRIGHT:
//		1999 Joseph M. O'Leary.  This code is free.  Use it anywhere you want.
//		Rewrite it, restructure it, whatever.  Please don't blame me if it makes
//		your $30 billion dollar satellite explode in orbit.  If you redistribute
//		it in any form, I'd appreciate it if you would leave this notice here.
//
//		If you find any bugs, please let me know:
//
//				jmoleary@earthlink.net
//				http://home.earthlink.net/~jmoleary
// =============================================================================
// Avoid multiple inclusion the VC++ way,
// Turn off browser references
// Turn off unavoidable compiler warnings
#if defined(_MSC_VER) && (_MSC_VER > 1100)
	#pragma once
	#pragma component(browser, off, references, "CStdString")
	#pragma warning (disable : 4290) // C++ Exception Specification ignored
	#pragma warning (disable : 4127) // Conditional expression is constant
	#pragma warning (disable : 4097) // typedef name used as synonym for class name
	// AV - 22/08/2000
	// To avoid "identifier was truncated to '255' characters in the debug information"
	#pragma warning (disable : 4786)
  #endif
  #ifndef STDSTRING_H
#define STDSTRING_H
  
// MACRO: SS_NO_REFCOUNT:
//		turns off reference counting at the assignment level
//		I define this by default.  comment it out if you don't want it.
#define SS_NO_REFCOUNT	
  // In non-Visual C++ and/or non-Win32 builds, we can't use some cool stuff.
#if !defined(_MSC_VER) || !defined(_WIN32)
	#define SS_ANSI
#endif
  // Avoid legacy code screw up: if _UNICODE is defined, UNICODE must be as well
#if defined (_UNICODE) && !defined (UNICODE)
	#define UNICODE
#endif
#if defined (UNICODE) && !defined (_UNICODE)
	#define _UNICODE
#endif
  // -----------------------------------------------------------------------------
// MIN and MAX.  The Standard C++ template versions go by so many names (at
// at least in the MS implementation) that you never know what's available 
// -----------------------------------------------------------------------------
template<class Type>
inline const Type& SSMIN(const Type& arg1, const Type& arg2)
{
	return arg2 < arg1 ? arg2 : arg1;
}
template<class Type>
inline const Type& SSMAX(const Type& arg1, const Type& arg2)
{
	return arg2 > arg1 ? arg2 : arg1;
}
  // If they have not #included W32Base.h (part of my W32 utility library) then
// we need to define some stuff.  Otherwise, this is all defined there.
#if !defined(W32BASE_H)
  	// If they want us to use only standard C++ stuff (no Win32 stuff)
	#ifdef SS_ANSI
  		// On non-Win32 platforms, there is no TCHAR.H so define what we need
		#ifndef _WIN32
  			typedef const char*		PCSTR;
			typedef char*			PSTR;
			typedef const wchar_t*	PCWSTR;
			typedef wchar_t*		PWSTR;
			#ifdef UNICODE
				typedef wchar_t		TCHAR;
			#else
				typedef char		TCHAR;
			#endif
			typedef wchar_t			OLECHAR;
  		#else
  			#include <TCHAR.H>
			#include <WTYPES.H>
			#ifndef STRICT
				#define STRICT
			#endif
  		#endif	// #ifndef _WIN32
  		// Make sure ASSERT and verify are defined in an ANSI fashion
		#ifndef ASSERT
			#include <assert.h>
			#define ASSERT(f) assert((f))
		#endif
		#ifndef VERIFY
			#ifdef _DEBUG
				#define VERIFY(x) ASSERT((x))
			#else
				#define VERIFY(x) x
			#endif
		#endif
  	#else // #ifdef SS_ANSI
		#include <TCHAR.H>
		#include <WTYPES.H>
		#ifndef STRICT
			#define STRICT
		#endif
  		// Make sure ASSERT and verify are defined
		#ifndef ASSERT
			#include <crtdbg.h>
			#define ASSERT(f) _ASSERTE((f))
		#endif
		#ifndef VERIFY
			#ifdef _DEBUG
				#define VERIFY(x) ASSERT((x))
			#else
				#define VERIFY(x) x
			#endif
		#endif
  	#endif // #ifdef SS_ANSI
	#ifndef UNUSED
		#define UNUSED(x) x
	#endif
  #endif // #ifndef W32BASE_H
// Standard headers needed
#include <string>			// basic_string
#include <algorithm>		// for_each, etc.
#include <functional>		// for StdStringLessNoCase, et al
#include <locale>			// for various facets
// If this is a recent enough version of VC include comdef.h, so we can write
// member functions to deal with COM types & compiler support classes e.g. _bstr_t
#if defined (_MSC_VER) && (_MSC_VER >= 1100)
	#include <comdef.h>
	#define SS_INC_COMDEF		// signal that we #included MS comdef.h file
	#define STDSTRING_INC_COMDEF
	#define SS_NOTHROW __declspec(nothrow)
#else
	#define SS_NOTHROW
#endif
  #ifndef TRACE
	#define TRACE_DEFINED_HERE
	#define TRACE
#endif
  // Microsoft defines PCSTR, PCWSTR, etc, but no PCTSTR.  I hate to use the
// versions with the "L" in front of them because that's a leftover from Win 16
// days, even though it evaluates to the same thing.  Therefore, Define a PCSTR
// as an LPCTSTR.
#if !defined(PCTSTR) && !defined(PCTSTR_DEFINED)
	typedef const TCHAR*			PCTSTR;
	#define PCTSTR_DEFINED
#endif
  #if !defined(PCOLESTR) && !defined(PCOLESTR_DEFINED)
	typedef const OLECHAR*			PCOLESTR;
	#define PCOLESTR_DEFINED
#endif
  #if !defined(POLESTR) && !defined(POLESTR_DEFINED)
	typedef OLECHAR*				POLESTR;
	#define POLESTR_DEFINED
#endif
  #if !defined(PCUSTR) && !defined(PCUSTR_DEFINED)
	typedef const unsigned char*	PCUSTR;
	typedef unsigned char*			PUSTR;
	#define PCUSTR_DEFINED
#endif
  // SS_USE_FACET macro and why we need it:
//
// Since I'm a good little Standard C++ programmer, I use locales.  Thus, I
// need to make use of the use_facet<> template function here.   Unfortunately,
// this need is complicated by the fact the MS' implementation of the Standard
// C++ Library has a non-standard version of use_facet that takes more
// arguments than the standard dictates.  Since I'm trying to write CStdString
// to work with any version of the Standard library, this presents a problem.
//
// The upshot of this is that I can't do 'use_facet' directly.  The MS' docs
// tell me that I have to use a macro, _USE() instead.  Since _USE obviously
// won't be available in other implementations, this means that I have to write
// my OWN macro -- SS_USE_FACET -- that evaluates either to _USE or to the
// standard, use_facet.
//
// If you are having trouble with the SS_USE_FACET macro, in your implementation
// of the Standard C++ Library, you can define your own version of SS_USE_FACET.
#ifndef schMSG
	#define schSTR(x)	   #x
	#define schSTR2(x)	schSTR(x)
	#define schMSG(desc) message(__FILE__ "(" schSTR2(__LINE__) "):" #desc)
#endif
  #ifndef SS_USE_FACET
	// STLPort #defines a macro (__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) for
	// all MSVC builds, erroneously in my opinion.  It causes problems for
	// my SS_ANSI builds.  In my code, I always comment out that line.  You'll
	// find it in   \stlport\config\stl_msvc.h
	#if defined(__SGI_STL_PORT) && (__SGI_STL_PORT >= 0x400 )
		#if defined(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && defined(_MSC_VER)
			#ifdef SS_ANSI
				#pragma schMSG(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS defined!!)
			#endif
		#endif
		#define SS_USE_FACET(loc, fac) std::use_facet<fac >(loc)
	#elif defined(_MSC_VER )
		#define SS_USE_FACET(loc, fac) std::_USE(loc,fac)
	#else
		#define SS_USE_FACET(loc, fac) std::use_facet<fac >(loc)
	#endif
#endif
  // =============================================================================
// UNICODE/MBCS conversion macros.  Made to work just like the MFC/ATL ones.
// =============================================================================
// First define the conversion helper functions.  We define these regardless of
// any preprocessor macro settings since their names won't collide. 
#ifdef SS_ANSI // Are we doing things the standard, non-Win32 way?...
	typedef std::codecvt<wchar_t, char, mbstate_t> SSCodeCvt;
  	// Not sure if we need all these headers.   I believe ANSI says we do.
	#include <stdio.h>
	#include <stdarg.h>
	#include <wchar.h>
	#ifndef va_start
		#include <varargs.h>
	#endif
  	// StdCodeCvt - made to look like Win32 functions WideCharToMultiByte annd
	//              MultiByteToWideChar but uses locales in SS_ANSI builds
	inline PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, int nChars,
		const std::locale& loc=std::locale())
	{
		ASSERT(NULL != pA);
		ASSERT(NULL != pW);
		pW[0] = '\0';
		PSTR pBadA				= NULL;
		PWSTR pBadW				= NULL;
		SSCodeCvt::result res	= SSCodeCvt::ok;
		const SSCodeCvt& conv	= SS_USE_FACET(loc, SSCodeCvt);
		res						= conv.in(res,
										  pA, pA + nChars, pBadA,
										  pW, pW + nChars, pBadW);
		ASSERT(SSCodeCvt::ok == res);
		return pW;
	}
	inline PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, int nChars,
		const std::locale& loc=std::locale())
	{
		return StdCodeCvt(pW, (PCSTR)pA, nChars, loc);
	}
  	inline PSTR StdCodeCvt(PSTR pA, PCWSTR pW, int nChars,
		const std::locale& loc=std::locale())
	{
		ASSERT(NULL != pA);
		ASSERT(NULL != pW);
		pA[0] = '\0';
		PSTR pBadA				= NULL;
		PWSTR pBadW				= NULL;
		const SSCodeCvt& conv	= SS_USE_FACET(loc, SSCodeCvt);
		SSCodeCvt::result res	= SSCodeCvt::ok;
		res						= conv.out(res,
										   pW, pW + nChars, pBadW,
										   pA, pA + nChars, pBadA);
		ASSERT(SSCodeCvt::ok == res);
		return pA;
	}
	inline PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, int nChars,
		const std::locale& loc=std::locale())
	{
		return (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, loc);
	}
  #else   // ...or are we doing things assuming win32 and Visual C++?
	#include <malloc.h>	// needed for _alloca
	inline PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, int nChars, UINT acp=CP_ACP)
	{
		ASSERT(NULL != pA);
		ASSERT(NULL != pW);
		pW[0] = '\0';
		MultiByteToWideChar(acp, 0, pA, -1, pW, nChars);
		return pW;
	}
	inline PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, int nChars, UINT acp=CP_ACP)
	{
		return StdCodeCvt(pW, (PCSTR)pA, nChars, acp);
	}
  	inline PSTR StdCodeCvt(PSTR pA, PCWSTR pW, int nChars, UINT acp=CP_ACP)
	{
		ASSERT(NULL != pA);
		ASSERT(NULL != pW);
		pA[0] = '\0';
		WideCharToMultiByte(acp, 0, pW, -1, pA, nChars, NULL, NULL);
		return pA;
	}
	inline PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, int nChars, UINT acp=CP_ACP)
	{
		return (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, acp);
	}
  	// Define our conversion macros to look exactly like Microsoft's to
	// facilitate using this stuff both with and without MFC/ATL
	#ifdef _CONVERSION_USES_THREAD_LOCALE
		#ifndef _DEBUG
			#define SSCVT int _cvt; _cvt; UINT _acp=GetACP(); \
				_acp; PCWSTR _pw; _pw; PCSTR _pa; _pa
		#else
			#define SSCVT int _cvt = 0; _cvt; UINT _acp=GetACP();\
				 _acp; PCWSTR _pw=NULL; _pw; PCSTR _pa=NULL; _pa
		#endif
	#else
		#ifndef _DEBUG
			#define SSCVT int _cvt; _cvt; UINT _acp=CP_ACP; _acp;\
				 PCWSTR _pw; _pw; PCSTR _pa; _pa
		#else
			#define SSCVT int _cvt = 0; _cvt; UINT _acp=CP_ACP; \
				_acp; PCWSTR _pw=NULL; _pw; PCSTR _pa=NULL; _pa
		#endif
	#endif
  	#ifdef _CONVERSION_USES_THREAD_LOCALE
		#define SSA2W(pa) (\
			((_pa = pa) == NULL) ? NULL : (\
				_cvt = (strlen(_pa)+1),\
				StdCodeCvt((PWSTR) _alloca(_cvt*2), _pa, _cvt, _acp)))
		#define SSW2A(pw) (\
			((_pw = pw) == NULL) ? NULL : (\
				_cvt = (wcslen(_pw)+1)*2,\
				StdW2AHelper((LPSTR) _alloca(_cvt), _pw, _cvt, _acp)))
	#else
		#define SSA2W(pa) (\
			((_pa = pa) == NULL) ? NULL : (\
				_cvt = (strlen(_pa)+1),\
				StdCodeCvt((PWSTR) _alloca(_cvt*2), _pa, _cvt)))
		#define SSW2A(pw) (\
			((_pw = pw) == NULL) ? NULL : (\
				_cvt = (wcslen(_pw)+1)*2,\
				StdCodeCvt((LPSTR) _alloca(_cvt), _pw, _cvt)))
	#endif
  	#define SSA2CW(pa) ((PCWSTR)SSA2W((pa)))
	#define SSW2CA(pw) ((PCSTR)SSW2A((pw)))
  	#ifdef UNICODE
		#define SST2A	SSW2A
		#define SSA2T	SSA2W
		#define SST2CA	SSW2CA
		#define SSA2CT	SSA2CW
		inline PWSTR	SST2W(PTSTR p)			{ return p; }
		inline PTSTR	SSW2T(PWSTR p)			{ return p; }
		inline PCWSTR	SST2CW(PCTSTR p)		{ return p; }
		inline PCTSTR	SSW2CT(PCWSTR p)		{ return p; }
	#else
		#define SST2W	SSA2W
		#define SSW2T	SSW2A
		#define SST2CW	SSA2CW
		#define SSW2CT	SSW2CA
		inline PSTR		SST2A(PTSTR p)			{ return p; }
		inline PTSTR	SSA2T(PSTR p)			{ return p; }
		inline PCSTR	SST2CA(PCTSTR p)		{ return p; }
		inline PCTSTR	SSA2CT(PCSTR p)			{ return p; }
	#endif // #ifdef UNICODE
	#if defined(UNICODE)
	// in these cases the default (TCHAR) is the same as OLECHAR
		inline PCOLESTR	SST2COLE(PCTSTR p)		{ return p; }
		inline PCTSTR	SSOLE2CT(PCOLESTR p)	{ return p; }
		inline POLESTR	SST2OLE(PTSTR p)		{ return p; }
		inline PTSTR	SSOLE2T(POLESTR p)		{ return p; }
	#elif defined(OLE2ANSI)
	// in these cases the default (TCHAR) is the same as OLECHAR
		inline PCOLESTR	SST2COLE(PCTSTR p)		{ return p; }
		inline PCTSTR	SSOLE2CT(PCOLESTR p)	{ return p; }
		inline POLESTR	SST2OLE(PTSTR p)		{ return p; }
		inline PTSTR	SSOLE2T(POLESTR p)		{ return p; }
	#else
		//CharNextW doesn't work on Win95 so we use this
		#define SST2COLE(pa)	SSA2CW((pa))
		#define SST2OLE(pa)		SSA2W((pa))
		#define SSOLE2CT(po)	SSW2CA((po))
		#define SSOLE2T(po)		SSW2A((po))
	#endif
  	#ifdef OLE2ANSI
		#define SSW2OLE		SSW2A
		#define SSOLE2W		SSA2W
		#define SSW2COLE	SSW2CA
		#define SSOLE2CW	SSA2CW
		inline POLESTR		SSA2OLE(PSTR p)		{ return p; }
		inline PSTR			SSOLE2A(POLESTR p)	{ return p; }
		inline PCOLESTR		SSA2COLE(PCSTR p)	{ return p; }
		inline PCSTR		SSOLE2CA(PCOLESTR p){ return p; }
	#else
		#define SSA2OLE		SSA2W
		#define SSOLE2A		SSW2A
		#define SSA2COLE	SSA2CW
		#define SSOLE2CA	SSW2CA
		inline POLESTR		SSW2OLE(PWSTR p)	{ return p; }
		inline PWSTR		SSOLE2W(POLESTR p)	{ return p; }
		inline PCOLESTR		SSW2COLE(PCWSTR p)	{ return p; }
		inline PCWSTR		SSOLE2CW(PCOLESTR p){ return p; }
	#endif
  	// Above we've defined macros that look like MS' but all have
	// an 'SS' prefix.  Now we need the real macros.  We'll either
	// get them from the macros above or from MFC/ATL.  If
	// SS_NO_CONVERSION is #defined, we'll forgo them
	#ifndef SS_NO_CONVERSION
  		#if defined (USES_CONVERSION)
  			#define _NO_STDCONVERSION	// just to be consistent
		#else
  			#ifdef _MFC_VER
  				#include <afxconv.h>
				#define _NO_STDCONVERSION // just to be consistent
			#else
  				#define USES_CONVERSION SSCVT
				#define A2CW			SSA2CW
				#define W2CA			SSW2CA
				#define T2A				SST2A
				#define A2T				SSA2T
				#define T2W				SST2W
				#define W2T				SSW2T
				#define T2CA			SST2CA
				#define A2CT			SSA2CT
				#define T2CW			SST2CW
				#define W2CT			SSW2CT
				#define ocslen			sslen
				#define ocscpy			sscpy
				#define T2COLE			SST2COLE
				#define OLE2CT			SSOLE2CT
				#define T2OLE			SST2COLE
				#define OLE2T			SSOLE2CT
				#define A2OLE			SSA2OLE
				#define OLE2A			SSOLE2A
				#define W2OLE			SSW2OLE
				#define OLE2W			SSOLE2W
				#define A2COLE			SSA2COLE
				#define OLE2CA			SSOLE2CA
				#define W2COLE			SSW2COLE
				#define OLE2CW			SSOLE2CW
		
			#endif // #ifdef _MFC_VER
		#endif // #ifndef USES_CONVERSION
	#endif // #ifndef SS_NO_CONVERSION
	// Define ostring - generic name for std::basic_string<OLECHAR>
	#if !defined(ostring) && !defined(OSTRING_DEFINED)
		typedef std::basic_string<OLECHAR> ostring;
		#define OSTRING_DEFINED
	#endif
  #endif // #ifndef SS_ANSI
// StdCodeCvt when there's no conversion to be done
inline PSTR StdCodeCvt(PSTR pDst, PCSTR pSrc, int nChars)
{
	pDst[0]				= '\0';
	std::char_traits<char>().copy(pDst, pSrc, nChars);
	if ( nChars > 0 )
		pDst[nChars]	= '\0';
  	return pDst;
}
inline PSTR StdCodeCvt(PSTR pDst, PCUSTR pSrc, int nChars)
{
	return StdCodeCvt(pDst, (PCSTR)pSrc, nChars);
}
inline PUSTR StdCodeCvt(PUSTR pDst, PCSTR pSrc, int nChars)
{
	return (PUSTR)StdCodeCvt((PSTR)pDst, pSrc, nChars);
}
  inline PWSTR StdCodeCvt(PWSTR pDst, PCWSTR pSrc, int nChars)
{
	pDst[0]				= '\0';
	std::char_traits<wchar_t>().copy(pDst, pSrc, nChars);
	if ( nChars > 0 )
		pDst[nChars]	= '\0';
  	return pDst;
}
  
// Define tstring -- generic name for std::basic_string<TCHAR>
#if !defined(tstring) && !defined(TSTRING_DEFINED)
	typedef std::basic_string<TCHAR> tstring;
	#define TSTRING_DEFINED
#endif
  // a very shorthand way of applying the fix for KB problem Q172398
// (basic_string assignment bug)
#if defined ( _MSC_VER ) && ( _MSC_VER < 1200 )
	#define Q172398(x) (x).erase()
#else
	#define Q172398(x)
#endif
  // =============================================================================
// INLINE FUNCTIONS ON WHICH CSTDSTRING RELIES
//
// Usually for generic text mapping, we rely on preprocessor macro definitions
// to map to string functions.  However the CStdStr<> template cannot use
// macro-based generic text mappings because its character types do not get
// resolved until template processing which comes AFTER macro processing.  In
// other words, UNICODE is of little help to us in the CStdStr template
//
// Therefore, to keep the CStdStr declaration simple, we have these inline
// functions.  The template calls them often.  Since they are inline (and NOT
// exported when this is built as a DLL), they will probably be resolved away
// to nothing. 
//
// Without these functions, the CStdStr<> template would probably have to broken
// out into two, almost identical classes.  Either that or it would be a huge,
// convoluted mess, with tons of "if" statements all over the place checking the
// size of template parameter CT.
// 
// In several cases, you will see two versions of each function.  One version is
// the more portable, standard way of doing things, while the other is the
// non-standard, but often significantly faster Visual C++ way.
// =============================================================================
// If they defined SS_NO_REFCOUNT, then we must convert all assignments
#ifdef SS_NO_REFCOUNT
	#define SSREF(x) (x).c_str()
#else
	#define SSREF(x) (x)
#endif
  // -----------------------------------------------------------------------------
// sslen: strlen/wcslen wrappers
// -----------------------------------------------------------------------------
template<typename CT> inline int sslen(const CT* pT)
{
	return NULL == pT ? 0 : std::char_traits<CT>::length(pT);
}
inline SS_NOTHROW int sslen(const std::string& s)
{
	return s.length();
}
inline SS_NOTHROW int sslen(const std::wstring& s)
{
	return s.length();
}
  
// -----------------------------------------------------------------------------
// ssasn: assignment functions -- assign "sSrc" to "sDst"
// -----------------------------------------------------------------------------
typedef std::string::size_type		SS_SIZETYPE; // just for shorthand, really
typedef std::string::pointer		SS_PTRTYPE;  
typedef std::wstring::size_type		SW_SIZETYPE;
typedef std::wstring::pointer		SW_PTRTYPE;  
  inline void	ssasn(std::string& sDst, const std::string& sSrc)
{
	if ( sDst.c_str() != sSrc.c_str() )
	{
		sDst.erase();
		sDst.assign(SSREF(sSrc));
	}
}
inline void	ssasn(std::string& sDst, PCSTR pA)
{
	// Watch out for NULLs, as always.
	if ( NULL == pA )
	{
		sDst.erase();
	}
  	// If pA actually points to part of sDst, we must NOT erase(), but
	// rather take a substring
	else if ( pA >= sDst.c_str() && pA <= sDst.c_str() + sDst.size() )
	{
		sDst =sDst.substr(static_cast<SS_SIZETYPE>(pA-sDst.c_str()));
	}
  	// Otherwise (most cases) apply the assignment bug fix, if applicable
	// and do the assignment
	else
	{
		Q172398(sDst);
		sDst.assign(pA);
	}
}
inline void	ssasn(std::string& sDst, const std::wstring& sSrc)
{
#ifdef SS_ANSI
	int nLen	= sSrc.size();
	sDst.resize(0);
	sDst.resize(nLen);
	StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()), sSrc.c_str(), nLen);
#else
	SSCVT;
	sDst.assign(SSW2CA(sSrc.c_str()));
#endif
}
inline void	ssasn(std::string& sDst, PCWSTR pW)
{
#ifdef SS_ANSI
	int nLen	= sslen(pW);
	sDst.resize(0);
	sDst.resize(nLen);
	StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()), pW, nLen);
#else
	SSCVT;
	sDst.assign(pW ? SSW2CA(pW) : "");
#endif
}
inline void ssasn(std::string& sDst, const int nNull)
{
	UNUSED(nNull);
	ASSERT(nNull==NULL);
	sDst.assign("");
}	
inline void	ssasn(std::wstring& sDst, const std::wstring& sSrc)
{
	if ( sDst.c_str() != sSrc.c_str() )
	{
		sDst.erase();
		sDst.assign(SSREF(sSrc));
	}
}
inline void	ssasn(std::wstring& sDst, PCWSTR pW)
{
	// Watch out for NULLs, as always.
	if ( NULL == pW )
	{
		sDst.erase();
	}
  	// If pW actually points to part of sDst, we must NOT erase(), but
	// rather take a substring
	else if ( pW >= sDst.c_str() && pW <= sDst.c_str() + sDst.size() )
	{
		sDst = sDst.substr(static_cast<SW_SIZETYPE>(pW-sDst.c_str()));
	}
  	// Otherwise (most cases) apply the assignment bug fix, if applicable
	// and do the assignment
	else
	{
		Q172398(sDst);
		sDst.assign(pW);
	}
}
#undef StrSizeType
inline void	ssasn(std::wstring& sDst, const std::string& sSrc)
{
#ifdef SS_ANSI
	int nLen	= sSrc.size();
	sDst.resize(0);
	sDst.resize(nLen);
	StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()), sSrc.c_str(), nLen);
#else
	SSCVT;
	sDst.assign(SSA2CW(sSrc.c_str()));
#endif
}
inline void	ssasn(std::wstring& sDst, PCSTR pA)
{
#ifdef SS_ANSI
	int nLen	= sslen(pA);
	sDst.resize(0);
	sDst.resize(nLen);
	StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()), pA, nLen);
#else
	SSCVT;
	sDst.assign(pA ? SSA2CW(pA) : L"");
#endif
}
inline void ssasn(std::wstring& sDst, const int nNull)
{
	UNUSED(nNull);
	ASSERT(nNull==NULL);
	sDst.assign(L"");
}
  
// -----------------------------------------------------------------------------
// ssadd: string object concatenation -- add second argument to first
// -----------------------------------------------------------------------------
inline void	ssadd(std::string& sDst, const std::wstring& sSrc)
{
#ifdef SS_ANSI
	int nLen	= sSrc.size();
	sDst.resize(sDst.size() + nLen);
	StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()+nLen), sSrc.c_str(), nLen);
#else
	SSCVT; 
	sDst.append(SSW2CA(sSrc.c_str())); 
#endif
}
inline void	ssadd(std::string& sDst, const std::string& sSrc)
{ 
	sDst.append(sSrc.c_str());
}
inline void	ssadd(std::string& sDst, PCWSTR pW)
{
#ifdef SS_ANSI
	int nLen	= sslen(pW);
	sDst.resize(sDst.size() + nLen);
	StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()+nLen), pW, nLen);
#else
	SSCVT;
	if ( NULL != pW )
		sDst.append(SSW2CA(pW)); 
#endif
}
inline void	ssadd(std::string& sDst, PCSTR pA)
{
	if ( pA )
		sDst.append(pA); 
}
inline void	ssadd(std::wstring& sDst, const std::wstring& sSrc)
{
	sDst.append(sSrc.c_str());
}
inline void	ssadd(std::wstring& sDst, const std::string& sSrc)
{
#ifdef SS_ANSI
	int nLen	= sSrc.size();
	sDst.resize(sDst.size() + nLen);
	StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()+nLen), sSrc.c_str(), nLen);
#else
	SSCVT;
	sDst.append(SSA2CW(sSrc.c_str()));
#endif
}
inline void	ssadd(std::wstring& sDst, PCSTR pA)
{
#ifdef SS_ANSI
	int nLen	= sslen(pA);
	sDst.resize(sDst.size() + nLen);
	StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()+nLen), pA, nLen);
#else
	SSCVT;
	if ( NULL != pA )
		sDst.append(SSA2CW(pA));
#endif
}
inline void	ssadd(std::wstring& sDst, PCWSTR pW)
{
	if ( pW )
		sDst.append(pW);
}
  
// -----------------------------------------------------------------------------
// ssicmp: comparison (case insensitive )
// -----------------------------------------------------------------------------
#ifdef SS_ANSI
	template<typename CT>
	inline int ssicmp(const CT* pA1, const CT* pA2)
	{
		std::locale loc;
		const std::ctype<CT>& ct = SS_USE_FACET(loc, std::ctype<CT>);
		CT f;
		CT l;
              do 
			{
				f = ct.tolower(*(pA1++));
				l = ct.tolower(*(pA2++));
            } while ( (f) && (f == l) );
          return (int)(f - l);
	}
#else
	#ifdef _MBCS
		inline long sscmp(PCSTR pA1, PCSTR pA2)
		{
			return _mbscmp((PCUSTR)pA1, (PCUSTR)pA2);
		}
		inline long ssicmp(PCSTR pA1, PCSTR pA2)
		{
			return _mbsicmp((PCUSTR)pA1, (PCUSTR)pA2);
		}
	#else
		inline long sscmp(PCSTR pA1, PCSTR pA2)
		{
			return strcmp(pA1, pA2);
		}
		inline long ssicmp(PCSTR pA1, PCSTR pA2)
		{
			return _stricmp(pA1, pA2);
		}
	#endif
	inline long sscmp(PCWSTR pW1, PCWSTR pW2)
	{
		return wcscmp(pW1, pW2);
	}
	inline long ssicmp(PCWSTR pW1, PCWSTR pW2)
	{
		return _wcsicmp(pW1, pW2);
	}
#endif
  // -----------------------------------------------------------------------------
// ssupr/sslwr: Uppercase/Lowercase conversion functions
// -----------------------------------------------------------------------------
#ifdef SS_ANSI
	template<typename CT>
	inline void sslwr(CT* pT, size_t nLen)
	{
		SS_USE_FACET(std::locale(), std::ctype<CT>).tolower(pT, pT+nLen);
	}
	template<typename CT>
	inline void ssupr(CT* pT, size_t nLen)
	{
		SS_USE_FACET(std::locale(), std::ctype<CT>).toupper(pT, pT+nLen);
	}
#else  // #else we must be on Win32
	#ifdef _MBCS
		inline void	ssupr(PSTR pA, size_t /*nLen*/)
		{
			_mbsupr((PUSTR)pA);
		}
		inline void	sslwr(PSTR pA, size_t /*nLen*/)
		{
			_mbslwr((PUSTR)pA);
		}
	#else
		inline void	ssupr(PSTR pA, size_t /*nLen*/)
		{
			_strupr(pA); 
		}
		inline void	sslwr(PSTR pA, size_t /*nLen*/)
		{
			_strlwr(pA);
		}
	#endif
	inline void	ssupr(PWSTR pW, size_t /*nLen*/)	
	{
		_wcsupr(pW);
	}
	inline void	sslwr(PWSTR pW, size_t /*nLen*/)	
	{
		_wcslwr(pW);
	}
#endif // #ifdef SS_ANSI
// -----------------------------------------------------------------------------
//  vsprintf/vswprintf or _vsnprintf/_vsnwprintf equivalents.  In standard
//  builds we can't use _vsnprintf/_vsnwsprintf because they're MS extensions.
// -----------------------------------------------------------------------------
#ifdef SS_ANSI
	inline int ssvsprintf(PSTR pA, size_t /*nCount*/, PCSTR pFmtA, va_list vl)
	{
		return vsprintf(pA, pFmtA, vl);
	}
	inline int ssvsprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl)
	{
	#ifdef __MWERKS__
		return vswprintf(pW, nCount, pFmtW, vl);
	#else
		nCount;
		return vswprintf(pW, pFmtW, vl);
	#endif
	}
	inline int ssvsprintf(PWSTR pW, PCWSTR pFmtW, va_list vl)
	{
		return vswprintf(pW, pFmtW, vl);
	}
#else
	inline int	ssnprintf(PSTR pA, size_t nCount, PCSTR pFmtA, va_list vl)
	{ 
		return _vsnprintf(pA, nCount, pFmtA, vl);
	}
	inline int	ssnprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl)
	{
		return _vsnwprintf(pW, nCount, pFmtW, vl);
	}
#endif
  
// -----------------------------------------------------------------------------
// ssload: Type safe, overloaded ::LoadString wrappers
// There is no equivalent of these in non-Win32-specific builds.  However, I'm
// thinking that with the message facet, there might eventually be one
// -----------------------------------------------------------------------------
#ifdef SS_ANSI
#else
	inline int ssload(HMODULE hInst, UINT uId, PSTR pBuf, int nMax)
	{
		return ::LoadStringA(hInst, uId, pBuf, nMax);
	}
	inline int ssload(HMODULE hInst, UINT uId, PWSTR pBuf, int nMax)
	{
		return ::LoadStringW(hInst, uId, pBuf, nMax);
	}
#endif
  
// -----------------------------------------------------------------------------
// sscoll/ssicoll: Collation wrappers
// -----------------------------------------------------------------------------
#ifdef SS_ANSI
	template <typename CT>
	inline int sscoll(const CT* sz1, int nLen1, const CT* sz2, int nLen2)
	{
		const std::collate<CT>& coll =
			SS_USE_FACET(std::locale(), std::collate<CT>);
		return coll.compare(sz1, sz1+nLen1, sz2, sz2+nLen2);
	}
	template <typename CT>
	inline int ssicoll(const CT* sz1, int nLen1, const CT* sz2, int nLen2)
	{
		const std::locale loc;
		const std::collate<CT>& coll = SS_USE_FACET(loc, std::collate<CT>);
  		std::collate<CT>::string_type s1(sz1);
		std::collate<CT>::string_type s2(sz2);
  		sslwr(const_cast<CT*>(s1.c_str()), nLen1);
		sslwr(const_cast<CT*>(s2.c_str()), nLen2);
		return coll.compare(s1.c_str(), s1.c_str()+nLen1,
							s2.c_str(), s2.c_str()+nLen2);
	}
#else
	#ifdef _MBCS
		inline int sscoll(PCSTR sz1, int /*nLen1*/, PCSTR sz2, int /*nLen2*/)
		{
			return _mbscoll((PCUSTR)sz1, (PCUSTR)sz2);
		}
		inline int ssicoll(PCSTR sz1, int /*nLen1*/, PCSTR sz2, int /*nLen2*/)
		{
			return _mbsicoll((PCUSTR)sz1, (PCUSTR)sz2);
		}
	#else
		inline int sscoll(PCSTR sz1, int /*nLen1*/, PCSTR sz2, int /*nLen2*/)
		{
			return strcoll(sz1, sz2);
		}
		inline int ssicoll(PCSTR sz1, int /*nLen1*/, PCSTR sz2, int /*nLen2*/)
		{
			return _stricoll(sz1, sz2);
		}
	#endif
	inline int sscoll(PCWSTR sz1, int /*nLen1*/, PCWSTR sz2, int /*nLen2*/)
	{
		return wcscoll(sz1, sz2);
	}
	inline int ssicoll(PCWSTR sz1, int /*nLen1*/, PCWSTR sz2, int /*nLen2*/)
	{
		return _wcsicoll(sz1, sz2);
	}
#endif
  
// -----------------------------------------------------------------------------
// ssfmtmsg: FormatMessage equivalents.  Needed because I added a CString facade
// Again -- no equivalent of these on non-Win32 builds but their might one day
// be one if the message facet gets implemented
// -----------------------------------------------------------------------------
#ifdef SS_ANSI
#else
	inline DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId,
						  DWORD dwLangId, PSTR pBuf, DWORD nSize,
						  va_list* vlArgs)
	{ 
		return FormatMessageA(dwFlags, pSrc, dwMsgId, dwLangId,
							  pBuf, nSize,vlArgs);
	}
	inline DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId,
						  DWORD dwLangId, PWSTR pBuf, DWORD nSize,
						  va_list* vlArgs)
	{
		return FormatMessageW(dwFlags, pSrc, dwMsgId, dwLangId,
							  pBuf, nSize,vlArgs);
	}
#endif
 
  
// FUNCTION: sscpy.  Copies up to 'nMax' characters from pSrc to pDst.
// -----------------------------------------------------------------------------
// FUNCTION:  sscpy
//		inline int sscpy(PSTR pDst, PCSTR pSrc, int nMax=-1);
//		inline int sscpy(PUSTR pDst,  PCSTR pSrc, int nMax=-1)
//		inline int sscpy(PSTR pDst, PCWSTR pSrc, int nMax=-1);
//		inline int sscpy(PWSTR pDst, PCWSTR pSrc, int nMax=-1);
//		inline int sscpy(PWSTR pDst, PCSTR pSrc, int nMax=-1);
//
// DESCRIPTION:
//		This function is very much (but not exactly) like strcpy.  These
//		overloads simplify copying one C-style string into another by allowing
//		the caller to specify two different types of strings if necessary.
//
//		The strings must NOT overlap
//
//		"Character" is expressed in terms of the destination string, not
//		the source.  If no 'nMax' argument is supplied, then the number of
//		characters copied will be sslen(pSrc).  A NULL terminator will
//		also be added so pDst must actually be big enough to hold nMax+1
//		characters.  The return value is the number of characters copied,
//		not including the NULL terminator.
//
// PARAMETERS: 
//		pSrc - the string to be copied FROM.  May be a char based string, an
//			   MBCS string (in Win32 builds) or a wide string (wchar_t).
//		pSrc - the string to be copied TO.  Also may be either MBCS or wide
//		nMax - the maximum number of characters to be copied into szDest.  Note
//			   that this is expressed in whatever a "character" means to pDst.
//			   If pDst is a wchar_t type string than this will be the maximum
//			   number of wchar_ts that my be copied.  The pDst string must be
//			   large enough to hold least nMaxChars+1 characters.
//			   If the caller supplies no argument for nMax this is a signal to
//			   the routine to copy all the characters in pSrc, regardless of
//			   how long it is.
//
// RETURN VALUE: none
// -----------------------------------------------------------------------------
template<typename CT1, typename CT2>
inline int sscpycvt(CT1* pDst, const CT2* pSrc, int nChars)
{
	StdCodeCvt(pDst, pSrc, nChars);
	pDst[SSMAX(nChars, 0)]	= '\0';
	return nChars;
}
  template<typename CT1, typename CT2>
inline int sscpy(CT1* pDst, const CT2* pSrc, int nMax, int nLen)
{
	return sscpycvt(pDst, pSrc, SSMIN(nMax, nLen));
}
template<typename CT1, typename CT2>
inline int sscpy(CT1* pDst, const CT2* pSrc, int nMax)
{
	return sscpycvt(pDst, pSrc, SSMIN(nMax, sslen(pSrc)));
}
template<typename CT1, typename CT2>
inline int sscpy(CT1* pDst, const CT2* pSrc)
{
	return sscpycvt(pDst, pSrc, sslen(pSrc));
}
template<typename CT1, typename CT2>
inline int sscpy(CT1* pDst, const std::basic_string<CT2>& sSrc, int nMax)
{
	return sscpycvt(pDst, sSrc.c_str(), SSMIN(nMax, (int)sSrc.length()));
}
template<typename CT1, typename CT2>
inline int sscpy(CT1* pDst, const std::basic_string<CT2>& sSrc)
{
	return sscpycvt(pDst, sSrc.c_str(), (int)sSrc.length());
}
 
 
 
 
  // -----------------------------------------------------------------------------
// Functional objects for changing case.  They also let you pass locales
// -----------------------------------------------------------------------------
#ifdef SS_ANSI
	template<typename CT>
	struct SSToUpper : public std::binary_function<CT, std::locale, CT>
	{
		inline CT operator()(const CT& t, const std::locale& loc) const
		{
			return std::toupper<CT>(t, loc);
		}
	};
	template<typename CT>
	struct SSToLower : public std::binary_function<CT, std::locale, CT>
	{
		inline CT operator()(const CT& t, const std::locale& loc) const
		{
			return std::tolower<CT>(t, loc);
		}
	};
#endif
  // struct SSSHDR - useful for non Std C++ persistence schemes.
typedef struct SSSHDR
{
	BYTE	byCtrl;
	ULONG	nChars;
} SSSHDR;	// as in "Standard String Stream Header"
// This struct is used for TrimRight() and TrimLeft() function implementations.
//template<typename CT>
//struct NotSpace : public std::unary_function<CT, bool>
//{
//	const std::locale& loc;
//	inline NotSpace(const std::locale& locArg) : loc(locArg) {}
//	inline bool operator() (CT t) { return !std::isspace(t, loc); }
//};
template<typename CT>
struct NotSpace : public std::unary_function<CT, bool>
{
	const std::locale& loc;
	NotSpace(const std::locale& locArg) : loc(locArg) {}
  	// DINKUMWARE BUG:
	// Note -- using std::isspace in a COM DLL gives us access violations
	// because it causes the dynamic addition of a function to be called
	// when the library shuts down.  Unfortunately the list is maintained
	// in DLL memory but the function is in static memory.  So the COM DLL
	// goes away along with the function that was supposed to be called,
	// and then later when the DLL CRT shuts down it unloads the list and
	// tries to call the long-gone function.
	// This is DinkumWare's implementation problem.  Until then, we will
	// use good old isspace and iswspace from the CRT unless they
	// specify SS_ANSI
#ifdef SS_ANSI
	bool operator() const (CT t) { return !std::isspace(t, loc); }
#else
	bool ssisp(char c) const { return FALSE != ::isspace((int) c); }
	bool ssisp(wchar_t c) const { return FALSE != ::iswspace((wint_t) c); }
	bool operator()(CT t) const  { return !ssisp(t); }
#endif
};
 
 
  
//			Now we can define the template (finally!)
// =============================================================================
// TEMPLATE: CStdStr
//		template<typename CT> class CStdStr : public std::basic_string<CT>
//
// REMARKS:
//		This template derives from basic_string<CT> and adds some MFC CString-
//		like functionality
//
//		Basically, this is my attempt to make Standard C++ library strings as
//		easy to use as the MFC CString class.
//
//		Note that although this is a template, it makes the assumption that the
//		template argument (CT, the character type) is either char or wchar_t.  
// =============================================================================
//#define CStdStr _SS	// avoid compiler warning 4786
  template<typename CT>
class CStdStr : public std::basic_string<CT>
{
	// Typedefs for shorter names.  Using these names also appears to help
	// us avoid some ambiguities that otherwise arise on some platforms
	typedef typename std::basic_string<CT>	MYBASE;	 // my base class
	typedef CStdStr<CT>						MYTYPE;	 // myself
	typedef typename MYBASE::const_pointer	PCMYSTR; // PCSTR or PCWSTR 
	typedef typename MYBASE::pointer		PMYSTR;	 // PSTR or PWSTR
	typedef typename MYBASE::iterator		MYITER;  // my iterator type
	typedef typename MYBASE::const_iterator	MYCITER; // you get the idea...
	typedef typename MYBASE::size_type		MYSIZE;   
	typedef typename MYBASE::value_type		MYVAL; 
	typedef typename MYBASE::allocator_type	MYALLOC;
	
  public:
  	// shorthand conversion from PCTSTR to string resource ID
	#define _TRES(pctstr) (LOWORD((DWORD)(pctstr)))	
  	// CStdStr inline constructors
	CStdStr()
	{
	}
  	CStdStr(const MYTYPE& str) : MYBASE(SSREF(str))
	{
	}
  	CStdStr(const std::string& str)
	{
		ssasn(*this, SSREF(str));
	}
  	CStdStr(const std::wstring& str)
	{
		ssasn(*this, SSREF(str));
	}
  	CStdStr(PCMYSTR pT, MYSIZE n) : MYBASE(pT, n)
	{
	}
  	CStdStr(PCSTR pA)
	{
	#ifdef SS_ANSI
		*this = pA;
	#else
		if ( NULL != HIWORD(pA) )
			*this = pA;
		else if ( NULL != pA && !Load(_TRES(pA)) )
			TRACE(_T("Can't load string %u\n"), _TRES(pA));
	#endif
	}
  	CStdStr(PCWSTR pW)
	{
	#ifdef SS_ANSI
		*this = pW;
	#else
		if ( NULL != HIWORD(pW) )
			*this = pW;
		else if ( NULL != pW && !Load(_TRES(pW)) )
			TRACE(_T("Can't load string %u\n"), _TRES(pW));
	#endif
	}
  	CStdStr(MYCITER first, MYCITER last)
		: MYBASE(first, last)
	{
	}
  	CStdStr(MYSIZE nSize, MYVAL ch, const MYALLOC& al=MYALLOC())
		: MYBASE(nSize, ch, al)
	{
	}
  	#ifdef SS_INC_COMDEF
		CStdStr(const _bstr_t& bstr)
		{
			*this = static_cast<PCTSTR>(bstr);
		}
	#endif
  	// CStdStr inline assignment operators -- the ssasn function now takes care
	// of fixing  the MSVC assignment bug (see knowledge base article Q172398).
	MYTYPE& operator=(const MYTYPE& str)
	{ 
		ssasn(*this, str); 
		return *this;
	}
  	MYTYPE& operator=(const std::string& str)
	{
		ssasn(*this, str);
		return *this;
	}
  	MYTYPE& operator=(const std::wstring& str)
	{
		ssasn(*this, str);
		return *this;
	}
  	MYTYPE& operator=(PCSTR pA)
	{
		ssasn(*this, pA);
		return *this;
	}
  	MYTYPE& operator=(PCWSTR pW)
	{
		ssasn(*this, pW);
		return *this;
	}
  	MYTYPE& operator=(CT t)
	{
		Q172398(*this);
		MYBASE::assign(1, t);
		return *this;
	}
  	#ifdef SS_INC_COMDEF
		MYTYPE& operator=(const _bstr_t& bstr)
		{
			return operator=(static_cast<const CT*>(bstr));
		}
	#endif
  
	// Overloads  also needed to fix the MSVC assignment bug (KB: Q172398)
	//  *** Thanks to Pete The Plumber for catching this one ***
	// They also are compiled if you have explicitly turned off refcounting
	#if ( defined(_MSC_VER) && ( _MSC_VER < 1200 ) ) || defined(SS_NO_REFCOUNT) 
  		MYTYPE& assign(const MYTYPE& str)
		{
			ssasn(*this, str);
			return *this;
		}
  		MYTYPE& assign(const MYTYPE& str, MYSIZE nStart, MYSIZE nChars)
		{
			// This overload of basic_string::assign is supposed to assign up to
			// <nChars> or the NULL terminator, whichever comes first.  Since we
			// are about to call a less forgiving overload (in which <nChars>
			// must be a valid length), we must adjust the length here to a safe
			// value.  Thanks to Ullrich Pollähne for catching this bug
			nChars		= SSMIN(nChars, str.length() - nStart);
  			// Watch out for assignment to self
			if ( this == &str )
			{
				MYTYPE strTemp(str.c_str()+nStart, nChars);
				assign(strTemp);
			}
			else
			{
				Q172398(*this);
				MYBASE::assign(str.c_str()+nStart, nChars);
			}
			return *this;
		}
  		MYTYPE& assign(const MYBASE& str)
		{
			ssasn(*this, str);
			return *this;
		}
  		MYTYPE& assign(const MYBASE& str, MYSIZE nStart, MYSIZE nChars)
		{
			// This overload of basic_string::assign is supposed to assign up to
			// <nChars> or the NULL terminator, whichever comes first.  Since we
			// are about to call a less forgiving overload (in which <nChars>
			// must be a valid length), we must adjust the length here to a safe
			// value. Thanks to Ullrich Pollähne for catching this bug
			nChars		= SSMIN(nChars, str.length() - nStart);
  			// Watch out for assignment to self
			if ( this == &str )	// watch out for assignment to self
			{
				MYTYPE strTemp(str.c_str() + nStart, nChars);
				assign(strTemp);
			}
			else
			{
				Q172398(*this);
				MYBASE::assign(str.c_str()+nStart, nChars);
			}
			return *this;
		}
  		MYTYPE& assign(const CT* pC, MYSIZE nChars)
		{
			// Q172398 only fix -- erase before assigning, but not if we're
			// assigning from our own buffer
	#if defined ( _MSC_VER ) && ( _MSC_VER < 1200 )
			if ( !empty() && ( pC < data() || pC > data() + capacity() ) )
				erase();
	#endif
			Q172398(*this);
			MYBASE::assign(pC, nChars);
			return *this;
		}
  		MYTYPE& assign(MYSIZE nChars, MYVAL val)
		{
			Q172398(*this);
			MYBASE::assign(nChars, val);
			return *this;
		}
  		MYTYPE& assign(const CT* pT)
		{
			return assign(pT, CStdStr::traits_type::length(pT));
		}
  		MYTYPE& assign(MYCITER iterFirst, MYCITER iterLast)
		{
	#if defined ( _MSC_VER ) && ( _MSC_VER < 1200 ) 
			// Q172398 fix.  don't call erase() if we're assigning from ourself
			if ( iterFirst < begin() || iterFirst > begin() + size() )
				erase()
	#endif
			replace(begin(), end(), iterFirst, iterLast);
			return *this;
		}
	#endif
  
	// -------------------------------------------------------------------------
	// CStdStr inline concatenation.
	// -------------------------------------------------------------------------
	MYTYPE& operator+=(const MYTYPE& str)
	{
		ssadd(*this, str);
		return *this;
	}
  	MYTYPE& operator+=(const std::string& str)
	{
		ssadd(*this, str);
		return *this; 
	}
  	MYTYPE& operator+=(const std::wstring& str)
	{
		ssadd(*this, str);
		return *this;
	}
  	MYTYPE& operator+=(PCSTR pA)
	{
		ssadd(*this, pA);
		return *this;
	}
  	MYTYPE& operator+=(PCWSTR pW)
	{
		ssadd(*this, pW);
		return *this;
	}
  	MYTYPE& operator+=(CT t)
	{
		append(1, t);
		return *this;
	}
	#ifdef SS_INC_COMDEF	// if we have _bstr_t, define a += for it too.
		MYTYPE& operator+=(const _bstr_t& bstr)
		{
			return operator+=(static_cast<PCMYSTR>(bstr));
		}
	#endif
  
	// addition operators -- global friend functions.
	friend	MYTYPE	operator+(const MYTYPE& str1,	const MYTYPE& str2);
	friend	MYTYPE	operator+(const MYTYPE& str,	CT t);
	friend	MYTYPE	operator+(const MYTYPE& str,	PCSTR sz);
	friend	MYTYPE	operator+(const MYTYPE& str,	PCWSTR sz);
	friend	MYTYPE	operator+(PCSTR pA,				const MYTYPE& str);
	friend	MYTYPE	operator+(PCWSTR pW,			const MYTYPE& str);
#ifdef SS_INC_COMDEF
	friend	MYTYPE	operator+(const _bstr_t& bstr,	const MYTYPE& str);
	friend	MYTYPE	operator+(const MYTYPE& str,	const _bstr_t& bstr);
#endif
  	// -------------------------------------------------------------------------
	// Case changing functions
	// -------------------------------------------------------------------------
	// -------------------------------------------------------------------------
	MYTYPE& ToUpper()
	{
	//  Strictly speaking, this would be about the most portable way
	//	std::transform(begin(),
	//				   end(),
	//				   begin(),
	//				   std::bind2nd(SSToUpper<CT>(), std::locale()));
		// But practically speaking, this works faster
		if ( !empty() )
			ssupr(GetBuf(), size());
  		return *this;
	}
 
 
  	MYTYPE& ToLower()
	{
	//  Strictly speaking, this would be about the most portable way
	//	std::transform(begin(),
	//				   end(),
	//				   begin(),
	//				   std::bind2nd(SSToLower<CT>(), std::locale()));
		// But practically speaking, this works faster
		if ( !empty() )
			sslwr(GetBuf(), size());
  		return *this;
	}
 
 
  	MYTYPE& Normalize()
	{
		return Trim().ToLower();
	}
  
	// -------------------------------------------------------------------------
	// CStdStr -- Direct access to character buffer.  In the MS' implementation,
	// the at() function that we use here also calls _Freeze() providing us some
	// protection from multithreading problems associated with ref-counting.
	// -------------------------------------------------------------------------
	CT* GetBuf(int nMinLen=-1)
	{
		if ( static_cast<int>(size()) < nMinLen )
			resize(static_cast<MYSIZE>(nMinLen));
  		return empty() ? const_cast<CT*>(data()) : &(at(0));
	}
  	CT* SetBuf(int nLen)
	{
		nLen = ( nLen > 0 ? nLen : 0 );
		if ( capacity() < 1 && nLen == 0 )
			resize(1);
  		resize(static_cast<MYSIZE>(nLen));
		return const_cast<CT*>(data());
	}
	void RelBuf(int nNewLen=-1)
	{
		resize(static_cast<MYSIZE>(nNewLen > -1 ? nNewLen : sslen(c_str())));
	}
  	void BufferRel()		 { RelBuf(); }			// backwards compatability
	CT*  Buffer()			 { return GetBuf(); }	// backwards compatability
	CT*  BufferSet(int nLen) { return SetBuf(nLen);}// backwards compatability
	bool Equals(const CT* pT, bool bUseCase=false) const
	{	// get copy, THEN compare (thread safe)
		return  bUseCase ? compare(pT) == 0 : ssicmp(MYTYPE(*this), pT) == 0;
	} 
  	// -------------------------------------------------------------------------
	// FUNCTION:  CStdStr::Load
	// REMARKS:
	//		Loads string from resource specified by nID
	//
	// PARAMETERS:
	//		nID - resource Identifier.  Purely a Win32 thing in this case
	//
	// RETURN VALUE:
	//		true if successful, false otherwise
	// -------------------------------------------------------------------------
#ifndef SS_ANSI
	bool Load(UINT nId, HMODULE hModule=NULL)
	{
		bool bLoaded		= false;	// set to true of we succeed.
	#ifdef _MFC_VER		// When in Rome...
		CString strRes;
		bLoaded				= FALSE != strRes.LoadString(nId);
		if ( bLoaded )
			*this			= strRes;
  	#else
		
		// Get the resource name and module handle
		if ( NULL == hModule )
			hModule			= GetResourceHandle();
  		PCTSTR szName		= MAKEINTRESOURCE((nId>>4)+1); // lifted 
		DWORD dwSize		= 0;
  		// No sense continuing if we can't find the resource
		HRSRC hrsrc			= ::FindResource(hModule, szName, RT_STRING);
  		if ( NULL == hrsrc )
			TRACE(_T("Cannot find resource %d: 0x%X"), nId, ::GetLastError());
		else if ( 0 == (dwSize = ::SizeofResource(hModule, hrsrc) / sizeof(CT)))
			TRACE(_T("Cant get size of resource %d 0x%X\n"),nId,GetLastError());
		else
		{
			bLoaded			= 0 != ssload(hModule, nId, GetBuf(dwSize), dwSize);
			ReleaseBuffer();
		}
  	#endif
  		if ( !bLoaded )
			TRACE(_T("String not loaded 0x%X\n"), ::GetLastError());
  		return bLoaded;
	}
#endif
	
	// -------------------------------------------------------------------------
	// FUNCTION:  CStdStr::Format
	//		void _cdecl Formst(CStdStringA& PCSTR szFormat, ...)
	//		void _cdecl Format(PCSTR szFormat);
	//           
	// DESCRIPTION:
	//		This function does sprintf/wsprintf style formatting on CStdStringA
	//		objects.  It looks a lot like MFC's CString::Format.  Some people
	//		might even call this identical.  Fortunately, these people are now
	//		dead.
	//
	// PARAMETERS: 
	//		nId - ID of string resource holding the format string
	//		szFormat - a PCSTR holding the format specifiers
	//		argList - a va_list holding the arguments for the format specifiers.
	//
	// RETURN VALUE:  None.
	// -------------------------------------------------------------------------
	// formatting (using wsprintf style formatting)
	#ifndef SS_ANSI
	void Format(UINT nId, ...)
	{
		va_list argList;
		va_start(argList, nId);
		va_start(argList, nId);
  		MYTYPE strFmt;
		if ( strFmt.Load(nId) )
			FormatV(strFmt, argList);
  		va_end(argList);
	}
	#endif
	void Format(const CT* szFmt, ...)
	{
		va_list argList;
		va_start(argList, szFmt);
		FormatV(szFmt, argList);
		va_end(argList);
	}
	void AppendFormat(const CT* szFmt, ...)
	{
		va_list argList;
		va_start(argList, szFmt);
		AppendFormatV(szFmt, argList);
		va_end(argList);
	}
  	#define MAX_FMT_TRIES		5	 // #of times we try 
	#define FMT_BLOCK_SIZE		2048 // # of bytes to increment per try
	#define BUFSIZE_1ST	256
	#define BUFSIZE_2ND 512
	#define STD_BUF_SIZE		1024
  	// an efficient way to add formatted characters to the string.  You may only
	// add up to STD_BUF_SIZE characters at a time, though
	void AppendFormatV(const CT* szFmt, va_list argList)
	{
		CT szBuf[STD_BUF_SIZE];
	#ifdef SS_ANSI
		int nLen = ssvsprintf(szBuf, STD_BUF_SIZE-1, szFmt, argList);
	#else
		int nLen = ssnprintf(szBuf, STD_BUF_SIZE-1, szFmt, argList);
	#endif
		if ( 0 < nLen )
			append(szBuf, nLen);
	}
  	// -------------------------------------------------------------------------
	// FUNCTION:  FormatV
	//		void FormatV(PCSTR szFormat, va_list, argList);
	//           
	// DESCRIPTION:
	//		This function formats the string with sprintf style format-specs. 
	//		It makes a general guess at required buffer size and then tries
	//		successively larger buffers until it finds one big enough or a
	//		threshold (MAX_FMT_TRIES) is exceeded.
	//
	// PARAMETERS: 
	//		szFormat - a PCSTR holding the format of the output
	//		argList - a Microsoft specific va_list for variable argument lists
	//
	// RETURN VALUE: 
	// -------------------------------------------------------------------------
	void FormatV(const CT* szFormat, va_list argList)
	{
	#ifdef SS_ANSI
  		int nLen	= sslen(szFormat) + STD_BUF_SIZE;
		ssvsprintf(GetBuffer(nLen), nLen-1, szFormat, argList);
		ReleaseBuffer();
  	#else
  		CT* pBuf			= NULL;
		int nChars			= 1;
		int nUsed			= 0;
		size_type nActual	= 0;
		int nTry			= 0;
  		do	
		{
			// Grow more than linearly (e.g. 512, 1536, 3072, etc)
			nChars			+= (nTry+1 * FMT_BLOCK_SIZE);
			pBuf			= reinterpret_cast<CT*>(_alloca(sizeof(CT)*nChars));
			nUsed			= ssnprintf(pBuf, nChars-1, szFormat, argList);
  			// Ensure proper NULL termination.
			nActual			= nUsed == -1 ? nChars-1 : SSMIN(nUsed, nChars-1);
			pBuf[nActual+1]= '\0';
  
		} while ( nUsed < 0 && nTry++ < MAX_FMT_TRIES );
  		// assign whatever we managed to format
		assign(pBuf, nActual);
  	#endif
	}
	
  	// -------------------------------------------------------------------------
	// CString Facade Functions:
	//
	// The following methods are intended to allow you to use this class as a
	// drop-in replacement for CString.
	// -------------------------------------------------------------------------
	#ifndef SS_ANSI
		BSTR AllocSysString() const
		{
			ostring os;
			ssasn(os, *this);
			return ::SysAllocString(os.c_str());
		}
	#endif
  	int Collate(PCMYSTR szThat) const
	{
		return sscoll(c_str(), length(), szThat, sslen(szThat));
	}
  	int CollateNoCase(PCMYSTR szThat) const
	{
		return ssicoll(c_str(), length(), szThat, sslen(szThat));
	}
  	int CompareNoCase(PCMYSTR szThat)	const
	{
		return ssicmp(c_str(), szThat);
	}
  	int Delete(int nIdx, int nCount=1)
	{
		if ( nIdx < GetLength() )
			erase(static_cast<MYSIZE>(nIdx), static_cast<MYSIZE>(nCount));
  		return GetLength();
	}
  	void Empty()
	{
		erase();
	}
  	int Find(CT ch) const
	{
		MYSIZE nIdx	= find_first_of(ch);
		return static_cast<int>(nIdx == npos ? -1 : nIdx);
	}
  	int Find(PCMYSTR szSub) const
	{
		MYSIZE nIdx	= find(szSub);
		return static_cast<int>(nIdx == npos ? -1 : nIdx);
	}
  	int Find(CT ch, int nStart) const
	{
		// CString::Find docs say add 1 to nStart when it's not zero
		// CString::Find code doesn't do that however.  We'll stick
		// with what the code does
		MYSIZE nIdx	= find_first_of(ch, static_cast<MYSIZE>(nStart));
		return static_cast<int>(nIdx == npos ? -1 : nIdx);
	}
  	int Find(PCMYSTR szSub, int nStart) const
	{
		// CString::Find docs say add 1 to nStart when it's not zero
		// CString::Find code doesn't do that however.  We'll stick
		// with what the code does
		MYSIZE nIdx	= find(szSub, static_cast<MYSIZE>(nStart));
		return static_cast<int>(nIdx == npos ? -1 : nIdx);
	}
  	int FindOneOf(PCMYSTR szCharSet) const
	{
		MYSIZE nIdx = find_first_of(szCharSet);
		return static_cast<int>(nIdx == npos ? -1 : nIdx);
	}
  #ifndef SS_ANSI
	void FormatMessage(PCMYSTR szFormat, ...) throw(std::exception)
	{
		va_list argList;
		va_start(argList, szFormat);
		PMYSTR szTemp;
		if ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
					   szFormat, 0, 0,
					   reinterpret_cast<PMYSTR>(&szTemp), 0, &argList) == 0 ||
			 szTemp == NULL )
		{
			throw std::runtime_error("out of memory");
		}
		*this = szTemp;
		LocalFree(szTemp);
		va_end(argList);
	}
  	void FormatMessage(UINT nFormatId, ...) throw(std::exception)
	{
		MYTYPE sFormat;
		VERIFY(sFormat.LoadString(nFormatId) != 0);
		va_list argList;
		va_start(argList, nFormatId);
		PMYSTR szTemp;
		if ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
					   sFormat, 0, 0,
					   reinterpret_cast<PMYSTR>(&szTemp), 0, &argList) == 0 ||
			szTemp == NULL)
		{
			throw std::runtime_error("out of memory");
		}
		*this = szTemp;
		LocalFree(szTemp);
		va_end(argList);
	}
#endif
  
	// -------------------------------------------------------------------------
	// GetXXXX -- Direct access to character buffer
	// -------------------------------------------------------------------------
	CT GetAt(int nIdx) const
	{
		return at(static_cast<MYSIZE>(nIdx));
	}
  	CT* GetBuffer(int nMinLen=-1)
	{
		return GetBuf(nMinLen);
	}
  	CT* GetBufferSetLength(int nLen)
	{
		return BufferSet(nLen);
	}
  	// GetLength() -- MFC docs say this is the # of BYTES but
	// in truth it is the number of CHARACTERs (chars or wchar_ts)
	int GetLength() const
	{
		return static_cast<int>(length());
	}
  	
	int Insert(int nIdx, CT ch)
	{
		if ( static_cast<MYSIZE>(nIdx) > size() -1 )
			append(1, ch);
		else
			insert(static_cast<MYSIZE>(nIdx), 1, ch);
  		return GetLength();
	}
  	int Insert(int nIdx, PCMYSTR sz)
	{
		insert(static_cast<MYSIZE>(nIdx), sz);
		return GetLength();
	}
  	bool IsEmpty() const
	{
		return empty();
	}
  	MYTYPE Left(int nCount) const
	{
		return substr(0, static_cast<MYSIZE>(nCount)); 
	}
  	#ifndef SS_ANSI
	bool LoadString(UINT nId)
	{
		return this->Load(nId);
	}
	#endif
  	void MakeLower()
	{
		ToLower();
	}
  	void MakeReverse()
	{
		std::reverse(begin(), end());
	}
  	void MakeUpper()
	{ 
		ToUpper();
	}
  	MYTYPE Mid(int nFirst ) const
	{
		return substr(static_cast<MYSIZE>(nFirst));
	}
  	MYTYPE Mid(int nFirst, int nCount) const
	{
		return substr(static_cast<MYSIZE>(nFirst), static_cast<MYSIZE>(nCount));
	}
  	void ReleaseBuffer(int nNewLen=-1)
	{
		RelBuf(nNewLen);
	}
  	int Remove(CT ch)
	{
		MYSIZE nIdx		= 0;
		int nRemoved	= 0;
		while ( (nIdx=find_first_of(ch)) != npos )
		{
			erase(nIdx, 1);
			nRemoved++;
		}
		return nRemoved;
	}
  	int Replace(CT chOld, CT chNew)
	{
		int nReplaced	= 0;
		for ( MYITER iter=begin(); iter != end(); iter++ )
		{
			if ( *iter == chOld )
			{
				*iter = chNew;
				nReplaced++;
			}
		}
		return nReplaced;
	}
  	int Replace(PCMYSTR szOld, PCMYSTR szNew)
	{
		int nReplaced		= 0;
		MYSIZE nIdx			= 0;
		static const CT _C	= CT(0);
		MYSIZE nOldLen		= sslen(szOld);
		MYSIZE nNewLen		= sslen(szNew);
		PCMYSTR szRealNew	= szNew == NULL ? &_C : szNew;
		PCMYSTR szRealOld	= szOld == NULL ? &_C : szOld;
		while ( (nIdx=find(szRealOld, nIdx)) != npos )
		{
			replace(begin()+nIdx, begin()+nIdx+nOldLen, szRealNew);
			nReplaced++;
			nIdx += nNewLen;
		}
		return nReplaced;
	}
  	int ReverseFind(CT ch) const
	{
		MYSIZE nIdx	= find_last_of(ch);
		return static_cast<int>(nIdx == npos ? -1 : nIdx);
	}
  	// ReverseFind overload that's not in CString but might be useful
	int ReverseFind(PCMYSTR szFind, size_type pos=npos) const
	{
		MYSIZE nIdx	= rfind(NULL == szFind ? MYTYPE() : szFind, pos);
		return static_cast<int>(nIdx == npos ? -1 : nIdx);
	}
  	MYTYPE Right(int nCount) const
	{
		nCount = SSMIN(nCount, static_cast<int>(size()));
		return substr(size()-static_cast<MYSIZE>(nCount));
	}
  	void SetAt(int nIndex, CT ch)
	{
		ASSERT(size() > static_cast<MYSIZE>(nIndex));
		at(static_cast<MYSIZE>(nIndex))		= ch;
	}
  	#ifndef SS_ANSI
		BSTR SetSysString(BSTR* pbstr) const
		{
			ostring os;
			ssasn(os, *this);
			if ( !::SysReAllocStringLen(pbstr, os.c_str(), os.length()) )
				throw std::runtime_error("out of memory");
  			ASSERT(*pbstr != NULL);
			return *pbstr;
		}
	#endif
  	MYTYPE SpanExcluding(PCMYSTR szCharSet) const
	{
		return Left(find_first_of(szCharSet));
	}
  	MYTYPE SpanIncluding(PCMYSTR szCharSet) const
	{
		return Left(find_first_not_of(szCharSet));
	}
  	#if !defined(UNICODE) && !defined(SS_ANSI)
  		// CString's OemToAnsi and AnsiToOem functions are available only in
		// Unicode builds.  However since we're a template we also need a
		// runtime check of CT and a reinterpret_cast to account for the fact
		// that CStdStringW gets instantiated even in non-Unicode builds.
		void AnsiToOem()
		{
			if ( sizeof(CT) == sizeof(char) && !empty() )
			{
				::CharToOem(reinterpret_cast<PCSTR>(c_str()),
							reinterpret_cast<PSTR>(GetBuf()));
			}
			else
			{
				ASSERT(false);
			}
		}
  		void OemToAnsi()
		{
			if ( sizeof(CT) == sizeof(char) && !empty() )
			{
				::OemToChar(reinterpret_cast<PCSTR>(c_str()),
							reinterpret_cast<PSTR>(GetBuf()));
			}
			else
			{
				ASSERT(false);
			}
		}
  	#endif
	
  	// -------------------------------------------------------------------------
	// Trim and its variants
	// -------------------------------------------------------------------------
	MYTYPE& Trim()
	{
		return TrimLeft().TrimRight();
	}
  	MYTYPE& TrimLeft()
	{
		erase(begin(), std::find_if(begin(),end(),NotSpace<CT>(std::locale())));
		return *this;
	}
  	MYTYPE&  TrimLeft(CT tTrim)
	{
		erase(0, find_first_not_of(tTrim));
		return *this;
	}
  	MYTYPE&  TrimLeft(PCMYSTR szTrimChars)
	{
		erase(0, find_first_not_of(szTrimChars));
		return *this;
	}
  	MYTYPE& TrimRight()
	{
		std::locale loc;
		reverse_iterator it = std::find_if(rbegin(), rend(), NotSpace<CT>(loc));
		if ( rend() != it )
			erase(rend() - it);
  		erase(it != rend() ? find_last_of(*it) + 1 : 0);
		return *this;
	}
  	MYTYPE&  TrimRight(CT tTrim)
	{
		MYSIZE nIdx	= find_last_not_of(tTrim);
		erase(npos == nIdx ? 0 : ++nIdx);
		return *this;
	}
  	MYTYPE&  TrimRight(PCMYSTR szTrimChars)
	{
		MYSIZE nIdx	= find_last_not_of(szTrimChars);
		erase(npos == nIdx ? 0 : ++nIdx);
		return *this;
	}
  	void			FreeExtra()
	{
		MYTYPE mt;
		swap(mt);
		if ( !mt.empty() )
			assign(mt.c_str(), mt.size());
	}
  	// I have intentionally not implemented the following CString
	// functions.   You cannot make them work without taking advantage
	// of implementation specific behavior.  However if you absolutely
	// MUST have them, uncomment out these lines for "sort-of-like"
	// their behavior.  You're on your own.
//	CT*				LockBuffer()	{ return GetBuf(); }// won't really lock
//	void			UnlockBuffer(); { }	// why have UnlockBuffer w/o LockBuffer?
	// Array-indexing operators.  Required because we defined an implicit cast
	// to operator const CT* (Thanks to Julian Selman for pointing this out)
	CT& operator[](int nIdx)
	{
		return MYBASE::operator[](static_cast<MYSIZE>(nIdx));
	}
  	const CT& operator[](int nIdx) const
	{
		return MYBASE::operator[](static_cast<MYSIZE>(nIdx));
	}
  	CT& operator[](unsigned int nIdx)
	{
		return MYBASE::operator[](static_cast<MYSIZE>(nIdx));
	}
  	const CT& operator[](unsigned int nIdx) const
	{
		return MYBASE::operator[](static_cast<MYSIZE>(nIdx));
	}
  	operator const CT*() const
	{
		return c_str();
	}
  	// IStream related functions.  Useful in IPersistStream implementations
#ifdef SS_INC_COMDEF
  	#define SSSO_UNICODE	0x01	// the string is a wide string
	#define SSSO_COMPRESS	0x02	// the string is compressed
	// -------------------------------------------------------------------------
	// FUNCTION: StreamSize
	// REMARKS:
	//		Returns how many bytes it will take to StreamSave() this CStdString
	//		object to an IStream.
	// -------------------------------------------------------------------------
	ULONG StreamSize() const
	{
		// Control header plus string
		ASSERT(size()*sizeof(CT) < 0xffffffffUL - sizeof(SSSHDR));
		return (size() * sizeof(CT)) + sizeof(SSSHDR);
	}
  	// -------------------------------------------------------------------------
	// FUNCTION: StreamSave
	// REMARKS:
	//		Saves this CStdString object to a COM IStream.
	// -------------------------------------------------------------------------
	HRESULT StreamSave(IStream* pStream) const
	{
		ASSERT(size()*sizeof(CT) < 0xffffffffUL - sizeof(SSSHDR));
		HRESULT hr		= E_FAIL;
		ASSERT(pStream != NULL);
		SSSHDR hdr;
		hdr.byCtrl		= sizeof(CT) == 2 ? SSSO_UNICODE : 0;
		hdr.nChars		= size();
  
		if ( FAILED(hr=pStream->Write(&hdr, sizeof(SSSHDR), NULL)) )
			TRACE(_T("StreamSave: Cannot write control header, ERR=0x%X\n"),hr);
		else if ( empty() )
			;		// nothing to write
		else if ( FAILED(hr=pStream->Write(c_str(), size()*sizeof(CT), NULL)) )
			TRACE(_T("StreamSave: Cannot write string to stream 0x%X\n"), hr);
  		return hr;
	}
  
	// -------------------------------------------------------------------------
	// FUNCTION: StreamLoad
	// REMARKS:
	//		This method loads the object from an IStream.
	// -------------------------------------------------------------------------
	HRESULT StreamLoad(IStream* pStream)
	{
		ASSERT(pStream != NULL);
		SSSHDR hdr;
		HRESULT hr			= E_FAIL;
  		if ( FAILED(hr=pStream->Read(&hdr, sizeof(SSSHDR), NULL)) )
		{
			TRACE(_T("StreamLoad: Cant read control header, ERR=0x%X\n"), hr);
		}
		else if ( hdr.nChars > 0 )
		{
			ULONG nRead		= 0;
			PMYSTR pMyBuf	= BufferSet(hdr.nChars);
  			// If our character size matches the character size of the string
			// we're trying to read, then we can read it directly into our
			// buffer. Otherwise, we have to read into an intermediate buffer
			// and convert.
			
			if ( (hdr.byCtrl & SSSO_UNICODE) != 0 )
			{
				ULONG nBytes	= hdr.nChars * sizeof(wchar_t);
				if ( sizeof(CT) == sizeof(wchar_t) )
				{
					if ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) )
						TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);
				}
				else
				{	
					PWSTR pBufW = reinterpret_cast<PWSTR>(_alloca((nBytes)+1));
					if ( FAILED(hr=pStream->Read(pBufW, nBytes, &nRead)) )
						TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);
					else
						sscpy(pMyBuf, pBufW, hdr.nChars*sizeof(wchar_t));
				}
			}
			else
			{
				ULONG nBytes	= hdr.nChars * sizeof(char);
				if ( sizeof(CT) == sizeof(char) )
				{
					if ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) )
						TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);
				}
				else
				{
					PSTR pBufA = reinterpret_cast<PSTR>(_alloca(nBytes));
					if ( FAILED(hr=pStream->Read(pBufA, hdr.nChars, &nRead)) )
						TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);
					else
						sscpy(pMyBuf, pBufA, hdr.nChars);
				}
			}
		}
		else
		{
			this->erase();
		}
		return hr;
	}
#endif // #ifdef SS_INC_COMDEF
	// SetResourceHandle/GetResourceHandle.  In MFC builds, these map directly
	// to AfxSetResourceHandle and AfxGetResourceHandle.  In non-MFC builds they
	// point to a single static HINST so that those who call the member
	// functions that take resource IDs can provide an alternate HINST of a DLL
	// to search.  This is not exactly the list of HMODULES that MFC provides
	// but it's better than nothing.
	#ifdef _MFC_VER
		static void SetResourceHandle(HMODULE hNew)
		{
			AfxSetResourceHandle(hNew);
		}
		static HMODULE GetResourceHandle()
		{
			return AfxGetResourceHandle();
		}
	#else
		static void SetResourceHandle(HMODULE hNew)
		{
			SSResourceHandle() = hNew;
		}
		static HMODULE GetResourceHandle()
		{
			return SSResourceHandle();
		}
	#endif
};
 
 
  // -----------------------------------------------------------------------------
// CStdStr friend addition functions defined as inline
// -----------------------------------------------------------------------------
template<typename CT>
inline
CStdStr<CT> operator+(const  CStdStr<CT>& str1, const  CStdStr<CT>& str2)
{
	CStdStr<CT> strRet(SSREF(str1));
	strRet.append(str2);
	return strRet;
}
  template<typename CT>	
inline
CStdStr<CT> operator+(const  CStdStr<CT>& str, CT t)
{
	// this particular overload is needed for disabling reference counting
	// though it's only an issue from line 1 to line 2
	CStdStr<CT> strRet(SSREF(str));	// 1
	strRet.append(1, t);				// 2
	return strRet;
}
  template<typename CT>
inline
CStdStr<CT> operator+(const  CStdStr<CT>& str, PCSTR pA)
{
	return CStdStr<CT>(str) + CStdStr<CT>(pA);
}
  template<typename CT>
inline
CStdStr<CT> operator+(PCSTR pA, const  CStdStr<CT>& str)
{
	CStdStr<CT> strRet(pA);
	strRet.append(str);
	return strRet;
}
  template<typename CT>
inline
CStdStr<CT> operator+(const CStdStr<CT>& str, PCWSTR pW)
{ 
	return CStdStr<CT>(SSREF(str)) + CStdStr<CT>(pW);
}
  template<typename CT>
inline
CStdStr<CT> operator+(PCWSTR pW, const CStdStr<CT>& str)
{
	CStdStr<CT> strRet(pW);
	strRet.append(str);
	return strRet;
}
  #ifdef SS_INC_COMDEF
	template<typename CT>
	inline
	CStdStr<CT> operator+(const _bstr_t& bstr, const CStdStr<CT>& str)
	{
		return static_cast<const CT*>(bstr) + str;
	}
  	template<typename CT>
	inline
	CStdStr<CT> operator+(const CStdStr<CT>& str, const _bstr_t& bstr)
	{
		return str + static_cast<const CT*>(bstr);
	}
#endif
  
// =============================================================================
//						END OF CStdStr INLINE FUNCTION DEFINITIONS
// =============================================================================
//	Now typedef our class names based upon this humongous template
typedef CStdStr<char>		CStdStringA;	// a better std::string
typedef CStdStr<wchar_t>	CStdStringW;	// a better std::wstring
typedef CStdStr<OLECHAR>	CStdStringO;	// almost always CStdStringW
// SSResourceHandle: our MFC-like resource handle
inline HMODULE& SSResourceHandle()
{
	static HMODULE hModuleSS	= GetModuleHandle(NULL);
	return hModuleSS;
}
  
// In MFC builds, define some global serialization operators
// Special operators that allow us to serialize CStdStrings to CArchives.
// Note that we use an intermediate CString object in order to ensure that
// we use the exact same format.
#ifdef _MFC_VER
	inline CArchive& AFXAPI operator<<(CArchive& ar, const CStdStringA& strA)
	{
		CString strTemp	= strA;
		return ar << strTemp;
	}
	inline CArchive& AFXAPI operator<<(CArchive& ar, const CStdStringW& strW)
	{
		CString strTemp	= strW;
		return ar << strTemp;
	}
  	inline CArchive& AFXAPI operator>>(CArchive& ar, CStdStringA& strA)
	{
		CString strTemp;
		ar >> strTemp;
		strA = strTemp;
		return ar;
	}
	inline CArchive& AFXAPI operator>>(CArchive& ar, CStdStringW& strW)
	{
		CString strTemp;
		ar >> strTemp;
		strW = strTemp;
		return ar;
	}
#endif	// #ifdef _MFC_VER -- (i.e. is this MFC?)
// WUSysMessage -- return the system string corresponding to a system error or
// HRESULT value.
#define SS_DEFLANGID MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
  
// -----------------------------------------------------------------------------
// HOW TO EXPORT CSTDSTRING FROM A DLL
//
// If you want to export CStdStringA and CStdStringW from a DLL, then all you
// need to
//		1.	make sure that all components link to the same DLL version
//			of the CRT (not the static one).
//		2.	Uncomment the 3 lines of code below
//		3.	#define 2 macros per the instructions in MS KnowledgeBase
//			article Q168958.  The macros are:
//
//		MACRO		DEFINTION WHEN EXPORTING		DEFINITION WHEN IMPORTING
//		-----		------------------------		-------------------------
//		SSDLLEXP	(nothing, just #define it)		extern
//		SSDLLSPEC	__declspec(dllexport)			__declspec(dllimport)
//
//		Note that these macros must be available to ALL clients who want to 
//		link to the DLL and use the class.  If they 
// -----------------------------------------------------------------------------
//#pragma warning(disable:4231) // non-standard extension ("extern template")
//	SSDLLEXP template class SSDLLSPEC CStdStr<char>;
//	SSDLLEXP template class SSDLLSPEC CStdStr<wchar_t>;
  // -----------------------------------------------------------------------------
// GLOBAL FUNCTION:  WUFormat
//		CStdStringA WUFormat(UINT nId, ...);
//		CStdStringA WUFormat(PCSTR szFormat, ...);
//
// REMARKS:
//		This function allows the caller for format and return a CStdStringA
//		object with a single line of code.
// -----------------------------------------------------------------------------
#ifdef SS_ANSI
#else
	inline CStdStringA WUFormatA(UINT nId, ...)
	{
		va_list argList;
		va_start(argList, nId);
  		CStdStringA strFmt;
		CStdStringA strOut;
		if ( strFmt.Load(nId) )
			strOut.FormatV(strFmt, argList);
  		va_end(argList);
		return strOut;
	}
	inline CStdStringA WUFormatA(PCSTR szFormat, ...)
	{
		va_list argList;
		va_start(argList, szFormat);
		CStdStringA strOut;
		strOut.FormatV(szFormat, argList);
		va_end(argList);
		return strOut;
	}
  	inline CStdStringW WUFormatW(UINT nId, ...)
	{
		va_list argList;
		va_start(argList, nId);
  		CStdStringW strFmt;
		CStdStringW strOut;
		if ( strFmt.Load(nId) )
			strOut.FormatV(strFmt, argList);
  		va_end(argList);
		return strOut;
	}
	inline CStdStringW WUFormatW(PCWSTR szwFormat, ...)
	{
		va_list argList;
		va_start(argList, szwFormat);
		CStdStringW strOut;
		strOut.FormatV(szwFormat, argList);
		va_end(argList);
		return strOut;
	}
#endif // #ifdef SS_ANSI
#ifdef SS_ANSI
#else
	// -------------------------------------------------------------------------
	// FUNCTION: WUSysMessage
	//	 CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID);
	//	 CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID);
	//           
	// DESCRIPTION:
	//	 This function simplifies the process of obtaining a string equivalent
	//	 of a system error code returned from GetLastError().  You simply
	//	 supply the value returned by GetLastError() to this function and the
	//	 corresponding system string is returned in the form of a CStdStringA.
	//
	// PARAMETERS: 
	//	 dwError - a DWORD value representing the error code to be translated
	//	 dwLangId - the language id to use.  defaults to english.
	//
	// RETURN VALUE: 
	//	 a CStdStringA equivalent of the error code.  Currently, this function
	//	 only returns either English of the system default language strings.  
	// -------------------------------------------------------------------------
	#define SS_DEFLANGID MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
	inline CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID)
	{
		CHAR szBuf[512];
  		if ( 0 != ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
								   dwLangId, szBuf, 511, NULL) )
			return WUFormatA("%s (0x%X)", szBuf, dwError);
		else
 			return WUFormatA("Unknown error (0x%X)", dwError);
	}
	inline CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID)
	{
		WCHAR szBuf[512];
  		if ( 0 != ::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
								   dwLangId, szBuf, 511, NULL) )
			return WUFormatW(L"%s (0x%X)", szBuf, dwError);
		else
 			return WUFormatW(L"Unknown error (0x%X)", dwError);
	}
#endif
  // Define TCHAR based friendly names for some of these functions
#ifdef UNICODE
	#define CStdString				CStdStringW
	#define WUSysMessage			WUSysMessageW
	#define WUFormat				WUFormatW
#else
	#define CStdString				CStdStringA
	#define WUSysMessage			WUSysMessageA
	#define WUFormat				WUFormatA
#endif
  // ...and some shorter names for the space-efficient
#define WUSysMsg					WUSysMessage
#define WUSysMsgA					WUSysMessageA
#define WUSysMsgW					WUSysMessageW
#define WUFmtA						WUFormatA
#define	WUFmtW						WUFormatW
#define WUFmt						WUFormat
#define WULastErrMsg()				WUSysMessage(::GetLastError())
#define WULastErrMsgA()				WUSysMessageA(::GetLastError())
#define WULastErrMsgW()				WUSysMessageW(::GetLastError())
  
// -----------------------------------------------------------------------------
// FUNCTIONAL COMPARATORS:
// REMARKS:
//		These structs are derived from the std::binary_function template.  They
//		give us functional classes (which may be used in Standard C++ Library
//		collections and algorithms) that perform case-insensitive comparisons of
//		CStdString objects.  This is useful for maps in which the key may be the
//		 proper string but in the wrong case.
// -----------------------------------------------------------------------------
#define StdStringLessNoCaseW		SSLNCW	// avoid VC compiler warning 4786
#define StdStringEqualsNoCaseW		SSENCW		
#define StdStringLessNoCaseA		SSLNCA		
#define StdStringEqualsNoCaseA		SSENCA		
  #ifdef UNICODE
	#define StdStringLessNoCase		SSLNCW		
	#define StdStringEqualsNoCase	SSENCW		
#else
	#define StdStringLessNoCase		SSLNCA		
	#define StdStringEqualsNoCase	SSENCA		
#endif
  struct StdStringLessNoCaseW
	: std::binary_function<CStdStringW, CStdStringW, bool>
{
	inline
	bool operator()(const CStdStringW& sLeft, const CStdStringW& sRight) const
	{ return ssicmp(sLeft.c_str(), sRight.c_str()) < 0; }
};
struct StdStringEqualsNoCaseW
	: std::binary_function<CStdStringW, CStdStringW, bool>
{
	inline
	bool operator()(const CStdStringW& sLeft, const CStdStringW& sRight) const
	{ return ssicmp(sLeft.c_str(), sRight.c_str()) == 0; }
};
struct StdStringLessNoCaseA
	: std::binary_function<CStdStringA, CStdStringA, bool>
{
	inline
	bool operator()(const CStdStringA& sLeft, const CStdStringA& sRight) const
	{ return ssicmp(sLeft.c_str(), sRight.c_str()) < 0; }
};
struct StdStringEqualsNoCaseA
	: std::binary_function<CStdStringA, CStdStringA, bool>
{
	inline
	bool operator()(const CStdStringA& sLeft, const CStdStringA& sRight) const
	{ return ssicmp(sLeft.c_str(), sRight.c_str()) == 0; }
};
  // If we had to define our own version of TRACE above, get rid of it now
#ifdef TRACE_DEFINED_HERE
	#undef TRACE
	#undef TRACE_DEFINED_HERE
#endif
  
#endif	// #ifndef STDSTRING_H   |  
  
 | 
 
  
Currently browsing [inifile.zip] (62,782 bytes) - [Html version/CIniFile.cpp.html] - (69,037 bytes)
 
 <H3><CENTER>D:\CIniFile-Filpcode\CIniFile.cpp</CENTER></H3><PRE>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// File name    : CIniFile.cpp</FONT>
<FONT color="#008000">// Author       : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// date         : 20/11/2000</FONT>
<FONT color="#008000">// Description  : CIniFile class implementation</FONT>
<FONT color="#008000">//              : Easy IniFile object management</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Macros</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#define</FONT> M_MODULE_BGN
<FONT color="#0f4b95">#define</FONT> M_MODULE_END
  <FONT color="#0f4b95">#define</FONT> M_INCLUDES_BGN
<FONT color="#0f4b95">#define</FONT> M_INCLUDES_END
  <FONT color="#0f4b95">#define</FONT> M_INIFILE_FN_BGN
<FONT color="#0f4b95">#define</FONT> M_INIFILE_FN_END
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
M_MODULE_BGN(<FONT color="#a52a00">"CIniFile.cpp"</FONT>)
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Includes</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
M_INCLUDES_BGN(<FONT color="#a52a00">"CIniFile.cpp"</FONT>)
      <FONT color="#0f4b95">#include</FONT> <FONT color="#a52a00">"Common.h"</FONT>
    <FONT color="#0f4b95">#include</FONT> <FONT color="#a52a00">"CIniFile.h"</FONT>
<FONT color="#008000">//  #include "CCrypto.h"</FONT>
    <FONT color="#0f4b95">#include</FONT> <FONT color="#a52a00">"float.h"</FONT>
    <FONT color="#0f4b95">#include</FONT> <FONT color="#a52a00">"limits.h"</FONT>
  M_INCLUDES_END(<FONT color="#a52a00">"CIniFile.cpp"</FONT>)
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifdef</FONT>  _DEBUG_NEW
<FONT color="#0f4b95">#undef</FONT>  <FONT color="#0f4b95">new</FONT>
<FONT color="#0f4b95">#define</FONT> <FONT color="#0f4b95">new</FONT> DEBUG_NEW
<FONT color="#0f4b95">#undef</FONT>  THIS_FILE
<FONT color="#0f4b95">#define</FONT> THIS_FILE __FILE__
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Error constants</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">const</FONT> CStdString CIniFile::ms_strError = <FONT color="#a52a00">"CINIFILE_ERROR_READING_KEY_OR_SECTION"</FONT>;
<FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT>        CIniFile::ms_iError   = INT_MAX;
<FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT>      CIniFile::ms_fError   = FLT_MAX;
  <FONT color="#0f4b95">const</FONT> CStdString CIniFile::ms_strErrorMsg[CIniFile::E_INI_ERROR_MESSAGES::E_ERROR_MESSAGES_COUNT] = 
{
      <FONT color="#a52a00">"Error: Unable to open ini file"</FONT>,
    <FONT color="#a52a00">"Error: Unable to save ini file"</FONT>,
    <FONT color="#a52a00">"Error: Unable to locate specified section"</FONT>,
    <FONT color="#a52a00">"Error: Unable to locate specified key"</FONT>,
    <FONT color="#a52a00">"Warning: unknown extension"</FONT> ,
    <FONT color="#a52a00">"Warning: end string delimiter not found"</FONT>
};
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Internal shortcuts constants</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">const</FONT> CStdString CIniFile::ms_strComment  [CIniFile::E_INI_COMMENTS  ::E_COMMENTS_COUNT  ] = { <FONT color="#a52a00">";"</FONT>   , <FONT color="#a52a00">"//"</FONT>, <FONT color="#a52a00">"/*"</FONT>, <FONT color="#a52a00">"\t\t"</FONT> };
<FONT color="#0f4b95">const</FONT> CStdString CIniFile::ms_strType     [CIniFile::E_INI_TYPES     ::E_TYPES_COUNT     ] = { <FONT color="#a52a00">"%d"</FONT>  , <FONT color="#a52a00">"%f"</FONT>, <FONT color="#a52a00">"%s"</FONT>         };
<FONT color="#0f4b95">const</FONT> CStdString CIniFile::ms_strMarkup   [CIniFile::E_INI_MARKUPS   ::E_MARKUPS_COUNT   ] = { <FONT color="#a52a00">"["</FONT>   , <FONT color="#a52a00">"]"</FONT> , <FONT color="#a52a00">"="</FONT>          };
<FONT color="#0f4b95">const</FONT> CStdString CIniFile::ms_strTrim     [CIniFile::E_INI_TRIM      ::E_TRIM_COUNT      ] = { <FONT color="#a52a00">" "</FONT>   , <FONT color="#a52a00">"\t"</FONT>               };
<FONT color="#0f4b95">const</FONT> CStdString CIniFile::ms_strExtension[CIniFile::E_INI_EXTENSIONS::E_EXTENSIONS_COUNT] = { <FONT color="#a52a00">".ini"</FONT>, <FONT color="#a52a00">".crk"</FONT>             };
  <FONT color="#0f4b95">const</FONT> CStdString CIniFile::ms_strStringDelimiter = <FONT color="#a52a00">"\""</FONT>;
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Various defines</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
  <FONT color="#0f4b95">#ifdef</FONT>  TO_BOOL
<FONT color="#0f4b95">#undef</FONT>  TO_BOOL
<FONT color="#0f4b95">#endif</FONT>
<FONT color="#0f4b95">#define</FONT> TO_BOOL(i)      (((i)==<FONT color="#a52a00">0</FONT>)?false:true)
  <FONT color="#0f4b95">#ifdef</FONT>  TO_INT
<FONT color="#0f4b95">#undef</FONT>  TO_INT
<FONT color="#0f4b95">#endif</FONT>
<FONT color="#0f4b95">#define</FONT> TO_INT(b)       (((b))?<FONT color="#a52a00">1</FONT>:<FONT color="#a52a00">0</FONT>)
  <FONT color="#0f4b95">#define</FONT> BREAKPOINT      _asm <FONT color="#0f4b95">int</FONT> <FONT color="#a52a00">3</FONT>
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// CIniFile Implementation</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CIniFile::CIniFile()</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Construct empty IniFile object</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CIniFile::CIniFile()
{
M_INIFILE_FN_BGN(CIniFile::CIniFile())
      SetReadableExtension (ms_strExtension[E_INI_EXTENSIONS::E_READABLE ]);
    SetEncryptedExtension(ms_strExtension[E_INI_EXTENSIONS::E_ENCRYPTED]);
      m_bFastRead = false;
  M_INIFILE_FN_END
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CIniFile::CIniFile(const CFilename & strFilename, bool bFastRead)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Construct IniFile object based on given file</FONT>
<FONT color="#008000">//             : Optionnal fast read may be used if file doesn't contain any</FONT>
<FONT color="#008000">//             : trailing spaces nor tabs</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CIniFile::CIniFile(<FONT color="#0f4b95">const</FONT> CFilename & strFilename, <FONT color="#0f4b95">bool</FONT> bFastRead)
{
M_INIFILE_FN_BGN(CIniFile::CIniFile(<FONT color="#0f4b95">const</FONT> CFilename & strFilename))
      SetReadableExtension (ms_strExtension[E_INI_EXTENSIONS::E_READABLE ]);
    SetEncryptedExtension(ms_strExtension[E_INI_EXTENSIONS::E_ENCRYPTED]);
      Load(strFilename, bFastRead);
  M_INIFILE_FN_END
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CIniFile::~CIniFile()</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Destruct IniFile object</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CIniFile::~CIniFile()
{
M_INIFILE_FN_BGN(CIniFile::~CIniFile(<FONT color="#0f4b95">bool</FONT> bSave))
  <FONT color="#0f4b95">#ifdef</FONT> INI_SAVE_ON_EXIT
      Save(m_strPath);
  <FONT color="#0f4b95">#endif</FONT>
  M_INIFILE_FN_END
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::Load(const CStdString& strFilename, bool bFastRead)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Load ini file from disk or from previous specified file</FONT>
<FONT color="#008000">//             : Optionnal fast read may be used if file doesn't contain any</FONT>
<FONT color="#008000">//             : trailing spaces nor tabs</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::Load(<FONT color="#0f4b95">const</FONT> CStdString& strFilename, <FONT color="#0f4b95">bool</FONT> bFastRead)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::Load(<FONT color="#0f4b95">const</FONT> CStdString& strFilename))
      m_bFastRead = bFastRead;
      <FONT color="#0f4b95">if</FONT> (strFilename != <FONT color="#a52a00">""</FONT>) 
    {
        m_strPath = strFilename;
    }
      <FONT color="#008000">// Try reading readable ini file</FONT>
      <FONT color="#0f4b95">if</FONT> (m_strPath.GetLength() > m_strReadableExtension.GetLength())
    <FONT color="#0f4b95">if</FONT> (!m_strReadableExtension.CompareNoCase(m_strPath.Right(m_strReadableExtension.GetLength())))
    {
        <FONT color="#008000">// If *.ini doesn't exist change extension to crypted extension and try again</FONT>
          <FONT color="#0f4b95">if</FONT> (LoadReadableFile(m_strPath, true)) 
        {
            <FONT color="#0f4b95">return</FONT> true;
        }
        <FONT color="#0f4b95">else</FONT>
        {
            m_strPath = m_strPath.Left(m_strPath.GetLength() - m_strReadableExtension.GetLength()) + m_strEncryptedExtension;
        }
    }
      <FONT color="#008000">// Try reading crypted ini file</FONT>
    
    <FONT color="#0f4b95">if</FONT> (m_strPath.GetLength() > m_strEncryptedExtension.GetLength())
    <FONT color="#0f4b95">if</FONT> (!m_strEncryptedExtension.CompareNoCase(m_strPath.Right(m_strEncryptedExtension.GetLength())))
    {
        <FONT color="#0f4b95">return</FONT> LoadReadableFile(m_strPath, false);
    }
      <FONT color="#008000">// No recognized extension found</FONT>
    <FONT color="#008000">// Try reading readable ini file</FONT>
      m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_UNKNOWN_EXTENSION];
      <FONT color="#0f4b95">if</FONT> (LoadReadableFile())
    {
        <FONT color="#0f4b95">return</FONT> true;
    }
    <FONT color="#0f4b95">else</FONT>
    {
        m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_READ];
          <FONT color="#0f4b95">#ifdef</FONT> WIN32
            CStdString strMsg = m_strPath + <FONT color="#a52a00">" file not found !"</FONT>;
            ::<FONT color="#0f4b95">MessageBox</FONT>(NULL,strMsg, m_strLastError, MB_OK);
        <FONT color="#0f4b95">#endif</FONT>
          BREAKPOINT;
      <FONT color="#0f4b95">#ifdef</FONT> INI_USE_EXEPTIONS
          throw(strMsg.c_str());
      <FONT color="#0f4b95">#endif</FONT>
          <FONT color="#0f4b95">return</FONT> false;
    }
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::LoadReadableFile(const CStdString& strFilename, bool bIsReadable)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Internal function - file loading</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::LoadReadableFile(<FONT color="#0f4b95">const</FONT> CStdString& strFilename, <FONT color="#0f4b95">bool</FONT> bIsReadable)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::LoadReadableFile(<FONT color="#0f4b95">const</FONT> CStdString& strFilename, <FONT color="#0f4b95">bool</FONT> bIsReadable))
      <FONT color="#0f4b95">if</FONT> (strFilename != <FONT color="#a52a00">""</FONT>) m_strPath = strFilename;
      <FONT color="#008000">// Open stream</FONT>
      std::ifstream inifile;
    inifile.open(m_strPath);
      <FONT color="#0f4b95">if</FONT> (inifile.fail())
    {
        m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_READ];
        <FONT color="#0f4b95">return</FONT> false;
    }
      <FONT color="#008000">// Open stream Ok, parse file lines</FONT>
      CStdString strLine, strSection, strKey, strValue;
      <FONT color="#0f4b95">while</FONT> (GetLine(inifile, strLine))
    {
        <FONT color="#0f4b95">if</FONT> (! bIsReadable) 
        {
            Decrypt(strLine);
        }
          <FONT color="#0f4b95">if</FONT> (!m_bFastRead)
        {
            ManageComments(&strLine);
        }
          <FONT color="#0f4b95">if</FONT> (strLine != <FONT color="#a52a00">""</FONT>)
        {
            <FONT color="#0f4b95">if</FONT> (    strLine[<FONT color="#a52a00">0</FONT>]                      == (ms_strMarkup[E_INI_MARKUPS::E_SECTION_BEGIN])[<FONT color="#a52a00">0</FONT>] && 
                    strLine[strLine.GetLength()-<FONT color="#a52a00">1</FONT>]  == (ms_strMarkup[E_INI_MARKUPS::E_SECTION_END]  )[<FONT color="#a52a00">0</FONT>]    )
            {
                <FONT color="#008000">// Section found</FONT>
                  strSection = strLine;
                  strSection.TrimLeft (ms_strMarkup[E_INI_MARKUPS::E_SECTION_BEGIN]);
                strSection.TrimRight(ms_strMarkup[E_INI_MARKUPS::E_SECTION_END]);
                  <FONT color="#0f4b95">if</FONT> (!m_bFastRead)
                {
                    CleanString(&strSection);
                }
            }
            <FONT color="#0f4b95">else</FONT>
            {
                <FONT color="#008000">// Key found</FONT>
                  strKey   = strLine.Left (strLine.Find(ms_strMarkup[E_INI_MARKUPS::E_KEY]));
                strValue = strLine.Right(strLine.GetLength()-strKey.GetLength()-<FONT color="#a52a00">1</FONT>);
                  <FONT color="#0f4b95">if</FONT> (!m_bFastRead)
                {
                    CleanString(&strKey);
                    CleanString(&strValue);
                }
                  strValue.TrimLeft(ms_strMarkup[E_INI_MARKUPS::E_KEY]);
                
                SetValue(strSection, strKey, strValue);
            }
        }
    }
      inifile.close();
      <FONT color="#0f4b95">return</FONT> true;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false;   
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::Save(const CStdString& strFilename)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Save IniFile object to disk with specified filename</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::Save(<FONT color="#0f4b95">const</FONT> CStdString& strFilename)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::Save(<FONT color="#0f4b95">const</FONT> CStdString& strFilename))
      <FONT color="#0f4b95">if</FONT> (strFilename != <FONT color="#a52a00">""</FONT>) m_strPath = strFilename;
      <FONT color="#0f4b95">if</FONT> (m_strPath.GetLength() > m_strReadableExtension.GetLength())
    <FONT color="#0f4b95">if</FONT> (!m_strReadableExtension.CompareNoCase(m_strPath.Right(m_strReadableExtension.GetLength())))
    {
        <FONT color="#0f4b95">return</FONT> SaveReadableFile();
    }
    
    <FONT color="#0f4b95">if</FONT> (m_strPath.GetLength() > m_strEncryptedExtension.GetLength())
    <FONT color="#0f4b95">if</FONT> (!m_strEncryptedExtension.CompareNoCase(m_strPath.Right(m_strEncryptedExtension.GetLength())))
    {
        <FONT color="#0f4b95">return</FONT> SaveEncryptedFile();
    }
      m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_UNKNOWN_EXTENSION];
      SaveReadableFile();
      <FONT color="#0f4b95">return</FONT> false;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SaveReadableFile(const CStdString& strFilename)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : internal function - save readable file to disk</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SaveReadableFile(<FONT color="#0f4b95">const</FONT> CStdString& strFilename)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SaveReadableFile(<FONT color="#0f4b95">const</FONT> CStdString& strFilename))
      <FONT color="#0f4b95">if</FONT> (strFilename != <FONT color="#a52a00">""</FONT>) m_strPath = strFilename;
      std::ofstream inifile;
    inifile.open(m_strPath);
      <FONT color="#0f4b95">for</FONT>(m_itSection=m_data.begin(); m_itSection!=m_data.end(); m_itSection++)
    {
        inifile << <FONT color="#a52a00">"\n"</FONT> << ms_strMarkup[E_INI_MARKUPS::E_SECTION_BEGIN] << (*m_itSection).first << ms_strMarkup[E_INI_MARKUPS::E_SECTION_END] << <FONT color="#a52a00">"\n"</FONT>;
          <FONT color="#0f4b95">for</FONT>(m_itKey=((*m_itSection).second).begin(); m_itKey!=((*m_itSection).second).end(); m_itKey++)
        {
            inifile << (*m_itKey).first << ms_strMarkup[E_INI_MARKUPS::E_KEY] << (*m_itKey).second << <FONT color="#a52a00">"\n"</FONT>;
        }
    }
      inifile.close();
      <FONT color="#0f4b95">return</FONT> true;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SaveEncryptedFile(const CStdString& strFilename)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : internal function - save crypted file to disk</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SaveEncryptedFile(<FONT color="#0f4b95">const</FONT> CStdString& strFilename)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SaveEncryptedFile(<FONT color="#0f4b95">const</FONT> CStdString& strFilename))
      <FONT color="#0f4b95">if</FONT> (strFilename != <FONT color="#a52a00">""</FONT>) m_strPath = strFilename;
      std::ofstream inifile;
    inifile.open(m_strPath);
      <FONT color="#0f4b95">for</FONT>(m_itSection=m_data.begin(); m_itSection!=m_data.end(); m_itSection++)
    {
        inifile << <FONT color="#a52a00">"\n"</FONT> << Encrypt(ms_strMarkup[E_INI_MARKUPS::E_SECTION_BEGIN]) << Encrypt((*m_itSection).first) << Encrypt(ms_strMarkup[E_INI_MARKUPS::E_SECTION_END]) << <FONT color="#a52a00">"\n"</FONT>;
          <FONT color="#0f4b95">for</FONT>(m_itKey=((*m_itSection).second).begin(); m_itKey!=((*m_itSection).second).end(); m_itKey++)
        {
            inifile << Encrypt((*m_itKey).first) << Encrypt(ms_strMarkup[E_INI_MARKUPS::E_KEY]) << Encrypt((*m_itKey).second) << <FONT color="#a52a00">"\n"</FONT>;
        }
    }
      inifile.close();
      <FONT color="#0f4b95">return</FONT> true;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : void CIniFile::Reset()</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Reset IniFile object - clears all sections and keys</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">void</FONT> CIniFile::Reset()
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">void</FONT> CIniFile::Reset())
      <FONT color="#0f4b95">for</FONT>(m_itSection=m_data.begin(); m_itSection!=m_data.end(); m_itSection++)
    {
        ((*m_itSection).second).clear();
    }
      m_data.clear();
  M_INIFILE_FN_END
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : unsigned int CIniFile::GetSectionCount()</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get number of sections</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> CIniFile::GetSectionCount()
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> CIniFile::GetSectionCount())
      <FONT color="#0f4b95">return</FONT> m_data.size();
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> <FONT color="#a52a00">0</FONT>;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : unsigned int CIniFile::GetKeyCount(const CStdString& strSection)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get number of keys in specified section</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> CIniFile::GetKeyCount(<FONT color="#0f4b95">const</FONT> CStdString& strSection)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> CIniFile::GetKeyCount(<FONT color="#0f4b95">const</FONT> CStdString& strSection))
      <FONT color="#0f4b95">return</FONT> m_data[strSection].size();
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> <FONT color="#a52a00">0</FONT>;   
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : unsigned int CIniFile::GetKeyCount(unsigned int iSection)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get number of keys in i-th section</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> CIniFile::GetKeyCount(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iSection)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> CIniFile::GetKeyCount(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iSection))
      m_itSection = m_data.begin();
    std::advance(m_itSection, iSection);
      <FONT color="#0f4b95">return</FONT> (*m_itSection).second.size();
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> <FONT color="#a52a00">0</FONT>;   
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::GetSection(unsigned int iSection)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get name of i-th section</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::GetSection(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iSection)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetSection(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iSection))
      m_itSection = m_data.begin();
    std::advance(m_itSection, iSection);
      <FONT color="#0f4b95">return</FONT> (*m_itSection).first;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> ms_strError;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::GetKey(unsigned int iSection, unsigned int iKey)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get name of i-th key from i-th section</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::GetKey(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iSection, <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iKey)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetKey(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iSection, <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iKey))
      m_itSection = m_data.begin();
    std::advance(m_itSection, iSection);
      m_itKey = (*m_itSection).second.begin();
    std::advance(m_itKey, iKey);
      <FONT color="#0f4b95">return</FONT> (*m_itKey).first;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> ms_strError;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::GetKey(const CStdString& strSection, unsigned int iKey)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get name of i-th key from specified section</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::GetKey(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iKey)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetKey(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iSection, <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iKey))
      m_itKey = m_data[strSection].begin();
    std::advance(m_itKey, iKey);
      <FONT color="#0f4b95">return</FONT> (*m_itKey).first;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> ms_strError;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : int CIniFile::GetSection(const CStdString& strSection)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get id of specified section</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">int</FONT> CIniFile::GetSection(<FONT color="#0f4b95">const</FONT> CStdString& strSection)
{
M_FN_BGN(<FONT color="#0f4b95">int</FONT> CIniFile::GetSection(<FONT color="#0f4b95">const</FONT> CStdString& strSection))
      <FONT color="#0f4b95">int</FONT> iCurrentSection = <FONT color="#a52a00">0</FONT>;
      <FONT color="#0f4b95">for</FONT>(m_itSection=m_data.begin(); m_itSection!=m_data.end(); m_itSection++)
    {
        <FONT color="#0f4b95">if</FONT> ((*m_itSection).first == strSection)
        {
            <FONT color="#0f4b95">return</FONT> iCurrentSection;
        }
          iCurrentSection++;
    }
      <FONT color="#0f4b95">return</FONT> -<FONT color="#a52a00">1</FONT>;
  M_FN_END
      <FONT color="#0f4b95">return</FONT> -<FONT color="#a52a00">1</FONT>;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : int CIniFile::GetKey(const CStdString& strSection, const CStdString& strKey)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get id of specified key from specified section</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">int</FONT> CIniFile::GetKey(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey)
{
M_FN_BGN(<FONT color="#0f4b95">int</FONT> CIniFile::GetKey(<FONT color="#0f4b95">const</FONT> CStdString& strKey);)
      <FONT color="#0f4b95">int</FONT> iCurrentKey = <FONT color="#a52a00">0</FONT>;
      <FONT color="#0f4b95">for</FONT>(m_itKey=m_data[strSection].begin(); m_itKey!=m_data[strSection].end(); m_itKey++)
    {
        <FONT color="#0f4b95">if</FONT> ((*m_itKey).first == strKey)
        {
            <FONT color="#0f4b95">return</FONT> iCurrentKey;
        }
          iCurrentKey++;
    }
      <FONT color="#0f4b95">return</FONT> -<FONT color="#a52a00">1</FONT>;
  M_FN_END
      <FONT color="#0f4b95">return</FONT> -<FONT color="#a52a00">1</FONT>;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::GetValue(const CStdString& strSection, const CStdString& strKey)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get string value from specified section/key</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::GetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey))
      <FONT color="#0f4b95">if</FONT> (!m_bFastRead)
    {
        <FONT color="#0f4b95">if</FONT> (m_data.find(strSection) == m_data.end())
        {
            m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_FIND_SECTION];
        }
        <FONT color="#0f4b95">else</FONT> <FONT color="#0f4b95">if</FONT> (m_data[strSection].find(strKey) == m_data[strSection].end())
        {
            m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_FIND_KEY];
        }
        <FONT color="#0f4b95">else</FONT>
        {
            <FONT color="#0f4b95">return</FONT> m_data[strSection][strKey];
        }
          <FONT color="#0f4b95">#ifdef</FONT> WIN32
            ::<FONT color="#0f4b95">MessageBox</FONT>(NULL, m_strLastError, m_strPath, MB_ICONWARNING);
        <FONT color="#0f4b95">#endif</FONT>
          <FONT color="#0f4b95">#ifdef</FONT> INI_USE_EXEPTIONS
            throw(ms_strError.c_str());
        <FONT color="#0f4b95">#endif</FONT>
          <FONT color="#0f4b95">return</FONT> ms_strError;
    }
      <FONT color="#0f4b95">return</FONT> m_data[strSection][strKey];
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> ms_strError;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::GetValueS(const CStdString& strSection, const CStdString& strKey)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get string value from specified section/key</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::GetValueS(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetValueS(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey))
      <FONT color="#0f4b95">return</FONT> GetValue(strSection,strKey);
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> ms_strError;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::GetValue(const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get string value from specified section/key and return default value if section or key not found</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::GetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& strDefault)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& strDefault))
      <FONT color="#0f4b95">if</FONT> (!m_bFastRead)
    {
        <FONT color="#0f4b95">if</FONT> ( (m_data.find(strSection) == m_data.end()) ||
             (m_data[strSection].find(strKey) == m_data[strSection].end()) )
        {
            <FONT color="#0f4b95">return</FONT> strDefault;
        }
    }
      <FONT color="#0f4b95">return</FONT> GetValue(strSection,strKey);
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> strDefault;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::GetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& strDefault)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get string value from specified section/key and return default value if section or key not found</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::GetValueS(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& strDefault)
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetValueS(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& strDefault))
      <FONT color="#0f4b95">return</FONT> GetValue(strSection,strKey,strDefault);
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> strDefault;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : int CIniFile::GetValueI(const CStdString& strSection, const CStdString& strKey)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get integer value from specified section/key</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">int</FONT> CIniFile::GetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">int</FONT> CIniFile::GetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey))
      <FONT color="#0f4b95">return</FONT> atoi(GetValue(strSection,strKey).c_str());
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> ms_iError;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : int CIniFile::GetValueI(const CStdString& strSection, const CStdString& strKey, const int & iDefault)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get integer value from specified section/key and return default value if section or key not found</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">int</FONT> CIniFile::GetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT> & iDefault)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">int</FONT> CIniFile::GetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT> & iDefault))
      CStdString strDefault;
    strDefault.Format(ms_strType[CIniFile::E_INI_TYPES::E_INTEGER], iDefault);
      <FONT color="#0f4b95">return</FONT> atoi(GetValue(strSection,strKey,strDefault).c_str());
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> iDefault;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::GetValueB(const CStdString& strSection, const CStdString& strKey)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get boolean value from specified section/key</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::GetValueB(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::GetValueB(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey))
      <FONT color="#0f4b95">return</FONT> TO_BOOL(GetValueI(strSection,strKey));
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> TO_BOOL(ms_iError);
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::GetValueB(const CStdString& strSection, const CStdString& strKey, const bool & bDefault)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get boolean value from specified section/key and return default value if section or key not found</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::GetValueB(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">bool</FONT> & bDefault)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::GetValueB(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">bool</FONT> & bDefault))
      <FONT color="#0f4b95">return</FONT> TO_BOOL(GetValueI(strSection,strKey,TO_INT(bDefault)));
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> TO_BOOL(bDefault);
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : float CIniFile::GetValueF(const CStdString& strSection, const CStdString& strKey)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get floating point value from specified section/key</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">float</FONT> CIniFile::GetValueF(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">float</FONT> CIniFile::GetValueF(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey))
      <FONT color="#0f4b95">return</FONT> (<FONT color="#0f4b95">float</FONT>)atof(GetValue(strSection,strKey).c_str());
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> ms_fError;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : float CIniFile::GetValueF(const CStdString& strSection, const CStdString& strKey, const float & fDefault)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get floating point value from specified section/key and return default value if section or key not found</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">float</FONT> CIniFile::GetValueF(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT> & fDefault)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">float</FONT> CIniFile::GetValueF(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT> & fDefault))
      CStdString strDefault;
    strDefault.Format(ms_strType[CIniFile::E_INI_TYPES::E_FLOAT], fDefault);
      <FONT color="#0f4b95">return</FONT> (<FONT color="#0f4b95">float</FONT>)atof(GetValue(strSection,strKey,strDefault).c_str());
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> fDefault;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : void CIniFile::SetReadableExtension(const CStdString& ext)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Change readable exension</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">void</FONT> CIniFile::SetReadableExtension(<FONT color="#0f4b95">const</FONT> CStdString& ext)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">void</FONT> CIniFile::SetReadableExtension(<FONT color="#0f4b95">const</FONT> CStdString& ext))
      m_strReadableExtension = ext;
  M_INIFILE_FN_END
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : void CIniFile::SetEncryptedExtension(const CStdString& ext)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Change crypted exension</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">void</FONT> CIniFile::SetEncryptedExtension(<FONT color="#0f4b95">const</FONT> CStdString& ext)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">void</FONT> CIniFile::SetEncryptedExtension(<FONT color="#0f4b95">const</FONT> CStdString& ext))
      m_strEncryptedExtension = ext;
  M_INIFILE_FN_END
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::GetLastErrorMessage()</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Get last error message</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::GetLastErrorMessage()
{
M_INIFILE_FN_BGN(CStdString CIniFile::GetLastErrorMessage())
      <FONT color="#0f4b95">return</FONT> m_strLastError;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> <FONT color="#a52a00">"error in error handling !"</FONT>;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const CStdString& value, bool bCreate)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Set string value to specified section/key. Possibility to create section/key if doesn't exist</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& value, <FONT color="#0f4b95">bool</FONT> bCreate)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& value, <FONT color="#0f4b95">bool</FONT> bCreate))
      <FONT color="#0f4b95">if</FONT> (m_data.find(strSection) == m_data.end())
    {
        <FONT color="#0f4b95">if</FONT> (!bCreate)
        {
            <FONT color="#0f4b95">return</FONT> false;
        }
          m_data.insert(CSection::value_type(strSection,CKey()));
    }
      <FONT color="#0f4b95">if</FONT> (m_data[strSection].find(strKey) == m_data[strSection].end())
    {
        <FONT color="#0f4b95">if</FONT> (!bCreate)
        {
            <FONT color="#0f4b95">return</FONT> false;
        }
          m_data[strSection].insert(CKey::value_type(strKey,<FONT color="#a52a00">""</FONT>));
    }
      m_data[strSection][strKey] = value;
    
    <FONT color="#0f4b95">return</FONT> true;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
  }
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SetValueS(const CStdString& strSection, const CStdString& strKey, const CStdString& value, bool create)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Set string value to specified section/key. Possibility to create section/key if doesn't exist</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SetValueS(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& value, <FONT color="#0f4b95">bool</FONT> create)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SetValueS(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& value, <FONT color="#0f4b95">bool</FONT> create))
      SetValue(strSection, strKey, value, create);
    
    <FONT color="#0f4b95">return</FONT> true;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
  }
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const int & value, bool create)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Set integer value to specified section/key. Possibility to create section/key if doesn't exist</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT> & value, <FONT color="#0f4b95">bool</FONT> create)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT> & value, <FONT color="#0f4b95">bool</FONT> create))
      <FONT color="#0f4b95">return</FONT> SetValueI(strSection, strKey, value, create);
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const bool & value, bool create)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Set boolean value to specified section/key. Possibility to create section/key if doesn't exist</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">bool</FONT> & value, <FONT color="#0f4b95">bool</FONT> create)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">bool</FONT> & value, <FONT color="#0f4b95">bool</FONT> create))
      <FONT color="#0f4b95">return</FONT> SetValueB(strSection, strKey, value, create);
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SetValue(const CStdString& strSection, const CStdString& strKey, const float & value, bool create)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Set floating point value to specified section/key. Possibility to create section/key if doesn't exist</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT> & value, <FONT color="#0f4b95">bool</FONT> create)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SetValue(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT> & value, <FONT color="#0f4b95">bool</FONT> create))
      <FONT color="#0f4b95">return</FONT> SetValueF(strSection, strKey, value, create);
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SetValueI(const CStdString& strSection, const CStdString& strKey, const int & value, bool create)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Set integer value to specified section/key. Possibility to create section/key if doesn't exist</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT> & value, <FONT color="#0f4b95">bool</FONT> create)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT> & value, <FONT color="#0f4b95">bool</FONT> create))
      CStdString temp;
    temp.Format(ms_strType[E_INI_TYPES::E_INTEGER],value);
    <FONT color="#0f4b95">return</FONT> SetValue(strSection, strKey, temp, create);
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SetValueB(const CStdString& strSection, const CStdString& strKey, const bool & value, bool create)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description :Set boolean value to specified section/key. Possibility to create section/key if doesn't exist</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SetValueB(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">bool</FONT> & value, <FONT color="#0f4b95">bool</FONT> create)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">bool</FONT> & value, <FONT color="#0f4b95">bool</FONT> create))
      CStdString temp;
    temp.Format(ms_strType[E_INI_TYPES::E_INTEGER],TO_INT(value));
    <FONT color="#0f4b95">return</FONT> SetValue(strSection, strKey, temp, create);
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::SetValueF(const CStdString& strSection, const CStdString& strKey, const float & value, bool create)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Set floating point value to specified section/key. Possibility to create section/key if doesn't exist</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::SetValueF(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT> & value, <FONT color="#0f4b95">bool</FONT> create)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::SetValueF(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT> & value, <FONT color="#0f4b95">bool</FONT> create))
      CStdString temp;
    temp.Format(ms_strType[E_INI_TYPES::E_FLOAT],value);
    <FONT color="#0f4b95">return</FONT> SetValue(strSection, strKey, temp, create);
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::Delete(const CStdString& strSection, const CStdString& strKey)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Delete section/key</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::Delete(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::Delete(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey))
      m_data[strSection].erase(strKey);
      <FONT color="#0f4b95">return</FONT> true;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : bool CIniFile::Delete(const CStdString& strSection)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : Delete section</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">bool</FONT> CIniFile::Delete(<FONT color="#0f4b95">const</FONT> CStdString& strSection)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">bool</FONT> CIniFile::Delete(<FONT color="#0f4b95">const</FONT> CStdString& strSection))
      m_data.erase(strSection);
      <FONT color="#0f4b95">return</FONT> true;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> false; 
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : std::istream & CIniFile::GetLine(std::istream & is, CStdString& str)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : internal function - get line from stream</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
std::istream & CIniFile::GetLine(std::istream & is, CStdString& str)
{
M_INIFILE_FN_BGN(std::istream & CIniFile::GetLine(std::istream & is, CStdString& str))
      <FONT color="#0f4b95">char</FONT> buf[INI_LINE_MAX_LENGTH];
    is.getline(buf, INI_LINE_MAX_LENGTH);
    str = buf;
    <FONT color="#0f4b95">return</FONT> is;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> is;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : void CIniFile::CleanString(CStdString * pString)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : internal function - clean given string (removes trailing characters)</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">void</FONT> CIniFile::CleanString(CStdString * pString)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">void</FONT> CIniFile::CleanString(CStdString * pString))
      <FONT color="#0f4b95">int</FONT> iOldLength = pString->GetLength();
      <FONT color="#0f4b95">do</FONT> <FONT color="#0f4b95">for</FONT>(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iTrim=<FONT color="#a52a00">0</FONT>; iTrim<E_INI_TRIM::E_TRIM_COUNT; iTrim++)
    {
        iOldLength = pString->GetLength();
          pString->TrimLeft (ms_strTrim[iTrim]);
        pString->TrimRight(ms_strTrim[iTrim]);
    }
    <FONT color="#0f4b95">while</FONT>(pString->GetLength() != iOldLength);
      pString->TrimLeft (ms_strStringDelimiter);
    pString->TrimRight(ms_strStringDelimiter);
  M_INIFILE_FN_END
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::ManageComments(CStdString * pString)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : internal function - removes (and retrieve) comment from string</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::ManageComments(CStdString * pString)
{
M_INIFILE_FN_BGN(CStdString CIniFile::ManageComments(CStdString * pString))
      <FONT color="#008000">// First, look for string delimiters</FONT>
      <FONT color="#0f4b95">int</FONT> iDelimiterBegin = pString->Find       (ms_strStringDelimiter[<FONT color="#a52a00">0</FONT>]);
    <FONT color="#0f4b95">int</FONT> iDelimiterEnd   = pString->ReverseFind(ms_strStringDelimiter[<FONT color="#a52a00">0</FONT>]);
      <FONT color="#0f4b95">if</FONT> (iDelimiterEnd < iDelimiterBegin)
    {
        m_strLastError = ms_strErrorMsg[E_INI_ERROR_MESSAGES::E_END_DELIMITER];
    }
      <FONT color="#008000">// then manage comments</FONT>
      CStdString strComment = <FONT color="#a52a00">""</FONT>;
      <FONT color="#0f4b95">int</FONT> iPrevPos, iPos, iLength=pString->GetLength();
      iPrevPos = pString->Find(ms_strComment[E_INI_COMMENTS::E_0]);
    <FONT color="#0f4b95">if</FONT> ((iPrevPos<<FONT color="#a52a00">0</FONT>)||((iPrevPos>iDelimiterBegin)&&(iPrevPos<iDelimiterEnd))) iPrevPos = iLength;
      iPos = pString->Find(ms_strComment[E_INI_COMMENTS::E_1]);
    <FONT color="#0f4b95">if</FONT> ((iPos<<FONT color="#a52a00">0</FONT>)||((iPos>iDelimiterBegin)&&(iPos<iDelimiterEnd))) iPos = iLength;
      iPos = (iPrevPos<iPos) ? iPrevPos : iPos;
      iPrevPos = pString->Find(ms_strComment[E_INI_COMMENTS::E_2]);
    <FONT color="#0f4b95">if</FONT> ((iPrevPos<<FONT color="#a52a00">0</FONT>)||((iPrevPos>iDelimiterBegin)&&(iPrevPos<iDelimiterEnd))) iPrevPos = iLength;
      iPos = (iPrevPos<iPos) ? iPrevPos : iPos;
      <FONT color="#0f4b95">if</FONT> (iPos>=<FONT color="#a52a00">0</FONT>)
    {
         strComment = pString->Right(iLength-iPos);
        *pString    = pString->Left (iPos);
           pString->TrimRight();
         pString->TrimRight(ms_strComment[E_INI_COMMENTS::E_SPACING]);
    }
      <FONT color="#0f4b95">return</FONT> strComment;
  M_INIFILE_FN_END
      <FONT color="#0f4b95">return</FONT> <FONT color="#a52a00">""</FONT>;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : void CIniFile::Decrypt(CStdString& str)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : internal function - decrypt string (uses CCrypto)</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">void</FONT> CIniFile::Decrypt(CStdString& str)
{
M_INIFILE_FN_BGN(<FONT color="#0f4b95">void</FONT> CIniFile::Decrypt(CStdString& str))
  <FONT color="#008000">//  CCrypto::Decrypt(&str);</FONT>
  M_INIFILE_FN_END
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Name        : CStdString CIniFile::Encrypt(const CStdString& str)</FONT>
<FONT color="#008000">// Author      : AV (Antoine Villepreux)</FONT>
<FONT color="#008000">// Date        : 20/11/2000</FONT>
<FONT color="#008000">// Description : internal function - encrypt string (uses CCrypto)</FONT>
<FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
CStdString CIniFile::Encrypt(<FONT color="#0f4b95">const</FONT> CStdString& str)
{
M_INIFILE_FN_BGN(CStdString CIniFile::Encrypt(<FONT color="#0f4b95">const</FONT> CStdString& str))
      CStdString strTmp = str;
  <FONT color="#008000">//  CCrypto::Encrypt(&strTmp);</FONT>
      <FONT color="#0f4b95">return</FONT> strTmp;
  M_INIFILE_FN_END
    
    <FONT color="#0f4b95">return</FONT> <FONT color="#a52a00">""</FONT>;
}
  <FONT color="#008000">//-----------------------------------------------------------------------------</FONT>
  M_MODULE_END(<FONT color="#a52a00">"CIniFile.cpp"</FONT>)
  </PRE><P><HR></P>   |  
  
 | 
 
  
Currently browsing [inifile.zip] (62,782 bytes) - [Html version/CIniFile.h.html] - (14,663 bytes)
 
 <H3><CENTER>D:\CIniFile-Filpcode\CIniFile.h</CENTER></H3><PRE>
<FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#008000">// File name   : CIniFile.h</FONT>
<FONT color="#008000">// Author      : Microïds - Antoine Villepreux</FONT>
<FONT color="#008000">// Description : CIniFile class definition</FONT>
<FONT color="#008000">// Purpose     : Easy *.ini files management</FONT>
<FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifndef</FONT> CINIFILE_H
<FONT color="#0f4b95">#define</FONT> CINIFILE_H
  <FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Precompiler options</FONT>
<FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#define</FONT> INI_USE_EXEPTIONS
<FONT color="#0f4b95">#define</FONT> INI_CASE_INENSITIVE
<FONT color="#0f4b95">#undef</FONT>  INI_SAVE_ON_EXIT
  <FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Includes</FONT>
<FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#include</FONT> <map>
<FONT color="#0f4b95">#include</FONT> <fstream>
<FONT color="#0f4b95">#include</FONT> <FONT color="#a52a00">"CStdString.h"</FONT>
  <FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#008000">// CIniFile defines</FONT>
<FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#define</FONT> INI_LINE_MAX_LENGTH <FONT color="#a52a00">1024</FONT>
  <FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#008000">// CFilename definition</FONT>
<FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#define</FONT> CFilename CStdString
  <FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#008000">// CIniFile definition</FONT>
<FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">class</FONT> CIniFile
{
<FONT color="#0f4b95">public</FONT>:
    <FONT color="#008000">// created in memory, no load from disk</FONT>
    CIniFile();
    CIniFile(<FONT color="#0f4b95">const</FONT> CFilename &, <FONT color="#0f4b95">bool</FONT> bFastRead = false);
    <FONT color="#0f4b95">virtual</FONT> ~CIniFile();
      <FONT color="#008000">// I/O - extension sensitive</FONT>
    <FONT color="#0f4b95">bool</FONT> Load(<FONT color="#0f4b95">const</FONT> CFilename & filename = <FONT color="#a52a00">""</FONT>, <FONT color="#0f4b95">bool</FONT> bFastRead = false);
    <FONT color="#0f4b95">bool</FONT> Save(<FONT color="#0f4b95">const</FONT> CFilename & filename = <FONT color="#a52a00">""</FONT>);
      <FONT color="#008000">// Clear all</FONT>
    <FONT color="#0f4b95">void</FONT> Reset();
      <FONT color="#008000">// Errors that 'GetValue' functions may return if key or section doesn't exist</FONT>
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> CStdString ms_strError;
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT>        ms_iError;
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT>      ms_fError;
      <FONT color="#008000">// Get/Set values</FONT>
    CStdString GetValue (<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey); <FONT color="#008000">// #ifdef INI_USE_EXEPTIONS throw CStdString</FONT>
    CStdString GetValueS(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey);
    <FONT color="#0f4b95">int</FONT>        GetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey); 
    <FONT color="#0f4b95">bool</FONT>       GetValueB(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey);
    <FONT color="#0f4b95">float</FONT>      GetValueF(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey);
      <FONT color="#008000">// No error but default value returned if section/key doesn't exists - use at your own risk</FONT>
    CStdString GetValue (<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& strDefault); 
    CStdString GetValueS(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& strDefault); 
    <FONT color="#0f4b95">int</FONT>        GetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT>       & iDefault  ); 
    <FONT color="#0f4b95">bool</FONT>       GetValueB(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">bool</FONT>      & bDefault  ); 
    <FONT color="#0f4b95">float</FONT>      GetValueF(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT>     & fDefault  ); 
      <FONT color="#008000">// beware!! 'Save' After Setting values (to save to disk)</FONT>
    <FONT color="#0f4b95">bool</FONT> SetValue (<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& strValue, <FONT color="#0f4b95">bool</FONT> bCreate=true);
    <FONT color="#0f4b95">bool</FONT> SetValue (<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT>       & iValue,   <FONT color="#0f4b95">bool</FONT> bCreate=true);
    <FONT color="#0f4b95">bool</FONT> SetValue (<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">bool</FONT>      & bValue,   <FONT color="#0f4b95">bool</FONT> bCreate=true);
    <FONT color="#0f4b95">bool</FONT> SetValue (<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT>     & fValue,   <FONT color="#0f4b95">bool</FONT> bCreate=true);
    
    <FONT color="#0f4b95">bool</FONT> SetValueS(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> CStdString& strValue, <FONT color="#0f4b95">bool</FONT> bCreate=true);
    <FONT color="#0f4b95">bool</FONT> SetValueI(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT>       & iValue,   <FONT color="#0f4b95">bool</FONT> bCreate=true);
    <FONT color="#0f4b95">bool</FONT> SetValueB(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">bool</FONT>      & bValue,   <FONT color="#0f4b95">bool</FONT> bCreate=true);
    <FONT color="#0f4b95">bool</FONT> SetValueF(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">float</FONT>     & fValue,   <FONT color="#0f4b95">bool</FONT> bCreate=true);
      <FONT color="#008000">// Sections/Keys Deletion/Retrieval</FONT>
    
    <FONT color="#0f4b95">bool</FONT> Delete(<FONT color="#0f4b95">const</FONT> CStdString& strSection);
    <FONT color="#0f4b95">bool</FONT> Delete(<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey);
      <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> GetSectionCount();
    <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> GetKeyCount(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT>      iSection);
    <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> GetKeyCount(<FONT color="#0f4b95">const</FONT> CStdString& strSection);
      CStdString GetSection(<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT>      iSection);
    CStdString GetKey    (<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT>      iSection,   <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iKey);
    CStdString GetKey    (<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> iKey);
      <FONT color="#0f4b95">int</FONT> GetSection(<FONT color="#0f4b95">const</FONT> CStdString& strSection);
    <FONT color="#0f4b95">int</FONT> GetKey    (<FONT color="#0f4b95">const</FONT> CStdString& strSection, <FONT color="#0f4b95">const</FONT> CStdString& strKey);
    
    <FONT color="#008000">// Extensions</FONT>
    <FONT color="#0f4b95">void</FONT> SetReadableExtension (<FONT color="#0f4b95">const</FONT> CStdString&);
    <FONT color="#0f4b95">void</FONT> SetEncryptedExtension(<FONT color="#0f4b95">const</FONT> CStdString&);
      <FONT color="#008000">// Error messages</FONT>
    CStdString GetLastErrorMessage();
  <FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Private</FONT>
<FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">protected</FONT>:
      <FONT color="#0f4b95">enum</FONT> E_INI_ERROR_MESSAGES
    {
        E_READ = <FONT color="#a52a00">0</FONT>,
        E_WRITE,
        E_FIND_SECTION,
        E_FIND_KEY,
        E_UNKNOWN_EXTENSION,
        E_END_DELIMITER,
        E_ERROR_MESSAGES_COUNT,
    };
      <FONT color="#0f4b95">enum</FONT> E_INI_COMMENTS
    {
        E_0 = <FONT color="#a52a00">0</FONT>,
        E_1,
        E_2,
        E_SPACING,
        E_COMMENTS_COUNT
    };
      <FONT color="#0f4b95">enum</FONT> E_INI_TYPES
    {
        E_INTEGER = <FONT color="#a52a00">0</FONT>,
        E_FLOAT,
        E_STRING,
        E_TYPES_COUNT
    };
      <FONT color="#0f4b95">enum</FONT> E_INI_MARKUPS
    {
        E_SECTION_BEGIN = <FONT color="#a52a00">0</FONT>,
        E_SECTION_END,
        E_KEY,
        E_MARKUPS_COUNT
    };
      <FONT color="#0f4b95">enum</FONT> E_INI_TRIM
    {
        E_TRIM_0 = <FONT color="#a52a00">0</FONT>,
        E_TRIM_1,
        E_TRIM_COUNT
    };
      <FONT color="#0f4b95">enum</FONT> E_INI_EXTENSIONS
    {
        E_READABLE = <FONT color="#a52a00">0</FONT>,
        E_ENCRYPTED,
        E_EXTENSIONS_COUNT
    };
  <FONT color="#0f4b95">private</FONT>:
      <FONT color="#008000">// Constants</FONT>
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> CStdString ms_strErrorMsg  [];
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> CStdString ms_strComment   [];
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> CStdString ms_strType      [];
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> CStdString ms_strMarkup    [];
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> CStdString ms_strTrim      [];
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> CStdString ms_strExtension [];
    <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> CStdString ms_strStringDelimiter;
      <FONT color="#008000">// Data</FONT>
    <FONT color="#0f4b95">typedef</FONT> std::map<CStdString, CStdString>    CKey;
    <FONT color="#0f4b95">typedef</FONT> std::map<CStdString, CKey>          CSection;
      CSection m_data;
      CSection::iterator  m_itSection;
    CKey::iterator      m_itKey;
      <FONT color="#008000">// File</FONT>
    CStdString m_strPath;
    std::istream & GetLine(std::istream&, CStdString&);
      <FONT color="#0f4b95">bool</FONT> LoadReadableFile (<FONT color="#0f4b95">const</FONT> CFilename& strFilename = <FONT color="#a52a00">""</FONT>, <FONT color="#0f4b95">bool</FONT> bIsReadable = true);
    <FONT color="#0f4b95">bool</FONT> SaveReadableFile (<FONT color="#0f4b95">const</FONT> CFilename& strFilename = <FONT color="#a52a00">""</FONT>);
    <FONT color="#0f4b95">bool</FONT> SaveEncryptedFile(<FONT color="#0f4b95">const</FONT> CFilename& strFilename = <FONT color="#a52a00">""</FONT>);
      <FONT color="#008000">// String format</FONT>
    CStdString ManageComments(CStdString*);
    <FONT color="#0f4b95">void</FONT> CleanString(CStdString*);
      <FONT color="#008000">// Encryption</FONT>
    CStdString m_strEncryptedExtension;
    CStdString m_strReadableExtension;
      <FONT color="#0f4b95">void</FONT> Decrypt(CStdString&);
    CStdString Encrypt(<FONT color="#0f4b95">const</FONT> CStdString&);
      <FONT color="#008000">// Various</FONT>
    CStdString m_strLastError;
    <FONT color="#0f4b95">bool</FONT> m_bFastRead;
};
  <FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Inline functions</FONT>
<FONT color="#008000">//------------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// CIniFile</FONT>
</PRE><P><HR></P>   |  
  
 | 
 
  
Currently browsing [inifile.zip] (62,782 bytes) - [Html version/CStdString.h.html] - (162,902 bytes)
 
 <H3><CENTER>D:\CIniFile-Filpcode\CStdString.h</CENTER></H3><PRE><FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">//  FILE:  StdString.h</FONT>
<FONT color="#008000">//  AUTHOR: Joe O'Leary (with outside help noted in comments)</FONT>
<FONT color="#008000">//  REMARKS:</FONT>
<FONT color="#008000">//      This header file declares the CStdStr template.  This template derives</FONT>
<FONT color="#008000">//      the Standard C++ Library basic_string<> template and add to it the</FONT>
<FONT color="#008000">//      the following conveniences:</FONT>
<FONT color="#008000">//          - The full MFC CString set of functions (including implicit cast)</FONT>
<FONT color="#008000">//          - writing to/reading from COM IStream interfaces</FONT>
<FONT color="#008000">//          - Functional objects for use in STL algorithms</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      From this template, we intstantiate two classes:  CStdStringA and</FONT>
<FONT color="#008000">//      CStdStringW.  The name "CStdString" is just a #define of one of these,</FONT>
<FONT color="#008000">//      based upone the _UNICODE macro setting</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      This header also declares our own version of the MFC/ATL UNICODE-MBCS</FONT>
<FONT color="#008000">//      conversion macros.  Our version looks exactly like the Microsoft's to</FONT>
<FONT color="#008000">//      facilitate portability.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//  NOTE:</FONT>
<FONT color="#008000">//      If you you use this in an MFC or ATL build, you should include either</FONT>
<FONT color="#008000">//      afx.h or atlbase.h first, as appropriate.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//  PEOPLE WHO HAVE CONTRIBUTED TO THIS CLASS:</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      Several people have helped me iron out problems and othewise improve</FONT>
<FONT color="#008000">//      this class.  OK, this is a long list but in my own defense, this code</FONT>
<FONT color="#008000">//      has undergone two major rewrites.  Many of the improvements became</FONT>
<FONT color="#008000">//      necessary after I rewrote the code as a template.  Others helped me</FONT>
<FONT color="#008000">//      improve the CString facade.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      Anyway, these people are (in chronological order):</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//          - Pete the Plumber (???)</FONT>
<FONT color="#008000">//          - Julian Selman</FONT>
<FONT color="#008000">//          - Chris (of Melbsys)</FONT>
<FONT color="#008000">//          - Dave Plummer</FONT>
<FONT color="#008000">//          - John C Sipos</FONT>
<FONT color="#008000">//          - Chris Sells</FONT>
<FONT color="#008000">//          - Nigel Nunn</FONT>
<FONT color="#008000">//          - Fan Xia</FONT>
<FONT color="#008000">//          - Matthew Williams</FONT>
<FONT color="#008000">//          - Carl Engman</FONT>
<FONT color="#008000">//          - Mark Zeren</FONT>
<FONT color="#008000">//          - Craig Watson</FONT>
<FONT color="#008000">//          - Rich Zuris</FONT>
<FONT color="#008000">//          - Karim Ratib</FONT>
<FONT color="#008000">//          - Chris Conti</FONT>
<FONT color="#008000">//          - Baptiste Lepilleur</FONT>
<FONT color="#008000">//          - Greg Pickles</FONT>
<FONT color="#008000">//          - Jim Cline</FONT>
<FONT color="#008000">//          - Jeff Kohn</FONT>
<FONT color="#008000">//          - Todd Heckel</FONT>
<FONT color="#008000">//          - Ullrich Pollähne</FONT>
<FONT color="#008000">//          - Joe Vitaterna</FONT>
<FONT color="#008000">//          - Joe Woodbury</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//  REVISION HISTORY</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    2000-JUL-11 - Joe Woodbury noted that the CString::Find docs don't match</FONT>
<FONT color="#008000">//                  what the CString::Find code really ends up doing.   I was</FONT>
<FONT color="#008000">//                  trying to match the docs.  Now I match the CString code</FONT>
<FONT color="#008000">//                - Joe also caught me truncating strings for GetBuffer() calls</FONT>
<FONT color="#008000">//                  when the supplied length was less than the current length.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    2000-MAY-25 - Better support for STLPORT's Standard library distribution</FONT>
<FONT color="#008000">//                - Got rid of the NSP macro - it interfered with Koenig lookup</FONT>
<FONT color="#008000">//                - Thanks to Joe Woodbury for catching a TrimLeft() bug that</FONT>
<FONT color="#008000">//                  I introduced in January.  Empty strings were not getting</FONT>
<FONT color="#008000">//                  trimmed</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    2000-APR-17 - Thanks to Joe Vitaterna for pointing out that ReverseFind</FONT>
<FONT color="#008000">//                  is supposed to be a const function.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    2000-MAR-07 - Thanks to Ullrich Pollähne for catching a range bug in one</FONT>
<FONT color="#008000">//                  of the overloads of assign.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    2000-FEB-01 - You can now use CStdString on the Mac with CodeWarrior!</FONT>
<FONT color="#008000">//                  Thanks to Todd Heckel for helping out with this.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    2000-JAN-23 - Thanks to Jim Cline for pointing out how I could make the</FONT>
<FONT color="#008000">//                  Trim() function more efficient.</FONT>
<FONT color="#008000">//                - Thanks to Jeff Kohn for prompting me to find and fix a typo</FONT>
<FONT color="#008000">//                  in one of the addition operators that takes _bstr_t.</FONT>
<FONT color="#008000">//                - Got rid of the .CPP file -  you only need StdString.h now!</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-DEC-22 - Thanks to Greg Pickles for helping me identify a problem</FONT>
<FONT color="#008000">//                  with my implementation of CStdString::FormatV in which</FONT>
<FONT color="#008000">//                  resulting string might not be properly NULL terminated.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-DEC-06 - Chris Conti pointed yet another basic_string<> assignment</FONT>
<FONT color="#008000">//                  bug that MS has not fixed.  CStdString did nothing to fix</FONT>
<FONT color="#008000">//                  it either but it does now!  The bug was: create a string</FONT>
<FONT color="#008000">//                  longer than 31 characters, get a pointer to it (via c_str())</FONT>
<FONT color="#008000">//                  and then assign that pointer to the original string object.</FONT>
<FONT color="#008000">//                  The resulting string would be empty.  Not with CStdString!</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-OCT-06 - BufferSet was erasing the string even when it was merely</FONT>
<FONT color="#008000">//                  supposed to shrink it.  Fixed.  Thanks to Chris Conti.</FONT>
<FONT color="#008000">//                - Some of the Q172398 fixes were not checking for assignment-</FONT>
<FONT color="#008000">//                  to-self.  Fixed.  Thanks to Baptiste Lepilleur.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-AUG-20 - Improved Load() function to be more efficient by using </FONT>
<FONT color="#008000">//                  SizeOfResource().  Thanks to Rich Zuris for this.</FONT>
<FONT color="#008000">//                - Corrected resource ID constructor, again thanks to Rich.</FONT>
<FONT color="#008000">//                - Fixed a bug that occurred with UNICODE characters above</FONT>
<FONT color="#008000">//                  the first 255 ANSI ones.  Thanks to Craig Watson. </FONT>
<FONT color="#008000">//                - Added missing overloads of TrimLeft() and TrimRight().</FONT>
<FONT color="#008000">//                  Thanks to Karim Ratib for pointing them out</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-JUL-21 - Made all calls to GetBuf() with no args check length first.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-JUL-10 - Improved MFC/ATL independence of conversion macros</FONT>
<FONT color="#008000">//                - Added SS_NO_REFCOUNT macro to allow you to disable any</FONT>
<FONT color="#008000">//                  reference-counting your basic_string<> impl. may do.</FONT>
<FONT color="#008000">//                - Improved ReleaseBuffer() to be as forgiving as CString.</FONT>
<FONT color="#008000">//                  Thanks for Fan Xia for helping me find this and to</FONT>
<FONT color="#008000">//                  Matthew Williams for pointing it out directly.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-JUL-06 - Thanks to Nigel Nunn for catching a very sneaky bug in</FONT>
<FONT color="#008000">//                  ToLower/ToUpper.  They should call GetBuf() instead of</FONT>
<FONT color="#008000">//                  data() in order to ensure the changed string buffer is not</FONT>
<FONT color="#008000">//                  reference-counted (in those implementations that refcount).</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-JUL-01 - Added a true CString facade.  Now you can use CStdString as</FONT>
<FONT color="#008000">//                  a drop-in replacement for CString.  If you find this useful,</FONT>
<FONT color="#008000">//                  you can thank Chris Sells for finally convincing me to give</FONT>
<FONT color="#008000">//                  in and implement it.</FONT>
<FONT color="#008000">//                - Changed operators << and >> (for MFC CArchive) to serialize</FONT>
<FONT color="#008000">//                  EXACTLY as CString's do.  So now you can send a CString out</FONT>
<FONT color="#008000">//                  to a CArchive and later read it in as a CStdString.   I have</FONT>
<FONT color="#008000">//                  no idea why you would want to do this but you can. </FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-JUN-21 - Changed the CStdString class into the CStdStr template.</FONT>
<FONT color="#008000">//                - Fixed FormatV() to correctly decrement the loop counter.</FONT>
<FONT color="#008000">//                  This was harmless bug but a bug nevertheless.  Thanks to</FONT>
<FONT color="#008000">//                  Chris (of Melbsys) for pointing it out</FONT>
<FONT color="#008000">//                - Changed Format() to try a normal stack-based array before</FONT>
<FONT color="#008000">//                  using to _alloca().</FONT>
<FONT color="#008000">//                - Updated the text conversion macros to properly use code</FONT>
<FONT color="#008000">//                  pages and to fit in better in MFC/ATL builds.  In other</FONT>
<FONT color="#008000">//                  words, I copied Microsoft's conversion stuff again. </FONT>
<FONT color="#008000">//                - Added equivalents of CString::GetBuffer, GetBufferSetLength</FONT>
<FONT color="#008000">//                - new sscpy() replacement of CStdString::CopyString()</FONT>
<FONT color="#008000">//                - a Trim() function that combines TrimRight() and TrimLeft().</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-MAR-13 - Corrected the "NotSpace" functional object to use _istpace()</FONT>
<FONT color="#008000">//                  instead of _isspace()   Thanks to Dave Plummer for this.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-FEB-26 - Removed errant line (left over from testing) that #defined</FONT>
<FONT color="#008000">//                  _MFC_VER.  Thanks to John C Sipos for noticing this.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1999-FEB-03 - Fixed a bug in a rarely-used overload of operator+() that</FONT>
<FONT color="#008000">//                  caused infinite recursion and stack overflow</FONT>
<FONT color="#008000">//                - Added member functions to simplify the process of</FONT>
<FONT color="#008000">//                  persisting CStdStrings to/from DCOM IStream interfaces </FONT>
<FONT color="#008000">//                - Added functional objects (e.g. StdStringLessNoCase) that</FONT>
<FONT color="#008000">//                  allow CStdStrings to be used as keys STL map objects with</FONT>
<FONT color="#008000">//                  case-insensitive comparison </FONT>
<FONT color="#008000">//                - Added array indexing operators (i.e. operator[]).  I</FONT>
<FONT color="#008000">//                  originally assumed that these were unnecessary and would be</FONT>
<FONT color="#008000">//                  inherited from basic_string.  However, without them, Visual</FONT>
<FONT color="#008000">//                  C++ complains about ambiguous overloads when you try to use</FONT>
<FONT color="#008000">//                  them.  Thanks to Julian Selman to pointing this out. </FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1998-FEB-?? - Added overloads of assign() function to completely account</FONT>
<FONT color="#008000">//                  for Q172398 bug.  Thanks to "Pete the Plumber" for this</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//    1998-FEB-?? - Initial submission</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// COPYRIGHT:</FONT>
<FONT color="#008000">//      1999 Joseph M. O'Leary.  This code is free.  Use it anywhere you want.</FONT>
<FONT color="#008000">//      Rewrite it, restructure it, whatever.  Please don't blame me if it makes</FONT>
<FONT color="#008000">//      your $30 billion dollar satellite explode in orbit.  If you redistribute</FONT>
<FONT color="#008000">//      it in any form, I'd appreciate it if you would leave this notice here.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      If you find any bugs, please let me know:</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//              jmoleary@earthlink.net</FONT>
<FONT color="#008000">//              http://home.earthlink.net/~jmoleary</FONT>
<FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">// Avoid multiple inclusion the VC++ way,</FONT>
<FONT color="#008000">// Turn off browser references</FONT>
<FONT color="#008000">// Turn off unavoidable compiler warnings</FONT>
<FONT color="#0f4b95">#if</FONT> defined(_MSC_VER) && (_MSC_VER > <FONT color="#a52a00">1100</FONT>)
    <FONT color="#0f4b95">#pragma</FONT> once
    <FONT color="#0f4b95">#pragma</FONT> component(browser, off, references, <FONT color="#a52a00">"CStdString"</FONT>)
    <FONT color="#0f4b95">#pragma</FONT> warning (disable : <FONT color="#a52a00">4290</FONT>) <FONT color="#008000">// C++ Exception Specification ignored</FONT>
    <FONT color="#0f4b95">#pragma</FONT> warning (disable : <FONT color="#a52a00">4127</FONT>) <FONT color="#008000">// Conditional expression is constant</FONT>
    <FONT color="#0f4b95">#pragma</FONT> warning (disable : <FONT color="#a52a00">4097</FONT>) <FONT color="#008000">// typedef name used as synonym for class name</FONT>
    <FONT color="#008000">// AV - 22/08/2000</FONT>
    <FONT color="#008000">// To avoid "identifier was truncated to '255' characters in the debug information"</FONT>
    <FONT color="#0f4b95">#pragma</FONT> warning (disable : <FONT color="#a52a00">4786</FONT>)
  <FONT color="#0f4b95">#endif</FONT>
  <FONT color="#0f4b95">#ifndef</FONT> STDSTRING_H
<FONT color="#0f4b95">#define</FONT> STDSTRING_H
  
<FONT color="#008000">// MACRO: SS_NO_REFCOUNT:</FONT>
<FONT color="#008000">//      turns off reference counting at the assignment level</FONT>
<FONT color="#008000">//      I define this by default.  comment it out if you don't want it.</FONT>
<FONT color="#0f4b95">#define</FONT> SS_NO_REFCOUNT  
  <FONT color="#008000">// In non-Visual C++ and/or non-Win32 builds, we can't use some cool stuff.</FONT>
<FONT color="#0f4b95">#if</FONT> !defined(_MSC_VER) || !defined(_WIN32)
    <FONT color="#0f4b95">#define</FONT> SS_ANSI
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// Avoid legacy code screw up: if _UNICODE is defined, UNICODE must be as well</FONT>
<FONT color="#0f4b95">#if</FONT> defined (_UNICODE) && !defined (UNICODE)
    <FONT color="#0f4b95">#define</FONT> UNICODE
<FONT color="#0f4b95">#endif</FONT>
<FONT color="#0f4b95">#if</FONT> defined (UNICODE) && !defined (_UNICODE)
    <FONT color="#0f4b95">#define</FONT> _UNICODE
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// MIN and MAX.  The Standard C++ template versions go by so many names (at</FONT>
<FONT color="#008000">// at least in the MS implementation) that you never know what's available </FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">template</FONT><<FONT color="#0f4b95">class</FONT> Type>
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">const</FONT> Type& SSMIN(<FONT color="#0f4b95">const</FONT> Type& arg1, <FONT color="#0f4b95">const</FONT> Type& arg2)
{
    <FONT color="#0f4b95">return</FONT> arg2 < arg1 ? arg2 : arg1;
}
<FONT color="#0f4b95">template</FONT><<FONT color="#0f4b95">class</FONT> Type>
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">const</FONT> Type& SSMAX(<FONT color="#0f4b95">const</FONT> Type& arg1, <FONT color="#0f4b95">const</FONT> Type& arg2)
{
    <FONT color="#0f4b95">return</FONT> arg2 > arg1 ? arg2 : arg1;
}
  <FONT color="#008000">// If they have not #included W32Base.h (part of my W32 utility library) then</FONT>
<FONT color="#008000">// we need to define some stuff.  Otherwise, this is all defined there.</FONT>
<FONT color="#0f4b95">#if</FONT> !defined(W32BASE_H)
      <FONT color="#008000">// If they want us to use only standard C++ stuff (no Win32 stuff)</FONT>
    <FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
          <FONT color="#008000">// On non-Win32 platforms, there is no TCHAR.H so define what we need</FONT>
        <FONT color="#0f4b95">#ifndef</FONT> _WIN32
              <FONT color="#0f4b95">typedef</FONT> <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">char</FONT>*     PCSTR;
            <FONT color="#0f4b95">typedef</FONT> <FONT color="#0f4b95">char</FONT>*           PSTR;
            <FONT color="#0f4b95">typedef</FONT> <FONT color="#0f4b95">const</FONT> wchar_t*  PCWSTR;
            <FONT color="#0f4b95">typedef</FONT> wchar_t*        PWSTR;
            <FONT color="#0f4b95">#ifdef</FONT> UNICODE
                <FONT color="#0f4b95">typedef</FONT> wchar_t     TCHAR;
            <FONT color="#0f4b95">#else</FONT>
                <FONT color="#0f4b95">typedef</FONT> <FONT color="#0f4b95">char</FONT>        TCHAR;
            <FONT color="#0f4b95">#endif</FONT>
            <FONT color="#0f4b95">typedef</FONT> wchar_t         OLECHAR;
          <FONT color="#0f4b95">#else</FONT>
              <FONT color="#0f4b95">#include</FONT> <TCHAR.H>
            <FONT color="#0f4b95">#include</FONT> <WTYPES.H>
            <FONT color="#0f4b95">#ifndef</FONT> STRICT
                <FONT color="#0f4b95">#define</FONT> STRICT
            <FONT color="#0f4b95">#endif</FONT>
          <FONT color="#0f4b95">#endif</FONT>  <FONT color="#008000">// #ifndef _WIN32</FONT>
          <FONT color="#008000">// Make sure ASSERT and verify are defined in an ANSI fashion</FONT>
        <FONT color="#0f4b95">#ifndef</FONT> ASSERT
            <FONT color="#0f4b95">#include</FONT> <assert.h>
            <FONT color="#0f4b95">#define</FONT> ASSERT(f) assert((f))
        <FONT color="#0f4b95">#endif</FONT>
        <FONT color="#0f4b95">#ifndef</FONT> VERIFY
            <FONT color="#0f4b95">#ifdef</FONT> _DEBUG
                <FONT color="#0f4b95">#define</FONT> VERIFY(x) ASSERT((x))
            <FONT color="#0f4b95">#else</FONT>
                <FONT color="#0f4b95">#define</FONT> VERIFY(x) x
            <FONT color="#0f4b95">#endif</FONT>
        <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#0f4b95">#else</FONT> <FONT color="#008000">// #ifdef SS_ANSI</FONT>
        <FONT color="#0f4b95">#include</FONT> <TCHAR.H>
        <FONT color="#0f4b95">#include</FONT> <WTYPES.H>
        <FONT color="#0f4b95">#ifndef</FONT> STRICT
            <FONT color="#0f4b95">#define</FONT> STRICT
        <FONT color="#0f4b95">#endif</FONT>
          <FONT color="#008000">// Make sure ASSERT and verify are defined</FONT>
        <FONT color="#0f4b95">#ifndef</FONT> ASSERT
            <FONT color="#0f4b95">#include</FONT> <crtdbg.h>
            <FONT color="#0f4b95">#define</FONT> ASSERT(f) _ASSERTE((f))
        <FONT color="#0f4b95">#endif</FONT>
        <FONT color="#0f4b95">#ifndef</FONT> VERIFY
            <FONT color="#0f4b95">#ifdef</FONT> _DEBUG
                <FONT color="#0f4b95">#define</FONT> VERIFY(x) ASSERT((x))
            <FONT color="#0f4b95">#else</FONT>
                <FONT color="#0f4b95">#define</FONT> VERIFY(x) x
            <FONT color="#0f4b95">#endif</FONT>
        <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifdef SS_ANSI</FONT>
    <FONT color="#0f4b95">#ifndef</FONT> UNUSED
        <FONT color="#0f4b95">#define</FONT> UNUSED(x) x
    <FONT color="#0f4b95">#endif</FONT>
  <FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifndef W32BASE_H</FONT>
<FONT color="#008000">// Standard headers needed</FONT>
<FONT color="#0f4b95">#include</FONT> <string>           <FONT color="#008000">// basic_string</FONT>
<FONT color="#0f4b95">#include</FONT> <algorithm>        <FONT color="#008000">// for_each, etc.</FONT>
<FONT color="#0f4b95">#include</FONT> <functional>       <FONT color="#008000">// for StdStringLessNoCase, et al</FONT>
<FONT color="#0f4b95">#include</FONT> <locale>           <FONT color="#008000">// for various facets</FONT>
<FONT color="#008000">// If this is a recent enough version of VC include comdef.h, so we can write</FONT>
<FONT color="#008000">// member functions to deal with COM types & compiler support classes e.g. _bstr_t</FONT>
<FONT color="#0f4b95">#if</FONT> defined (_MSC_VER) && (_MSC_VER >= <FONT color="#a52a00">1100</FONT>)
    <FONT color="#0f4b95">#include</FONT> <comdef.h>
    <FONT color="#0f4b95">#define</FONT> SS_INC_COMDEF       <FONT color="#008000">// signal that we #included MS comdef.h file</FONT>
    <FONT color="#0f4b95">#define</FONT> STDSTRING_INC_COMDEF
    <FONT color="#0f4b95">#define</FONT> SS_NOTHROW __declspec(nothrow)
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">#define</FONT> SS_NOTHROW
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#0f4b95">#ifndef</FONT> TRACE
    <FONT color="#0f4b95">#define</FONT> TRACE_DEFINED_HERE
    <FONT color="#0f4b95">#define</FONT> TRACE
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// Microsoft defines PCSTR, PCWSTR, etc, but no PCTSTR.  I hate to use the</FONT>
<FONT color="#008000">// versions with the "L" in front of them because that's a leftover from Win 16</FONT>
<FONT color="#008000">// days, even though it evaluates to the same thing.  Therefore, Define a PCSTR</FONT>
<FONT color="#008000">// as an LPCTSTR.</FONT>
<FONT color="#0f4b95">#if</FONT> !defined(PCTSTR) && !defined(PCTSTR_DEFINED)
    <FONT color="#0f4b95">typedef</FONT> <FONT color="#0f4b95">const</FONT> TCHAR*            PCTSTR;
    <FONT color="#0f4b95">#define</FONT> PCTSTR_DEFINED
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#0f4b95">#if</FONT> !defined(PCOLESTR) && !defined(PCOLESTR_DEFINED)
    <FONT color="#0f4b95">typedef</FONT> <FONT color="#0f4b95">const</FONT> OLECHAR*          PCOLESTR;
    <FONT color="#0f4b95">#define</FONT> PCOLESTR_DEFINED
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#0f4b95">#if</FONT> !defined(POLESTR) && !defined(POLESTR_DEFINED)
    <FONT color="#0f4b95">typedef</FONT> OLECHAR*                POLESTR;
    <FONT color="#0f4b95">#define</FONT> POLESTR_DEFINED
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#0f4b95">#if</FONT> !defined(PCUSTR) && !defined(PCUSTR_DEFINED)
    <FONT color="#0f4b95">typedef</FONT> <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">char</FONT>*    PCUSTR;
    <FONT color="#0f4b95">typedef</FONT> <FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">char</FONT>*          PUSTR;
    <FONT color="#0f4b95">#define</FONT> PCUSTR_DEFINED
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// SS_USE_FACET macro and why we need it:</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// Since I'm a good little Standard C++ programmer, I use locales.  Thus, I</FONT>
<FONT color="#008000">// need to make use of the use_facet<> template function here.   Unfortunately,</FONT>
<FONT color="#008000">// this need is complicated by the fact the MS' implementation of the Standard</FONT>
<FONT color="#008000">// C++ Library has a non-standard version of use_facet that takes more</FONT>
<FONT color="#008000">// arguments than the standard dictates.  Since I'm trying to write CStdString</FONT>
<FONT color="#008000">// to work with any version of the Standard library, this presents a problem.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// The upshot of this is that I can't do 'use_facet' directly.  The MS' docs</FONT>
<FONT color="#008000">// tell me that I have to use a macro, _USE() instead.  Since _USE obviously</FONT>
<FONT color="#008000">// won't be available in other implementations, this means that I have to write</FONT>
<FONT color="#008000">// my OWN macro -- SS_USE_FACET -- that evaluates either to _USE or to the</FONT>
<FONT color="#008000">// standard, use_facet.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// If you are having trouble with the SS_USE_FACET macro, in your implementation</FONT>
<FONT color="#008000">// of the Standard C++ Library, you can define your own version of SS_USE_FACET.</FONT>
<FONT color="#0f4b95">#ifndef</FONT> schMSG
    <FONT color="#0f4b95">#define</FONT> schSTR(x)      #x
    <FONT color="#0f4b95">#define</FONT> schSTR2(x)  schSTR(x)
    <FONT color="#0f4b95">#define</FONT> schMSG(desc) message(__FILE__ <FONT color="#a52a00">"("</FONT> schSTR2(__LINE__) <FONT color="#a52a00">"):"</FONT> #desc)
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#0f4b95">#ifndef</FONT> SS_USE_FACET
    <FONT color="#008000">// STLPort #defines a macro (__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) for</FONT>
    <FONT color="#008000">// all MSVC builds, erroneously in my opinion.  It causes problems for</FONT>
    <FONT color="#008000">// my SS_ANSI builds.  In my code, I always comment out that line.  You'll</FONT>
    <FONT color="#008000">// find it in   \stlport\config\stl_msvc.h</FONT>
    <FONT color="#0f4b95">#if</FONT> defined(__SGI_STL_PORT) && (__SGI_STL_PORT >= <FONT color="#a52a00">0x400</FONT> )
        <FONT color="#0f4b95">#if</FONT> defined(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && defined(_MSC_VER)
            <FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
                <FONT color="#0f4b95">#pragma</FONT> schMSG(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS defined!!)
            <FONT color="#0f4b95">#endif</FONT>
        <FONT color="#0f4b95">#endif</FONT>
        <FONT color="#0f4b95">#define</FONT> SS_USE_FACET(loc, fac) std::use_facet<fac >(loc)
    <FONT color="#0f4b95">#elif</FONT> defined(_MSC_VER )
        <FONT color="#0f4b95">#define</FONT> SS_USE_FACET(loc, fac) std::_USE(loc,fac)
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">#define</FONT> SS_USE_FACET(loc, fac) std::use_facet<fac >(loc)
    <FONT color="#0f4b95">#endif</FONT>
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">// UNICODE/MBCS conversion macros.  Made to work just like the MFC/ATL ones.</FONT>
<FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">// First define the conversion helper functions.  We define these regardless of</FONT>
<FONT color="#008000">// any preprocessor macro settings since their names won't collide. </FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI <FONT color="#008000">// Are we doing things the standard, non-Win32 way?...</FONT>
    <FONT color="#0f4b95">typedef</FONT> std::codecvt<wchar_t, <FONT color="#0f4b95">char</FONT>, mbstate_t> SSCodeCvt;
      <FONT color="#008000">// Not sure if we need all these headers.   I believe ANSI says we do.</FONT>
    <FONT color="#0f4b95">#include</FONT> <stdio.h>
    <FONT color="#0f4b95">#include</FONT> <stdarg.h>
    <FONT color="#0f4b95">#include</FONT> <wchar.h>
    <FONT color="#0f4b95">#ifndef</FONT> va_start
        <FONT color="#0f4b95">#include</FONT> <varargs.h>
    <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#008000">// StdCodeCvt - made to look like Win32 functions WideCharToMultiByte annd</FONT>
    <FONT color="#008000">//              MultiByteToWideChar but uses locales in SS_ANSI builds</FONT>
    <FONT color="#0f4b95">inline</FONT> PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, <FONT color="#0f4b95">int</FONT> nChars,
        <FONT color="#0f4b95">const</FONT> std::locale& loc=std::locale())
    {
        ASSERT(NULL != pA);
        ASSERT(NULL != pW);
        pW[<FONT color="#a52a00">0</FONT>] = <FONT color="#a52a00">'\0'</FONT>;
        PSTR pBadA              = NULL;
        PWSTR pBadW             = NULL;
        SSCodeCvt::result res   = SSCodeCvt::ok;
        <FONT color="#0f4b95">const</FONT> SSCodeCvt& conv   = SS_USE_FACET(loc, SSCodeCvt);
        res                     = conv.in(res,
                                          pA, pA + nChars, pBadA,
                                          pW, pW + nChars, pBadW);
        ASSERT(SSCodeCvt::ok == res);
        <FONT color="#0f4b95">return</FONT> pW;
    }
    <FONT color="#0f4b95">inline</FONT> PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, <FONT color="#0f4b95">int</FONT> nChars,
        <FONT color="#0f4b95">const</FONT> std::locale& loc=std::locale())
    {
        <FONT color="#0f4b95">return</FONT> StdCodeCvt(pW, (PCSTR)pA, nChars, loc);
    }
      <FONT color="#0f4b95">inline</FONT> PSTR StdCodeCvt(PSTR pA, PCWSTR pW, <FONT color="#0f4b95">int</FONT> nChars,
        <FONT color="#0f4b95">const</FONT> std::locale& loc=std::locale())
    {
        ASSERT(NULL != pA);
        ASSERT(NULL != pW);
        pA[<FONT color="#a52a00">0</FONT>] = <FONT color="#a52a00">'\0'</FONT>;
        PSTR pBadA              = NULL;
        PWSTR pBadW             = NULL;
        <FONT color="#0f4b95">const</FONT> SSCodeCvt& conv   = SS_USE_FACET(loc, SSCodeCvt);
        SSCodeCvt::result res   = SSCodeCvt::ok;
        res                     = conv.out(res,
                                           pW, pW + nChars, pBadW,
                                           pA, pA + nChars, pBadA);
        ASSERT(SSCodeCvt::ok == res);
        <FONT color="#0f4b95">return</FONT> pA;
    }
    <FONT color="#0f4b95">inline</FONT> PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, <FONT color="#0f4b95">int</FONT> nChars,
        <FONT color="#0f4b95">const</FONT> std::locale& loc=std::locale())
    {
        <FONT color="#0f4b95">return</FONT> (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, loc);
    }
  <FONT color="#0f4b95">#else</FONT>   <FONT color="#008000">// ...or are we doing things assuming win32 and Visual C++?</FONT>
    <FONT color="#0f4b95">#include</FONT> <malloc.h> <FONT color="#008000">// needed for _alloca</FONT>
    <FONT color="#0f4b95">inline</FONT> PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, <FONT color="#0f4b95">int</FONT> nChars, UINT acp=CP_ACP)
    {
        ASSERT(NULL != pA);
        ASSERT(NULL != pW);
        pW[<FONT color="#a52a00">0</FONT>] = <FONT color="#a52a00">'\0'</FONT>;
        MultiByteToWideChar(acp, <FONT color="#a52a00">0</FONT>, pA, -<FONT color="#a52a00">1</FONT>, pW, nChars);
        <FONT color="#0f4b95">return</FONT> pW;
    }
    <FONT color="#0f4b95">inline</FONT> PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, <FONT color="#0f4b95">int</FONT> nChars, UINT acp=CP_ACP)
    {
        <FONT color="#0f4b95">return</FONT> StdCodeCvt(pW, (PCSTR)pA, nChars, acp);
    }
      <FONT color="#0f4b95">inline</FONT> PSTR StdCodeCvt(PSTR pA, PCWSTR pW, <FONT color="#0f4b95">int</FONT> nChars, UINT acp=CP_ACP)
    {
        ASSERT(NULL != pA);
        ASSERT(NULL != pW);
        pA[<FONT color="#a52a00">0</FONT>] = <FONT color="#a52a00">'\0'</FONT>;
        WideCharToMultiByte(acp, <FONT color="#a52a00">0</FONT>, pW, -<FONT color="#a52a00">1</FONT>, pA, nChars, NULL, NULL);
        <FONT color="#0f4b95">return</FONT> pA;
    }
    <FONT color="#0f4b95">inline</FONT> PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, <FONT color="#0f4b95">int</FONT> nChars, UINT acp=CP_ACP)
    {
        <FONT color="#0f4b95">return</FONT> (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, acp);
    }
      <FONT color="#008000">// Define our conversion macros to look exactly like Microsoft's to</FONT>
    <FONT color="#008000">// facilitate using this stuff both with and without MFC/ATL</FONT>
    <FONT color="#0f4b95">#ifdef</FONT> _CONVERSION_USES_THREAD_LOCALE
        <FONT color="#0f4b95">#ifndef</FONT> _DEBUG
            <FONT color="#0f4b95">#define</FONT> SSCVT <FONT color="#0f4b95">int</FONT> _cvt; _cvt; UINT _acp=GetACP(); \
                _acp; PCWSTR _pw; _pw; PCSTR _pa; _pa
        <FONT color="#0f4b95">#else</FONT>
            <FONT color="#0f4b95">#define</FONT> SSCVT <FONT color="#0f4b95">int</FONT> _cvt = <FONT color="#a52a00">0</FONT>; _cvt; UINT _acp=GetACP();\
                 _acp; PCWSTR _pw=NULL; _pw; PCSTR _pa=NULL; _pa
        <FONT color="#0f4b95">#endif</FONT>
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">#ifndef</FONT> _DEBUG
            <FONT color="#0f4b95">#define</FONT> SSCVT <FONT color="#0f4b95">int</FONT> _cvt; _cvt; UINT _acp=CP_ACP; _acp;\
                 PCWSTR _pw; _pw; PCSTR _pa; _pa
        <FONT color="#0f4b95">#else</FONT>
            <FONT color="#0f4b95">#define</FONT> SSCVT <FONT color="#0f4b95">int</FONT> _cvt = <FONT color="#a52a00">0</FONT>; _cvt; UINT _acp=CP_ACP; \
                _acp; PCWSTR _pw=NULL; _pw; PCSTR _pa=NULL; _pa
        <FONT color="#0f4b95">#endif</FONT>
    <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#0f4b95">#ifdef</FONT> _CONVERSION_USES_THREAD_LOCALE
        <FONT color="#0f4b95">#define</FONT> SSA2W(pa) (\
            ((_pa = pa) == NULL) ? NULL : (\
                _cvt = (strlen(_pa)+<FONT color="#a52a00">1</FONT>),\
                StdCodeCvt((PWSTR) _alloca(_cvt*<FONT color="#a52a00">2</FONT>), _pa, _cvt, _acp)))
        <FONT color="#0f4b95">#define</FONT> SSW2A(pw) (\
            ((_pw = pw) == NULL) ? NULL : (\
                _cvt = (wcslen(_pw)+<FONT color="#a52a00">1</FONT>)*<FONT color="#a52a00">2</FONT>,\
                StdW2AHelper((<FONT color="#0f4b95">LPSTR</FONT>) _alloca(_cvt), _pw, _cvt, _acp)))
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">#define</FONT> SSA2W(pa) (\
            ((_pa = pa) == NULL) ? NULL : (\
                _cvt = (strlen(_pa)+<FONT color="#a52a00">1</FONT>),\
                StdCodeCvt((PWSTR) _alloca(_cvt*<FONT color="#a52a00">2</FONT>), _pa, _cvt)))
        <FONT color="#0f4b95">#define</FONT> SSW2A(pw) (\
            ((_pw = pw) == NULL) ? NULL : (\
                _cvt = (wcslen(_pw)+<FONT color="#a52a00">1</FONT>)*<FONT color="#a52a00">2</FONT>,\
                StdCodeCvt((<FONT color="#0f4b95">LPSTR</FONT>) _alloca(_cvt), _pw, _cvt)))
    <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#0f4b95">#define</FONT> SSA2CW(pa) ((PCWSTR)SSA2W((pa)))
    <FONT color="#0f4b95">#define</FONT> SSW2CA(pw) ((PCSTR)SSW2A((pw)))
      <FONT color="#0f4b95">#ifdef</FONT> UNICODE
        <FONT color="#0f4b95">#define</FONT> SST2A   SSW2A
        <FONT color="#0f4b95">#define</FONT> SSA2T   SSA2W
        <FONT color="#0f4b95">#define</FONT> SST2CA  SSW2CA
        <FONT color="#0f4b95">#define</FONT> SSA2CT  SSA2CW
        <FONT color="#0f4b95">inline</FONT> PWSTR    SST2W(PTSTR p)          { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PTSTR    SSW2T(PWSTR p)          { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCWSTR   SST2CW(PCTSTR p)        { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCTSTR   SSW2CT(PCWSTR p)        { <FONT color="#0f4b95">return</FONT> p; }
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">#define</FONT> SST2W   SSA2W
        <FONT color="#0f4b95">#define</FONT> SSW2T   SSW2A
        <FONT color="#0f4b95">#define</FONT> SST2CW  SSA2CW
        <FONT color="#0f4b95">#define</FONT> SSW2CT  SSW2CA
        <FONT color="#0f4b95">inline</FONT> PSTR     SST2A(PTSTR p)          { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PTSTR    SSA2T(PSTR p)           { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCSTR    SST2CA(PCTSTR p)        { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCTSTR   SSA2CT(PCSTR p)         { <FONT color="#0f4b95">return</FONT> p; }
    <FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifdef UNICODE</FONT>
    <FONT color="#0f4b95">#if</FONT> defined(UNICODE)
    <FONT color="#008000">// in these cases the default (TCHAR) is the same as OLECHAR</FONT>
        <FONT color="#0f4b95">inline</FONT> PCOLESTR SST2COLE(PCTSTR p)      { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCTSTR   SSOLE2CT(PCOLESTR p)    { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> POLESTR  SST2OLE(PTSTR p)        { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PTSTR    SSOLE2T(POLESTR p)      { <FONT color="#0f4b95">return</FONT> p; }
    <FONT color="#0f4b95">#elif</FONT> defined(OLE2ANSI)
    <FONT color="#008000">// in these cases the default (TCHAR) is the same as OLECHAR</FONT>
        <FONT color="#0f4b95">inline</FONT> PCOLESTR SST2COLE(PCTSTR p)      { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCTSTR   SSOLE2CT(PCOLESTR p)    { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> POLESTR  SST2OLE(PTSTR p)        { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PTSTR    SSOLE2T(POLESTR p)      { <FONT color="#0f4b95">return</FONT> p; }
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#008000">//CharNextW doesn't work on Win95 so we use this</FONT>
        <FONT color="#0f4b95">#define</FONT> SST2COLE(pa)    SSA2CW((pa))
        <FONT color="#0f4b95">#define</FONT> SST2OLE(pa)     SSA2W((pa))
        <FONT color="#0f4b95">#define</FONT> SSOLE2CT(po)    SSW2CA((po))
        <FONT color="#0f4b95">#define</FONT> SSOLE2T(po)     SSW2A((po))
    <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#0f4b95">#ifdef</FONT> OLE2ANSI
        <FONT color="#0f4b95">#define</FONT> SSW2OLE     SSW2A
        <FONT color="#0f4b95">#define</FONT> SSOLE2W     SSA2W
        <FONT color="#0f4b95">#define</FONT> SSW2COLE    SSW2CA
        <FONT color="#0f4b95">#define</FONT> SSOLE2CW    SSA2CW
        <FONT color="#0f4b95">inline</FONT> POLESTR      SSA2OLE(PSTR p)     { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PSTR         SSOLE2A(POLESTR p)  { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCOLESTR     SSA2COLE(PCSTR p)   { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCSTR        SSOLE2CA(PCOLESTR p){ <FONT color="#0f4b95">return</FONT> p; }
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">#define</FONT> SSA2OLE     SSA2W
        <FONT color="#0f4b95">#define</FONT> SSOLE2A     SSW2A
        <FONT color="#0f4b95">#define</FONT> SSA2COLE    SSA2CW
        <FONT color="#0f4b95">#define</FONT> SSOLE2CA    SSW2CA
        <FONT color="#0f4b95">inline</FONT> POLESTR      SSW2OLE(PWSTR p)    { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PWSTR        SSOLE2W(POLESTR p)  { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCOLESTR     SSW2COLE(PCWSTR p)  { <FONT color="#0f4b95">return</FONT> p; }
        <FONT color="#0f4b95">inline</FONT> PCWSTR       SSOLE2CW(PCOLESTR p){ <FONT color="#0f4b95">return</FONT> p; }
    <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#008000">// Above we've defined macros that look like MS' but all have</FONT>
    <FONT color="#008000">// an 'SS' prefix.  Now we need the real macros.  We'll either</FONT>
    <FONT color="#008000">// get them from the macros above or from MFC/ATL.  If</FONT>
    <FONT color="#008000">// SS_NO_CONVERSION is #defined, we'll forgo them</FONT>
    <FONT color="#0f4b95">#ifndef</FONT> SS_NO_CONVERSION
          <FONT color="#0f4b95">#if</FONT> defined (USES_CONVERSION)
              <FONT color="#0f4b95">#define</FONT> _NO_STDCONVERSION   <FONT color="#008000">// just to be consistent</FONT>
        <FONT color="#0f4b95">#else</FONT>
              <FONT color="#0f4b95">#ifdef</FONT> _MFC_VER
                  <FONT color="#0f4b95">#include</FONT> <afxconv.h>
                <FONT color="#0f4b95">#define</FONT> _NO_STDCONVERSION <FONT color="#008000">// just to be consistent</FONT>
            <FONT color="#0f4b95">#else</FONT>
                  <FONT color="#0f4b95">#define</FONT> USES_CONVERSION SSCVT
                <FONT color="#0f4b95">#define</FONT> A2CW            SSA2CW
                <FONT color="#0f4b95">#define</FONT> W2CA            SSW2CA
                <FONT color="#0f4b95">#define</FONT> T2A             SST2A
                <FONT color="#0f4b95">#define</FONT> A2T             SSA2T
                <FONT color="#0f4b95">#define</FONT> T2W             SST2W
                <FONT color="#0f4b95">#define</FONT> W2T             SSW2T
                <FONT color="#0f4b95">#define</FONT> T2CA            SST2CA
                <FONT color="#0f4b95">#define</FONT> A2CT            SSA2CT
                <FONT color="#0f4b95">#define</FONT> T2CW            SST2CW
                <FONT color="#0f4b95">#define</FONT> W2CT            SSW2CT
                <FONT color="#0f4b95">#define</FONT> ocslen          sslen
                <FONT color="#0f4b95">#define</FONT> ocscpy          sscpy
                <FONT color="#0f4b95">#define</FONT> T2COLE          SST2COLE
                <FONT color="#0f4b95">#define</FONT> OLE2CT          SSOLE2CT
                <FONT color="#0f4b95">#define</FONT> T2OLE           SST2COLE
                <FONT color="#0f4b95">#define</FONT> OLE2T           SSOLE2CT
                <FONT color="#0f4b95">#define</FONT> A2OLE           SSA2OLE
                <FONT color="#0f4b95">#define</FONT> OLE2A           SSOLE2A
                <FONT color="#0f4b95">#define</FONT> W2OLE           SSW2OLE
                <FONT color="#0f4b95">#define</FONT> OLE2W           SSOLE2W
                <FONT color="#0f4b95">#define</FONT> A2COLE          SSA2COLE
                <FONT color="#0f4b95">#define</FONT> OLE2CA          SSOLE2CA
                <FONT color="#0f4b95">#define</FONT> W2COLE          SSW2COLE
                <FONT color="#0f4b95">#define</FONT> OLE2CW          SSOLE2CW
        
            <FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifdef _MFC_VER</FONT>
        <FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifndef USES_CONVERSION</FONT>
    <FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifndef SS_NO_CONVERSION</FONT>
    <FONT color="#008000">// Define ostring - generic name for std::basic_string<OLECHAR></FONT>
    <FONT color="#0f4b95">#if</FONT> !defined(ostring) && !defined(OSTRING_DEFINED)
        <FONT color="#0f4b95">typedef</FONT> std::basic_string<OLECHAR> ostring;
        <FONT color="#0f4b95">#define</FONT> OSTRING_DEFINED
    <FONT color="#0f4b95">#endif</FONT>
  <FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifndef SS_ANSI</FONT>
<FONT color="#008000">// StdCodeCvt when there's no conversion to be done</FONT>
<FONT color="#0f4b95">inline</FONT> PSTR StdCodeCvt(PSTR pDst, PCSTR pSrc, <FONT color="#0f4b95">int</FONT> nChars)
{
    pDst[<FONT color="#a52a00">0</FONT>]             = <FONT color="#a52a00">'\0'</FONT>;
    std::char_traits<<FONT color="#0f4b95">char</FONT>>().copy(pDst, pSrc, nChars);
    <FONT color="#0f4b95">if</FONT> ( nChars > <FONT color="#a52a00">0</FONT> )
        pDst[nChars]    = <FONT color="#a52a00">'\0'</FONT>;
      <FONT color="#0f4b95">return</FONT> pDst;
}
<FONT color="#0f4b95">inline</FONT> PSTR StdCodeCvt(PSTR pDst, PCUSTR pSrc, <FONT color="#0f4b95">int</FONT> nChars)
{
    <FONT color="#0f4b95">return</FONT> StdCodeCvt(pDst, (PCSTR)pSrc, nChars);
}
<FONT color="#0f4b95">inline</FONT> PUSTR StdCodeCvt(PUSTR pDst, PCSTR pSrc, <FONT color="#0f4b95">int</FONT> nChars)
{
    <FONT color="#0f4b95">return</FONT> (PUSTR)StdCodeCvt((PSTR)pDst, pSrc, nChars);
}
  <FONT color="#0f4b95">inline</FONT> PWSTR StdCodeCvt(PWSTR pDst, PCWSTR pSrc, <FONT color="#0f4b95">int</FONT> nChars)
{
    pDst[<FONT color="#a52a00">0</FONT>]             = <FONT color="#a52a00">'\0'</FONT>;
    std::char_traits<wchar_t>().copy(pDst, pSrc, nChars);
    <FONT color="#0f4b95">if</FONT> ( nChars > <FONT color="#a52a00">0</FONT> )
        pDst[nChars]    = <FONT color="#a52a00">'\0'</FONT>;
      <FONT color="#0f4b95">return</FONT> pDst;
}
  
<FONT color="#008000">// Define tstring -- generic name for std::basic_string<TCHAR></FONT>
<FONT color="#0f4b95">#if</FONT> !defined(tstring) && !defined(TSTRING_DEFINED)
    <FONT color="#0f4b95">typedef</FONT> std::basic_string<TCHAR> tstring;
    <FONT color="#0f4b95">#define</FONT> TSTRING_DEFINED
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// a very shorthand way of applying the fix for KB problem Q172398</FONT>
<FONT color="#008000">// (basic_string assignment bug)</FONT>
<FONT color="#0f4b95">#if</FONT> defined ( _MSC_VER ) && ( _MSC_VER < <FONT color="#a52a00">1200</FONT> )
    <FONT color="#0f4b95">#define</FONT> Q172398(x) (x).erase()
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">#define</FONT> Q172398(x)
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">// INLINE FUNCTIONS ON WHICH CSTDSTRING RELIES</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// Usually for generic text mapping, we rely on preprocessor macro definitions</FONT>
<FONT color="#008000">// to map to string functions.  However the CStdStr<> template cannot use</FONT>
<FONT color="#008000">// macro-based generic text mappings because its character types do not get</FONT>
<FONT color="#008000">// resolved until template processing which comes AFTER macro processing.  In</FONT>
<FONT color="#008000">// other words, UNICODE is of little help to us in the CStdStr template</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// Therefore, to keep the CStdStr declaration simple, we have these inline</FONT>
<FONT color="#008000">// functions.  The template calls them often.  Since they are inline (and NOT</FONT>
<FONT color="#008000">// exported when this is built as a DLL), they will probably be resolved away</FONT>
<FONT color="#008000">// to nothing. </FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// Without these functions, the CStdStr<> template would probably have to broken</FONT>
<FONT color="#008000">// out into two, almost identical classes.  Either that or it would be a huge,</FONT>
<FONT color="#008000">// convoluted mess, with tons of "if" statements all over the place checking the</FONT>
<FONT color="#008000">// size of template parameter CT.</FONT>
<FONT color="#008000">// </FONT>
<FONT color="#008000">// In several cases, you will see two versions of each function.  One version is</FONT>
<FONT color="#008000">// the more portable, standard way of doing things, while the other is the</FONT>
<FONT color="#008000">// non-standard, but often significantly faster Visual C++ way.</FONT>
<FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">// If they defined SS_NO_REFCOUNT, then we must convert all assignments</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_NO_REFCOUNT
    <FONT color="#0f4b95">#define</FONT> SSREF(x) (x).c_str()
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">#define</FONT> SSREF(x) (x)
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// sslen: strlen/wcslen wrappers</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">template</FONT><typename CT> <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sslen(<FONT color="#0f4b95">const</FONT> CT* pT)
{
    <FONT color="#0f4b95">return</FONT> NULL == pT ? <FONT color="#a52a00">0</FONT> : std::char_traits<CT>::length(pT);
}
<FONT color="#0f4b95">inline</FONT> SS_NOTHROW <FONT color="#0f4b95">int</FONT> sslen(<FONT color="#0f4b95">const</FONT> std::string& s)
{
    <FONT color="#0f4b95">return</FONT> s.length();
}
<FONT color="#0f4b95">inline</FONT> SS_NOTHROW <FONT color="#0f4b95">int</FONT> sslen(<FONT color="#0f4b95">const</FONT> std::wstring& s)
{
    <FONT color="#0f4b95">return</FONT> s.length();
}
  
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// ssasn: assignment functions -- assign "sSrc" to "sDst"</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">typedef</FONT> std::string::size_type      SS_SIZETYPE; <FONT color="#008000">// just for shorthand, really</FONT>
<FONT color="#0f4b95">typedef</FONT> std::string::pointer        SS_PTRTYPE;  
<FONT color="#0f4b95">typedef</FONT> std::wstring::size_type     SW_SIZETYPE;
<FONT color="#0f4b95">typedef</FONT> std::wstring::pointer       SW_PTRTYPE;  
  <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::string& sDst, <FONT color="#0f4b95">const</FONT> std::string& sSrc)
{
    <FONT color="#0f4b95">if</FONT> ( sDst.c_str() != sSrc.c_str() )
    {
        sDst.erase();
        sDst.assign(SSREF(sSrc));
    }
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::string& sDst, PCSTR pA)
{
    <FONT color="#008000">// Watch out for NULLs, as always.</FONT>
    <FONT color="#0f4b95">if</FONT> ( NULL == pA )
    {
        sDst.erase();
    }
      <FONT color="#008000">// If pA actually points to part of sDst, we must NOT erase(), but</FONT>
    <FONT color="#008000">// rather take a substring</FONT>
    <FONT color="#0f4b95">else</FONT> <FONT color="#0f4b95">if</FONT> ( pA >= sDst.c_str() && pA <= sDst.c_str() + sDst.size() )
    {
        sDst =sDst.substr(static_cast<SS_SIZETYPE>(pA-sDst.c_str()));
    }
      <FONT color="#008000">// Otherwise (most cases) apply the assignment bug fix, if applicable</FONT>
    <FONT color="#008000">// and do the assignment</FONT>
    <FONT color="#0f4b95">else</FONT>
    {
        Q172398(sDst);
        sDst.assign(pA);
    }
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::string& sDst, <FONT color="#0f4b95">const</FONT> std::wstring& sSrc)
{
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">int</FONT> nLen    = sSrc.size();
    sDst.resize(<FONT color="#a52a00">0</FONT>);
    sDst.resize(nLen);
    StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()), sSrc.c_str(), nLen);
<FONT color="#0f4b95">#else</FONT>
    SSCVT;
    sDst.assign(SSW2CA(sSrc.c_str()));
<FONT color="#0f4b95">#endif</FONT>
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::string& sDst, PCWSTR pW)
{
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">int</FONT> nLen    = sslen(pW);
    sDst.resize(<FONT color="#a52a00">0</FONT>);
    sDst.resize(nLen);
    StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()), pW, nLen);
<FONT color="#0f4b95">#else</FONT>
    SSCVT;
    sDst.assign(pW ? SSW2CA(pW) : <FONT color="#a52a00">""</FONT>);
<FONT color="#0f4b95">#endif</FONT>
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::string& sDst, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT> nNull)
{
    UNUSED(nNull);
    ASSERT(nNull==NULL);
    sDst.assign(<FONT color="#a52a00">""</FONT>);
}   
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::wstring& sDst, <FONT color="#0f4b95">const</FONT> std::wstring& sSrc)
{
    <FONT color="#0f4b95">if</FONT> ( sDst.c_str() != sSrc.c_str() )
    {
        sDst.erase();
        sDst.assign(SSREF(sSrc));
    }
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::wstring& sDst, PCWSTR pW)
{
    <FONT color="#008000">// Watch out for NULLs, as always.</FONT>
    <FONT color="#0f4b95">if</FONT> ( NULL == pW )
    {
        sDst.erase();
    }
      <FONT color="#008000">// If pW actually points to part of sDst, we must NOT erase(), but</FONT>
    <FONT color="#008000">// rather take a substring</FONT>
    <FONT color="#0f4b95">else</FONT> <FONT color="#0f4b95">if</FONT> ( pW >= sDst.c_str() && pW <= sDst.c_str() + sDst.size() )
    {
        sDst = sDst.substr(static_cast<SW_SIZETYPE>(pW-sDst.c_str()));
    }
      <FONT color="#008000">// Otherwise (most cases) apply the assignment bug fix, if applicable</FONT>
    <FONT color="#008000">// and do the assignment</FONT>
    <FONT color="#0f4b95">else</FONT>
    {
        Q172398(sDst);
        sDst.assign(pW);
    }
}
<FONT color="#0f4b95">#undef</FONT> StrSizeType
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::wstring& sDst, <FONT color="#0f4b95">const</FONT> std::string& sSrc)
{
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">int</FONT> nLen    = sSrc.size();
    sDst.resize(<FONT color="#a52a00">0</FONT>);
    sDst.resize(nLen);
    StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()), sSrc.c_str(), nLen);
<FONT color="#0f4b95">#else</FONT>
    SSCVT;
    sDst.assign(SSA2CW(sSrc.c_str()));
<FONT color="#0f4b95">#endif</FONT>
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::wstring& sDst, PCSTR pA)
{
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">int</FONT> nLen    = sslen(pA);
    sDst.resize(<FONT color="#a52a00">0</FONT>);
    sDst.resize(nLen);
    StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()), pA, nLen);
<FONT color="#0f4b95">#else</FONT>
    SSCVT;
    sDst.assign(pA ? SSA2CW(pA) : L<FONT color="#a52a00">""</FONT>);
<FONT color="#0f4b95">#endif</FONT>
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssasn(std::wstring& sDst, <FONT color="#0f4b95">const</FONT> <FONT color="#0f4b95">int</FONT> nNull)
{
    UNUSED(nNull);
    ASSERT(nNull==NULL);
    sDst.assign(L<FONT color="#a52a00">""</FONT>);
}
  
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// ssadd: string object concatenation -- add second argument to first</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssadd(std::string& sDst, <FONT color="#0f4b95">const</FONT> std::wstring& sSrc)
{
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">int</FONT> nLen    = sSrc.size();
    sDst.resize(sDst.size() + nLen);
    StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()+nLen), sSrc.c_str(), nLen);
<FONT color="#0f4b95">#else</FONT>
    SSCVT; 
    sDst.append(SSW2CA(sSrc.c_str())); 
<FONT color="#0f4b95">#endif</FONT>
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssadd(std::string& sDst, <FONT color="#0f4b95">const</FONT> std::string& sSrc)
{ 
    sDst.append(sSrc.c_str());
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssadd(std::string& sDst, PCWSTR pW)
{
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">int</FONT> nLen    = sslen(pW);
    sDst.resize(sDst.size() + nLen);
    StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()+nLen), pW, nLen);
<FONT color="#0f4b95">#else</FONT>
    SSCVT;
    <FONT color="#0f4b95">if</FONT> ( NULL != pW )
        sDst.append(SSW2CA(pW)); 
<FONT color="#0f4b95">#endif</FONT>
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssadd(std::string& sDst, PCSTR pA)
{
    <FONT color="#0f4b95">if</FONT> ( pA )
        sDst.append(pA); 
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssadd(std::wstring& sDst, <FONT color="#0f4b95">const</FONT> std::wstring& sSrc)
{
    sDst.append(sSrc.c_str());
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssadd(std::wstring& sDst, <FONT color="#0f4b95">const</FONT> std::string& sSrc)
{
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">int</FONT> nLen    = sSrc.size();
    sDst.resize(sDst.size() + nLen);
    StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()+nLen), sSrc.c_str(), nLen);
<FONT color="#0f4b95">#else</FONT>
    SSCVT;
    sDst.append(SSA2CW(sSrc.c_str()));
<FONT color="#0f4b95">#endif</FONT>
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssadd(std::wstring& sDst, PCSTR pA)
{
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">int</FONT> nLen    = sslen(pA);
    sDst.resize(sDst.size() + nLen);
    StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()+nLen), pA, nLen);
<FONT color="#0f4b95">#else</FONT>
    SSCVT;
    <FONT color="#0f4b95">if</FONT> ( NULL != pA )
        sDst.append(SSA2CW(pA));
<FONT color="#0f4b95">#endif</FONT>
}
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssadd(std::wstring& sDst, PCWSTR pW)
{
    <FONT color="#0f4b95">if</FONT> ( pW )
        sDst.append(pW);
}
  
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// ssicmp: comparison (case insensitive )</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">template</FONT><typename CT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssicmp(<FONT color="#0f4b95">const</FONT> CT* pA1, <FONT color="#0f4b95">const</FONT> CT* pA2)
    {
        std::locale loc;
        <FONT color="#0f4b95">const</FONT> std::ctype<CT>& ct = SS_USE_FACET(loc, std::ctype<CT>);
        CT f;
        CT l;
              <FONT color="#0f4b95">do</FONT> 
            {
                f = ct.tolower(*(pA1++));
                l = ct.tolower(*(pA2++));
            } <FONT color="#0f4b95">while</FONT> ( (f) && (f == l) );
          <FONT color="#0f4b95">return</FONT> (<FONT color="#0f4b95">int</FONT>)(f - l);
    }
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">#ifdef</FONT> _MBCS
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">long</FONT> sscmp(PCSTR pA1, PCSTR pA2)
        {
            <FONT color="#0f4b95">return</FONT> _mbscmp((PCUSTR)pA1, (PCUSTR)pA2);
        }
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">long</FONT> ssicmp(PCSTR pA1, PCSTR pA2)
        {
            <FONT color="#0f4b95">return</FONT> _mbsicmp((PCUSTR)pA1, (PCUSTR)pA2);
        }
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">long</FONT> sscmp(PCSTR pA1, PCSTR pA2)
        {
            <FONT color="#0f4b95">return</FONT> strcmp(pA1, pA2);
        }
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">long</FONT> ssicmp(PCSTR pA1, PCSTR pA2)
        {
            <FONT color="#0f4b95">return</FONT> _stricmp(pA1, pA2);
        }
    <FONT color="#0f4b95">#endif</FONT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">long</FONT> sscmp(PCWSTR pW1, PCWSTR pW2)
    {
        <FONT color="#0f4b95">return</FONT> wcscmp(pW1, pW2);
    }
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">long</FONT> ssicmp(PCWSTR pW1, PCWSTR pW2)
    {
        <FONT color="#0f4b95">return</FONT> _wcsicmp(pW1, pW2);
    }
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// ssupr/sslwr: Uppercase/Lowercase conversion functions</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">template</FONT><typename CT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> sslwr(CT* pT, size_t nLen)
    {
        SS_USE_FACET(std::locale(), std::ctype<CT>).tolower(pT, pT+nLen);
    }
    <FONT color="#0f4b95">template</FONT><typename CT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssupr(CT* pT, size_t nLen)
    {
        SS_USE_FACET(std::locale(), std::ctype<CT>).toupper(pT, pT+nLen);
    }
<FONT color="#0f4b95">#else</FONT>  <FONT color="#008000">// #else we must be on Win32</FONT>
    <FONT color="#0f4b95">#ifdef</FONT> _MBCS
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssupr(PSTR pA, size_t <FONT color="#008000">/*nLen*/</FONT>)
        {
            _mbsupr((PUSTR)pA);
        }
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> sslwr(PSTR pA, size_t <FONT color="#008000">/*nLen*/</FONT>)
        {
            _mbslwr((PUSTR)pA);
        }
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssupr(PSTR pA, size_t <FONT color="#008000">/*nLen*/</FONT>)
        {
            _strupr(pA); 
        }
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> sslwr(PSTR pA, size_t <FONT color="#008000">/*nLen*/</FONT>)
        {
            _strlwr(pA);
        }
    <FONT color="#0f4b95">#endif</FONT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> ssupr(PWSTR pW, size_t <FONT color="#008000">/*nLen*/</FONT>)    
    {
        _wcsupr(pW);
    }
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">void</FONT> sslwr(PWSTR pW, size_t <FONT color="#008000">/*nLen*/</FONT>)    
    {
        _wcslwr(pW);
    }
<FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifdef SS_ANSI</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">//  vsprintf/vswprintf or _vsnprintf/_vsnwprintf equivalents.  In standard</FONT>
<FONT color="#008000">//  builds we can't use _vsnprintf/_vsnwsprintf because they're MS extensions.</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssvsprintf(PSTR pA, size_t <FONT color="#008000">/*nCount*/</FONT>, PCSTR pFmtA, va_list vl)
    {
        <FONT color="#0f4b95">return</FONT> vsprintf(pA, pFmtA, vl);
    }
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssvsprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl)
    {
    <FONT color="#0f4b95">#ifdef</FONT> __MWERKS__
        <FONT color="#0f4b95">return</FONT> vswprintf(pW, nCount, pFmtW, vl);
    <FONT color="#0f4b95">#else</FONT>
        nCount;
        <FONT color="#0f4b95">return</FONT> vswprintf(pW, pFmtW, vl);
    <FONT color="#0f4b95">#endif</FONT>
    }
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssvsprintf(PWSTR pW, PCWSTR pFmtW, va_list vl)
    {
        <FONT color="#0f4b95">return</FONT> vswprintf(pW, pFmtW, vl);
    }
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT>  ssnprintf(PSTR pA, size_t nCount, PCSTR pFmtA, va_list vl)
    { 
        <FONT color="#0f4b95">return</FONT> _vsnprintf(pA, nCount, pFmtA, vl);
    }
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT>  ssnprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl)
    {
        <FONT color="#0f4b95">return</FONT> _vsnwprintf(pW, nCount, pFmtW, vl);
    }
<FONT color="#0f4b95">#endif</FONT>
  
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// ssload: Type safe, overloaded ::LoadString wrappers</FONT>
<FONT color="#008000">// There is no equivalent of these in non-Win32-specific builds.  However, I'm</FONT>
<FONT color="#008000">// thinking that with the message facet, there might eventually be one</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssload(HMODULE hInst, UINT uId, PSTR pBuf, <FONT color="#0f4b95">int</FONT> nMax)
    {
        <FONT color="#0f4b95">return</FONT> ::LoadStringA(hInst, uId, pBuf, nMax);
    }
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssload(HMODULE hInst, UINT uId, PWSTR pBuf, <FONT color="#0f4b95">int</FONT> nMax)
    {
        <FONT color="#0f4b95">return</FONT> ::LoadStringW(hInst, uId, pBuf, nMax);
    }
<FONT color="#0f4b95">#endif</FONT>
  
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// sscoll/ssicoll: Collation wrappers</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">template</FONT> <typename CT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscoll(<FONT color="#0f4b95">const</FONT> CT* sz1, <FONT color="#0f4b95">int</FONT> nLen1, <FONT color="#0f4b95">const</FONT> CT* sz2, <FONT color="#0f4b95">int</FONT> nLen2)
    {
        <FONT color="#0f4b95">const</FONT> std::collate<CT>& coll =
            SS_USE_FACET(std::locale(), std::collate<CT>);
        <FONT color="#0f4b95">return</FONT> coll.compare(sz1, sz1+nLen1, sz2, sz2+nLen2);
    }
    <FONT color="#0f4b95">template</FONT> <typename CT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssicoll(<FONT color="#0f4b95">const</FONT> CT* sz1, <FONT color="#0f4b95">int</FONT> nLen1, <FONT color="#0f4b95">const</FONT> CT* sz2, <FONT color="#0f4b95">int</FONT> nLen2)
    {
        <FONT color="#0f4b95">const</FONT> std::locale loc;
        <FONT color="#0f4b95">const</FONT> std::collate<CT>& coll = SS_USE_FACET(loc, std::collate<CT>);
          std::collate<CT>::string_type s1(sz1);
        std::collate<CT>::string_type s2(sz2);
          sslwr(const_cast<CT*>(s1.c_str()), nLen1);
        sslwr(const_cast<CT*>(s2.c_str()), nLen2);
        <FONT color="#0f4b95">return</FONT> coll.compare(s1.c_str(), s1.c_str()+nLen1,
                            s2.c_str(), s2.c_str()+nLen2);
    }
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">#ifdef</FONT> _MBCS
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscoll(PCSTR sz1, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen1*/</FONT>, PCSTR sz2, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen2*/</FONT>)
        {
            <FONT color="#0f4b95">return</FONT> _mbscoll((PCUSTR)sz1, (PCUSTR)sz2);
        }
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssicoll(PCSTR sz1, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen1*/</FONT>, PCSTR sz2, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen2*/</FONT>)
        {
            <FONT color="#0f4b95">return</FONT> _mbsicoll((PCUSTR)sz1, (PCUSTR)sz2);
        }
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscoll(PCSTR sz1, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen1*/</FONT>, PCSTR sz2, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen2*/</FONT>)
        {
            <FONT color="#0f4b95">return</FONT> strcoll(sz1, sz2);
        }
        <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssicoll(PCSTR sz1, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen1*/</FONT>, PCSTR sz2, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen2*/</FONT>)
        {
            <FONT color="#0f4b95">return</FONT> _stricoll(sz1, sz2);
        }
    <FONT color="#0f4b95">#endif</FONT>
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscoll(PCWSTR sz1, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen1*/</FONT>, PCWSTR sz2, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen2*/</FONT>)
    {
        <FONT color="#0f4b95">return</FONT> wcscoll(sz1, sz2);
    }
    <FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> ssicoll(PCWSTR sz1, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen1*/</FONT>, PCWSTR sz2, <FONT color="#0f4b95">int</FONT> <FONT color="#008000">/*nLen2*/</FONT>)
    {
        <FONT color="#0f4b95">return</FONT> _wcsicoll(sz1, sz2);
    }
<FONT color="#0f4b95">#endif</FONT>
  
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// ssfmtmsg: FormatMessage equivalents.  Needed because I added a CString facade</FONT>
<FONT color="#008000">// Again -- no equivalent of these on non-Win32 builds but their might one day</FONT>
<FONT color="#008000">// be one if the message facet gets implemented</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">inline</FONT> DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId,
                          DWORD dwLangId, PSTR pBuf, DWORD nSize,
                          va_list* vlArgs)
    { 
        <FONT color="#0f4b95">return</FONT> FormatMessageA(dwFlags, pSrc, dwMsgId, dwLangId,
                              pBuf, nSize,vlArgs);
    }
    <FONT color="#0f4b95">inline</FONT> DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId,
                          DWORD dwLangId, PWSTR pBuf, DWORD nSize,
                          va_list* vlArgs)
    {
        <FONT color="#0f4b95">return</FONT> FormatMessageW(dwFlags, pSrc, dwMsgId, dwLangId,
                              pBuf, nSize,vlArgs);
    }
<FONT color="#0f4b95">#endif</FONT>
 
  
<FONT color="#008000">// FUNCTION: sscpy.  Copies up to 'nMax' characters from pSrc to pDst.</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// FUNCTION:  sscpy</FONT>
<FONT color="#008000">//      inline int sscpy(PSTR pDst, PCSTR pSrc, int nMax=-1);</FONT>
<FONT color="#008000">//      inline int sscpy(PUSTR pDst,  PCSTR pSrc, int nMax=-1)</FONT>
<FONT color="#008000">//      inline int sscpy(PSTR pDst, PCWSTR pSrc, int nMax=-1);</FONT>
<FONT color="#008000">//      inline int sscpy(PWSTR pDst, PCWSTR pSrc, int nMax=-1);</FONT>
<FONT color="#008000">//      inline int sscpy(PWSTR pDst, PCSTR pSrc, int nMax=-1);</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// DESCRIPTION:</FONT>
<FONT color="#008000">//      This function is very much (but not exactly) like strcpy.  These</FONT>
<FONT color="#008000">//      overloads simplify copying one C-style string into another by allowing</FONT>
<FONT color="#008000">//      the caller to specify two different types of strings if necessary.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      The strings must NOT overlap</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      "Character" is expressed in terms of the destination string, not</FONT>
<FONT color="#008000">//      the source.  If no 'nMax' argument is supplied, then the number of</FONT>
<FONT color="#008000">//      characters copied will be sslen(pSrc).  A NULL terminator will</FONT>
<FONT color="#008000">//      also be added so pDst must actually be big enough to hold nMax+1</FONT>
<FONT color="#008000">//      characters.  The return value is the number of characters copied,</FONT>
<FONT color="#008000">//      not including the NULL terminator.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// PARAMETERS: </FONT>
<FONT color="#008000">//      pSrc - the string to be copied FROM.  May be a char based string, an</FONT>
<FONT color="#008000">//             MBCS string (in Win32 builds) or a wide string (wchar_t).</FONT>
<FONT color="#008000">//      pSrc - the string to be copied TO.  Also may be either MBCS or wide</FONT>
<FONT color="#008000">//      nMax - the maximum number of characters to be copied into szDest.  Note</FONT>
<FONT color="#008000">//             that this is expressed in whatever a "character" means to pDst.</FONT>
<FONT color="#008000">//             If pDst is a wchar_t type string than this will be the maximum</FONT>
<FONT color="#008000">//             number of wchar_ts that my be copied.  The pDst string must be</FONT>
<FONT color="#008000">//             large enough to hold least nMaxChars+1 characters.</FONT>
<FONT color="#008000">//             If the caller supplies no argument for nMax this is a signal to</FONT>
<FONT color="#008000">//             the routine to copy all the characters in pSrc, regardless of</FONT>
<FONT color="#008000">//             how long it is.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// RETURN VALUE: none</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">template</FONT><typename CT1, typename CT2>
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscpycvt(CT1* pDst, <FONT color="#0f4b95">const</FONT> CT2* pSrc, <FONT color="#0f4b95">int</FONT> nChars)
{
    StdCodeCvt(pDst, pSrc, nChars);
    pDst[SSMAX(nChars, <FONT color="#a52a00">0</FONT>)]  = <FONT color="#a52a00">'\0'</FONT>;
    <FONT color="#0f4b95">return</FONT> nChars;
}
  <FONT color="#0f4b95">template</FONT><typename CT1, typename CT2>
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscpy(CT1* pDst, <FONT color="#0f4b95">const</FONT> CT2* pSrc, <FONT color="#0f4b95">int</FONT> nMax, <FONT color="#0f4b95">int</FONT> nLen)
{
    <FONT color="#0f4b95">return</FONT> sscpycvt(pDst, pSrc, SSMIN(nMax, nLen));
}
<FONT color="#0f4b95">template</FONT><typename CT1, typename CT2>
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscpy(CT1* pDst, <FONT color="#0f4b95">const</FONT> CT2* pSrc, <FONT color="#0f4b95">int</FONT> nMax)
{
    <FONT color="#0f4b95">return</FONT> sscpycvt(pDst, pSrc, SSMIN(nMax, sslen(pSrc)));
}
<FONT color="#0f4b95">template</FONT><typename CT1, typename CT2>
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscpy(CT1* pDst, <FONT color="#0f4b95">const</FONT> CT2* pSrc)
{
    <FONT color="#0f4b95">return</FONT> sscpycvt(pDst, pSrc, sslen(pSrc));
}
<FONT color="#0f4b95">template</FONT><typename CT1, typename CT2>
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscpy(CT1* pDst, <FONT color="#0f4b95">const</FONT> std::basic_string<CT2>& sSrc, <FONT color="#0f4b95">int</FONT> nMax)
{
    <FONT color="#0f4b95">return</FONT> sscpycvt(pDst, sSrc.c_str(), SSMIN(nMax, (<FONT color="#0f4b95">int</FONT>)sSrc.length()));
}
<FONT color="#0f4b95">template</FONT><typename CT1, typename CT2>
<FONT color="#0f4b95">inline</FONT> <FONT color="#0f4b95">int</FONT> sscpy(CT1* pDst, <FONT color="#0f4b95">const</FONT> std::basic_string<CT2>& sSrc)
{
    <FONT color="#0f4b95">return</FONT> sscpycvt(pDst, sSrc.c_str(), (<FONT color="#0f4b95">int</FONT>)sSrc.length());
}
 
 
 
 
  <FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// Functional objects for changing case.  They also let you pass locales</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">template</FONT><typename CT>
    <FONT color="#0f4b95">struct</FONT> SSToUpper : <FONT color="#0f4b95">public</FONT> std::binary_function<CT, std::locale, CT>
    {
        <FONT color="#0f4b95">inline</FONT> CT <FONT color="#0f4b95">operator</FONT>()(<FONT color="#0f4b95">const</FONT> CT& t, <FONT color="#0f4b95">const</FONT> std::locale& loc) <FONT color="#0f4b95">const</FONT>
        {
            <FONT color="#0f4b95">return</FONT> std::toupper<CT>(t, loc);
        }
    };
    <FONT color="#0f4b95">template</FONT><typename CT>
    <FONT color="#0f4b95">struct</FONT> SSToLower : <FONT color="#0f4b95">public</FONT> std::binary_function<CT, std::locale, CT>
    {
        <FONT color="#0f4b95">inline</FONT> CT <FONT color="#0f4b95">operator</FONT>()(<FONT color="#0f4b95">const</FONT> CT& t, <FONT color="#0f4b95">const</FONT> std::locale& loc) <FONT color="#0f4b95">const</FONT>
        {
            <FONT color="#0f4b95">return</FONT> std::tolower<CT>(t, loc);
        }
    };
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// struct SSSHDR - useful for non Std C++ persistence schemes.</FONT>
<FONT color="#0f4b95">typedef</FONT> <FONT color="#0f4b95">struct</FONT> SSSHDR
{
    BYTE    byCtrl;
    ULONG   nChars;
} SSSHDR;   <FONT color="#008000">// as in "Standard String Stream Header"</FONT>
<FONT color="#008000">// This struct is used for TrimRight() and TrimLeft() function implementations.</FONT>
<FONT color="#008000">//template<typename CT></FONT>
<FONT color="#008000">//struct NotSpace : public std::unary_function<CT, bool></FONT>
<FONT color="#008000">//{</FONT>
<FONT color="#008000">//  const std::locale& loc;</FONT>
<FONT color="#008000">//  inline NotSpace(const std::locale& locArg) : loc(locArg) {}</FONT>
<FONT color="#008000">//  inline bool operator() (CT t) { return !std::isspace(t, loc); }</FONT>
<FONT color="#008000">//};</FONT>
<FONT color="#0f4b95">template</FONT><typename CT>
<FONT color="#0f4b95">struct</FONT> NotSpace : <FONT color="#0f4b95">public</FONT> std::unary_function<CT, <FONT color="#0f4b95">bool</FONT>>
{
    <FONT color="#0f4b95">const</FONT> std::locale& loc;
    NotSpace(<FONT color="#0f4b95">const</FONT> std::locale& locArg) : loc(locArg) {}
      <FONT color="#008000">// DINKUMWARE BUG:</FONT>
    <FONT color="#008000">// Note -- using std::isspace in a COM DLL gives us access violations</FONT>
    <FONT color="#008000">// because it causes the dynamic addition of a function to be called</FONT>
    <FONT color="#008000">// when the library shuts down.  Unfortunately the list is maintained</FONT>
    <FONT color="#008000">// in DLL memory but the function is in static memory.  So the COM DLL</FONT>
    <FONT color="#008000">// goes away along with the function that was supposed to be called,</FONT>
    <FONT color="#008000">// and then later when the DLL CRT shuts down it unloads the list and</FONT>
    <FONT color="#008000">// tries to call the long-gone function.</FONT>
    <FONT color="#008000">// This is DinkumWare's implementation problem.  Until then, we will</FONT>
    <FONT color="#008000">// use good old isspace and iswspace from the CRT unless they</FONT>
    <FONT color="#008000">// specify SS_ANSI</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
    <FONT color="#0f4b95">bool</FONT> <FONT color="#0f4b95">operator</FONT>() <FONT color="#0f4b95">const</FONT> (CT t) { <FONT color="#0f4b95">return</FONT> !std::isspace(t, loc); }
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">bool</FONT> ssisp(<FONT color="#0f4b95">char</FONT> c) <FONT color="#0f4b95">const</FONT> { <FONT color="#0f4b95">return</FONT> FALSE != ::isspace((<FONT color="#0f4b95">int</FONT>) c); }
    <FONT color="#0f4b95">bool</FONT> ssisp(wchar_t c) <FONT color="#0f4b95">const</FONT> { <FONT color="#0f4b95">return</FONT> FALSE != ::iswspace((wint_t) c); }
    <FONT color="#0f4b95">bool</FONT> <FONT color="#0f4b95">operator</FONT>()(CT t) <FONT color="#0f4b95">const</FONT>  { <FONT color="#0f4b95">return</FONT> !ssisp(t); }
<FONT color="#0f4b95">#endif</FONT>
};
 
 
  
<FONT color="#008000">//          Now we can define the template (finally!)</FONT>
<FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">// TEMPLATE: CStdStr</FONT>
<FONT color="#008000">//      template<typename CT> class CStdStr : public std::basic_string<CT></FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// REMARKS:</FONT>
<FONT color="#008000">//      This template derives from basic_string<CT> and adds some MFC CString-</FONT>
<FONT color="#008000">//      like functionality</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      Basically, this is my attempt to make Standard C++ library strings as</FONT>
<FONT color="#008000">//      easy to use as the MFC CString class.</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      Note that although this is a template, it makes the assumption that the</FONT>
<FONT color="#008000">//      template argument (CT, the character type) is either char or wchar_t.  </FONT>
<FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">//#define CStdStr _SS   // avoid compiler warning 4786</FONT>
  <FONT color="#0f4b95">template</FONT><typename CT>
<FONT color="#0f4b95">class</FONT> CStdStr : <FONT color="#0f4b95">public</FONT> std::basic_string<CT>
{
    <FONT color="#008000">// Typedefs for shorter names.  Using these names also appears to help</FONT>
    <FONT color="#008000">// us avoid some ambiguities that otherwise arise on some platforms</FONT>
    <FONT color="#0f4b95">typedef</FONT> typename std::basic_string<CT>  MYBASE;  <FONT color="#008000">// my base class</FONT>
    <FONT color="#0f4b95">typedef</FONT> CStdStr<CT>                     MYTYPE;  <FONT color="#008000">// myself</FONT>
    <FONT color="#0f4b95">typedef</FONT> typename MYBASE::const_pointer  PCMYSTR; <FONT color="#008000">// PCSTR or PCWSTR </FONT>
    <FONT color="#0f4b95">typedef</FONT> typename MYBASE::pointer        PMYSTR;  <FONT color="#008000">// PSTR or PWSTR</FONT>
    <FONT color="#0f4b95">typedef</FONT> typename MYBASE::iterator       MYITER;  <FONT color="#008000">// my iterator type</FONT>
    <FONT color="#0f4b95">typedef</FONT> typename MYBASE::const_iterator MYCITER; <FONT color="#008000">// you get the idea...</FONT>
    <FONT color="#0f4b95">typedef</FONT> typename MYBASE::size_type      MYSIZE;   
    <FONT color="#0f4b95">typedef</FONT> typename MYBASE::value_type     MYVAL; 
    <FONT color="#0f4b95">typedef</FONT> typename MYBASE::allocator_type MYALLOC;
    
  <FONT color="#0f4b95">public</FONT>:
      <FONT color="#008000">// shorthand conversion from PCTSTR to string resource ID</FONT>
    <FONT color="#0f4b95">#define</FONT> _TRES(pctstr) (LOWORD((DWORD)(pctstr))) 
      <FONT color="#008000">// CStdStr inline constructors</FONT>
    CStdStr()
    {
    }
      CStdStr(<FONT color="#0f4b95">const</FONT> MYTYPE& str) : MYBASE(SSREF(str))
    {
    }
      CStdStr(<FONT color="#0f4b95">const</FONT> std::string& str)
    {
        ssasn(*<FONT color="#0f4b95">this</FONT>, SSREF(str));
    }
      CStdStr(<FONT color="#0f4b95">const</FONT> std::wstring& str)
    {
        ssasn(*<FONT color="#0f4b95">this</FONT>, SSREF(str));
    }
      CStdStr(PCMYSTR pT, MYSIZE n) : MYBASE(pT, n)
    {
    }
      CStdStr(PCSTR pA)
    {
    <FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
        *<FONT color="#0f4b95">this</FONT> = pA;
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">if</FONT> ( NULL != HIWORD(pA) )
            *<FONT color="#0f4b95">this</FONT> = pA;
        <FONT color="#0f4b95">else</FONT> <FONT color="#0f4b95">if</FONT> ( NULL != pA && !Load(_TRES(pA)) )
            TRACE(_T(<FONT color="#a52a00">"Can't load string %u\n"</FONT>), _TRES(pA));
    <FONT color="#0f4b95">#endif</FONT>
    }
      CStdStr(PCWSTR pW)
    {
    <FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
        *<FONT color="#0f4b95">this</FONT> = pW;
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">if</FONT> ( NULL != HIWORD(pW) )
            *<FONT color="#0f4b95">this</FONT> = pW;
        <FONT color="#0f4b95">else</FONT> <FONT color="#0f4b95">if</FONT> ( NULL != pW && !Load(_TRES(pW)) )
            TRACE(_T(<FONT color="#a52a00">"Can't load string %u\n"</FONT>), _TRES(pW));
    <FONT color="#0f4b95">#endif</FONT>
    }
      CStdStr(MYCITER first, MYCITER last)
        : MYBASE(first, last)
    {
    }
      CStdStr(MYSIZE nSize, MYVAL ch, <FONT color="#0f4b95">const</FONT> MYALLOC& al=MYALLOC())
        : MYBASE(nSize, ch, al)
    {
    }
      <FONT color="#0f4b95">#ifdef</FONT> SS_INC_COMDEF
        CStdStr(<FONT color="#0f4b95">const</FONT> _bstr_t& bstr)
        {
            *<FONT color="#0f4b95">this</FONT> = static_cast<PCTSTR>(bstr);
        }
    <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#008000">// CStdStr inline assignment operators -- the ssasn function now takes care</FONT>
    <FONT color="#008000">// of fixing  the MSVC assignment bug (see knowledge base article Q172398).</FONT>
    MYTYPE& <FONT color="#0f4b95">operator</FONT>=(<FONT color="#0f4b95">const</FONT> MYTYPE& str)
    { 
        ssasn(*<FONT color="#0f4b95">this</FONT>, str); 
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>=(<FONT color="#0f4b95">const</FONT> std::string& str)
    {
        ssasn(*<FONT color="#0f4b95">this</FONT>, str);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>=(<FONT color="#0f4b95">const</FONT> std::wstring& str)
    {
        ssasn(*<FONT color="#0f4b95">this</FONT>, str);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>=(PCSTR pA)
    {
        ssasn(*<FONT color="#0f4b95">this</FONT>, pA);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>=(PCWSTR pW)
    {
        ssasn(*<FONT color="#0f4b95">this</FONT>, pW);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>=(CT t)
    {
        Q172398(*<FONT color="#0f4b95">this</FONT>);
        MYBASE::assign(<FONT color="#a52a00">1</FONT>, t);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      <FONT color="#0f4b95">#ifdef</FONT> SS_INC_COMDEF
        MYTYPE& <FONT color="#0f4b95">operator</FONT>=(<FONT color="#0f4b95">const</FONT> _bstr_t& bstr)
        {
            <FONT color="#0f4b95">return</FONT> <FONT color="#0f4b95">operator</FONT>=(static_cast<<FONT color="#0f4b95">const</FONT> CT*>(bstr));
        }
    <FONT color="#0f4b95">#endif</FONT>
  
    <FONT color="#008000">// Overloads  also needed to fix the MSVC assignment bug (KB: Q172398)</FONT>
    <FONT color="#008000">//  *** Thanks to Pete The Plumber for catching this one ***</FONT>
    <FONT color="#008000">// They also are compiled if you have explicitly turned off refcounting</FONT>
    <FONT color="#0f4b95">#if</FONT> ( defined(_MSC_VER) && ( _MSC_VER < <FONT color="#a52a00">1200</FONT> ) ) || defined(SS_NO_REFCOUNT) 
          MYTYPE& assign(<FONT color="#0f4b95">const</FONT> MYTYPE& str)
        {
            ssasn(*<FONT color="#0f4b95">this</FONT>, str);
            <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
        }
          MYTYPE& assign(<FONT color="#0f4b95">const</FONT> MYTYPE& str, MYSIZE nStart, MYSIZE nChars)
        {
            <FONT color="#008000">// This overload of basic_string::assign is supposed to assign up to</FONT>
            <FONT color="#008000">// <nChars> or the NULL terminator, whichever comes first.  Since we</FONT>
            <FONT color="#008000">// are about to call a less forgiving overload (in which <nChars></FONT>
            <FONT color="#008000">// must be a valid length), we must adjust the length here to a safe</FONT>
            <FONT color="#008000">// value.  Thanks to Ullrich Pollähne for catching this bug</FONT>
            nChars      = SSMIN(nChars, str.length() - nStart);
              <FONT color="#008000">// Watch out for assignment to self</FONT>
            <FONT color="#0f4b95">if</FONT> ( <FONT color="#0f4b95">this</FONT> == &str )
            {
                MYTYPE strTemp(str.c_str()+nStart, nChars);
                assign(strTemp);
            }
            <FONT color="#0f4b95">else</FONT>
            {
                Q172398(*<FONT color="#0f4b95">this</FONT>);
                MYBASE::assign(str.c_str()+nStart, nChars);
            }
            <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
        }
          MYTYPE& assign(<FONT color="#0f4b95">const</FONT> MYBASE& str)
        {
            ssasn(*<FONT color="#0f4b95">this</FONT>, str);
            <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
        }
          MYTYPE& assign(<FONT color="#0f4b95">const</FONT> MYBASE& str, MYSIZE nStart, MYSIZE nChars)
        {
            <FONT color="#008000">// This overload of basic_string::assign is supposed to assign up to</FONT>
            <FONT color="#008000">// <nChars> or the NULL terminator, whichever comes first.  Since we</FONT>
            <FONT color="#008000">// are about to call a less forgiving overload (in which <nChars></FONT>
            <FONT color="#008000">// must be a valid length), we must adjust the length here to a safe</FONT>
            <FONT color="#008000">// value. Thanks to Ullrich Pollähne for catching this bug</FONT>
            nChars      = SSMIN(nChars, str.length() - nStart);
              <FONT color="#008000">// Watch out for assignment to self</FONT>
            <FONT color="#0f4b95">if</FONT> ( <FONT color="#0f4b95">this</FONT> == &str ) <FONT color="#008000">// watch out for assignment to self</FONT>
            {
                MYTYPE strTemp(str.c_str() + nStart, nChars);
                assign(strTemp);
            }
            <FONT color="#0f4b95">else</FONT>
            {
                Q172398(*<FONT color="#0f4b95">this</FONT>);
                MYBASE::assign(str.c_str()+nStart, nChars);
            }
            <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
        }
          MYTYPE& assign(<FONT color="#0f4b95">const</FONT> CT* pC, MYSIZE nChars)
        {
            <FONT color="#008000">// Q172398 only fix -- erase before assigning, but not if we're</FONT>
            <FONT color="#008000">// assigning from our own buffer</FONT>
    <FONT color="#0f4b95">#if</FONT> defined ( _MSC_VER ) && ( _MSC_VER < <FONT color="#a52a00">1200</FONT> )
            <FONT color="#0f4b95">if</FONT> ( !empty() && ( pC < data() || pC > data() + capacity() ) )
                erase();
    <FONT color="#0f4b95">#endif</FONT>
            Q172398(*<FONT color="#0f4b95">this</FONT>);
            MYBASE::assign(pC, nChars);
            <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
        }
          MYTYPE& assign(MYSIZE nChars, MYVAL val)
        {
            Q172398(*<FONT color="#0f4b95">this</FONT>);
            MYBASE::assign(nChars, val);
            <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
        }
          MYTYPE& assign(<FONT color="#0f4b95">const</FONT> CT* pT)
        {
            <FONT color="#0f4b95">return</FONT> assign(pT, CStdStr::traits_type::length(pT));
        }
          MYTYPE& assign(MYCITER iterFirst, MYCITER iterLast)
        {
    <FONT color="#0f4b95">#if</FONT> defined ( _MSC_VER ) && ( _MSC_VER < <FONT color="#a52a00">1200</FONT> ) 
            <FONT color="#008000">// Q172398 fix.  don't call erase() if we're assigning from ourself</FONT>
            <FONT color="#0f4b95">if</FONT> ( iterFirst < begin() || iterFirst > begin() + size() )
                erase()
    <FONT color="#0f4b95">#endif</FONT>
            replace(begin(), end(), iterFirst, iterLast);
            <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
        }
    <FONT color="#0f4b95">#endif</FONT>
  
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// CStdStr inline concatenation.</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    MYTYPE& <FONT color="#0f4b95">operator</FONT>+=(<FONT color="#0f4b95">const</FONT> MYTYPE& str)
    {
        ssadd(*<FONT color="#0f4b95">this</FONT>, str);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>+=(<FONT color="#0f4b95">const</FONT> std::string& str)
    {
        ssadd(*<FONT color="#0f4b95">this</FONT>, str);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>; 
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>+=(<FONT color="#0f4b95">const</FONT> std::wstring& str)
    {
        ssadd(*<FONT color="#0f4b95">this</FONT>, str);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>+=(PCSTR pA)
    {
        ssadd(*<FONT color="#0f4b95">this</FONT>, pA);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>+=(PCWSTR pW)
    {
        ssadd(*<FONT color="#0f4b95">this</FONT>, pW);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& <FONT color="#0f4b95">operator</FONT>+=(CT t)
    {
        append(<FONT color="#a52a00">1</FONT>, t);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
    <FONT color="#0f4b95">#ifdef</FONT> SS_INC_COMDEF    <FONT color="#008000">// if we have _bstr_t, define a += for it too.</FONT>
        MYTYPE& <FONT color="#0f4b95">operator</FONT>+=(<FONT color="#0f4b95">const</FONT> _bstr_t& bstr)
        {
            <FONT color="#0f4b95">return</FONT> <FONT color="#0f4b95">operator</FONT>+=(static_cast<PCMYSTR>(bstr));
        }
    <FONT color="#0f4b95">#endif</FONT>
  
    <FONT color="#008000">// addition operators -- global friend functions.</FONT>
    <FONT color="#0f4b95">friend</FONT>  MYTYPE  <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT> MYTYPE& str1,   <FONT color="#0f4b95">const</FONT> MYTYPE& str2);
    <FONT color="#0f4b95">friend</FONT>  MYTYPE  <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT> MYTYPE& str,    CT t);
    <FONT color="#0f4b95">friend</FONT>  MYTYPE  <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT> MYTYPE& str,    PCSTR sz);
    <FONT color="#0f4b95">friend</FONT>  MYTYPE  <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT> MYTYPE& str,    PCWSTR sz);
    <FONT color="#0f4b95">friend</FONT>  MYTYPE  <FONT color="#0f4b95">operator</FONT>+(PCSTR pA,             <FONT color="#0f4b95">const</FONT> MYTYPE& str);
    <FONT color="#0f4b95">friend</FONT>  MYTYPE  <FONT color="#0f4b95">operator</FONT>+(PCWSTR pW,            <FONT color="#0f4b95">const</FONT> MYTYPE& str);
<FONT color="#0f4b95">#ifdef</FONT> SS_INC_COMDEF
    <FONT color="#0f4b95">friend</FONT>  MYTYPE  <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT> _bstr_t& bstr,  <FONT color="#0f4b95">const</FONT> MYTYPE& str);
    <FONT color="#0f4b95">friend</FONT>  MYTYPE  <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT> MYTYPE& str,    <FONT color="#0f4b95">const</FONT> _bstr_t& bstr);
<FONT color="#0f4b95">#endif</FONT>
      <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// Case changing functions</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    MYTYPE& ToUpper()
    {
    <FONT color="#008000">//  Strictly speaking, this would be about the most portable way</FONT>
    <FONT color="#008000">//  std::transform(begin(),</FONT>
    <FONT color="#008000">//                 end(),</FONT>
    <FONT color="#008000">//                 begin(),</FONT>
    <FONT color="#008000">//                 std::bind2nd(SSToUpper<CT>(), std::locale()));</FONT>
        <FONT color="#008000">// But practically speaking, this works faster</FONT>
        <FONT color="#0f4b95">if</FONT> ( !empty() )
            ssupr(GetBuf(), size());
          <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
 
 
      MYTYPE& ToLower()
    {
    <FONT color="#008000">//  Strictly speaking, this would be about the most portable way</FONT>
    <FONT color="#008000">//  std::transform(begin(),</FONT>
    <FONT color="#008000">//                 end(),</FONT>
    <FONT color="#008000">//                 begin(),</FONT>
    <FONT color="#008000">//                 std::bind2nd(SSToLower<CT>(), std::locale()));</FONT>
        <FONT color="#008000">// But practically speaking, this works faster</FONT>
        <FONT color="#0f4b95">if</FONT> ( !empty() )
            sslwr(GetBuf(), size());
          <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
 
 
      MYTYPE& Normalize()
    {
        <FONT color="#0f4b95">return</FONT> Trim().ToLower();
    }
  
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// CStdStr -- Direct access to character buffer.  In the MS' implementation,</FONT>
    <FONT color="#008000">// the at() function that we use here also calls _Freeze() providing us some</FONT>
    <FONT color="#008000">// protection from multithreading problems associated with ref-counting.</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    CT* GetBuf(<FONT color="#0f4b95">int</FONT> nMinLen=-<FONT color="#a52a00">1</FONT>)
    {
        <FONT color="#0f4b95">if</FONT> ( static_cast<<FONT color="#0f4b95">int</FONT>>(size()) < nMinLen )
            resize(static_cast<MYSIZE>(nMinLen));
          <FONT color="#0f4b95">return</FONT> empty() ? const_cast<CT*>(data()) : &(at(<FONT color="#a52a00">0</FONT>));
    }
      CT* SetBuf(<FONT color="#0f4b95">int</FONT> nLen)
    {
        nLen = ( nLen > <FONT color="#a52a00">0</FONT> ? nLen : <FONT color="#a52a00">0</FONT> );
        <FONT color="#0f4b95">if</FONT> ( capacity() < <FONT color="#a52a00">1</FONT> && nLen == <FONT color="#a52a00">0</FONT> )
            resize(<FONT color="#a52a00">1</FONT>);
          resize(static_cast<MYSIZE>(nLen));
        <FONT color="#0f4b95">return</FONT> const_cast<CT*>(data());
    }
    <FONT color="#0f4b95">void</FONT> RelBuf(<FONT color="#0f4b95">int</FONT> nNewLen=-<FONT color="#a52a00">1</FONT>)
    {
        resize(static_cast<MYSIZE>(nNewLen > -<FONT color="#a52a00">1</FONT> ? nNewLen : sslen(c_str())));
    }
      <FONT color="#0f4b95">void</FONT> BufferRel()         { RelBuf(); }          <FONT color="#008000">// backwards compatability</FONT>
    CT*  Buffer()            { <FONT color="#0f4b95">return</FONT> GetBuf(); }   <FONT color="#008000">// backwards compatability</FONT>
    CT*  BufferSet(<FONT color="#0f4b95">int</FONT> nLen) { <FONT color="#0f4b95">return</FONT> SetBuf(nLen);}<FONT color="#008000">// backwards compatability</FONT>
    <FONT color="#0f4b95">bool</FONT> Equals(<FONT color="#0f4b95">const</FONT> CT* pT, <FONT color="#0f4b95">bool</FONT> bUseCase=false) <FONT color="#0f4b95">const</FONT>
    {   <FONT color="#008000">// get copy, THEN compare (thread safe)</FONT>
        <FONT color="#0f4b95">return</FONT>  bUseCase ? compare(pT) == <FONT color="#a52a00">0</FONT> : ssicmp(MYTYPE(*<FONT color="#0f4b95">this</FONT>), pT) == <FONT color="#a52a00">0</FONT>;
    } 
      <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// FUNCTION:  CStdStr::Load</FONT>
    <FONT color="#008000">// REMARKS:</FONT>
    <FONT color="#008000">//      Loads string from resource specified by nID</FONT>
    <FONT color="#008000">//</FONT>
    <FONT color="#008000">// PARAMETERS:</FONT>
    <FONT color="#008000">//      nID - resource Identifier.  Purely a Win32 thing in this case</FONT>
    <FONT color="#008000">//</FONT>
    <FONT color="#008000">// RETURN VALUE:</FONT>
    <FONT color="#008000">//      true if successful, false otherwise</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifndef</FONT> SS_ANSI
    <FONT color="#0f4b95">bool</FONT> Load(UINT nId, HMODULE hModule=NULL)
    {
        <FONT color="#0f4b95">bool</FONT> bLoaded        = false;    <FONT color="#008000">// set to true of we succeed.</FONT>
    <FONT color="#0f4b95">#ifdef</FONT> _MFC_VER     <FONT color="#008000">// When in Rome...</FONT>
        CString strRes;
        bLoaded             = FALSE != strRes.LoadString(nId);
        <FONT color="#0f4b95">if</FONT> ( bLoaded )
            *<FONT color="#0f4b95">this</FONT>           = strRes;
      <FONT color="#0f4b95">#else</FONT>
        
        <FONT color="#008000">// Get the resource name and module handle</FONT>
        <FONT color="#0f4b95">if</FONT> ( NULL == hModule )
            hModule         = GetResourceHandle();
          PCTSTR szName       = MAKEINTRESOURCE((nId>><FONT color="#a52a00">4</FONT>)+<FONT color="#a52a00">1</FONT>); <FONT color="#008000">// lifted </FONT>
        DWORD dwSize        = <FONT color="#a52a00">0</FONT>;
          <FONT color="#008000">// No sense continuing if we can't find the resource</FONT>
        HRSRC hrsrc         = ::<FONT color="#0f4b95">FindResource</FONT>(hModule, szName, RT_STRING);
          <FONT color="#0f4b95">if</FONT> ( NULL == hrsrc )
            TRACE(_T(<FONT color="#a52a00">"Cannot find resource %d: 0x%X"</FONT>), nId, ::GetLastError());
        <FONT color="#0f4b95">else</FONT> <FONT color="#0f4b95">if</FONT> ( <FONT color="#a52a00">0</FONT> == (dwSize = ::<FONT color="#0f4b95">SizeofResource</FONT>(hModule, hrsrc) / <FONT color="#0f4b95">sizeof</FONT>(CT)))
            TRACE(_T(<FONT color="#a52a00">"Cant get size of resource %d 0x%X\n"</FONT>),nId,GetLastError());
        <FONT color="#0f4b95">else</FONT>
        {
            bLoaded         = <FONT color="#a52a00">0</FONT> != ssload(hModule, nId, GetBuf(dwSize), dwSize);
            ReleaseBuffer();
        }
      <FONT color="#0f4b95">#endif</FONT>
          <FONT color="#0f4b95">if</FONT> ( !bLoaded )
            TRACE(_T(<FONT color="#a52a00">"String not loaded 0x%X\n"</FONT>), ::GetLastError());
          <FONT color="#0f4b95">return</FONT> bLoaded;
    }
<FONT color="#0f4b95">#endif</FONT>
    
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// FUNCTION:  CStdStr::Format</FONT>
    <FONT color="#008000">//      void _cdecl Formst(CStdStringA& PCSTR szFormat, ...)</FONT>
    <FONT color="#008000">//      void _cdecl Format(PCSTR szFormat);</FONT>
    <FONT color="#008000">//           </FONT>
    <FONT color="#008000">// DESCRIPTION:</FONT>
    <FONT color="#008000">//      This function does sprintf/wsprintf style formatting on CStdStringA</FONT>
    <FONT color="#008000">//      objects.  It looks a lot like MFC's CString::Format.  Some people</FONT>
    <FONT color="#008000">//      might even call this identical.  Fortunately, these people are now</FONT>
    <FONT color="#008000">//      dead.</FONT>
    <FONT color="#008000">//</FONT>
    <FONT color="#008000">// PARAMETERS: </FONT>
    <FONT color="#008000">//      nId - ID of string resource holding the format string</FONT>
    <FONT color="#008000">//      szFormat - a PCSTR holding the format specifiers</FONT>
    <FONT color="#008000">//      argList - a va_list holding the arguments for the format specifiers.</FONT>
    <FONT color="#008000">//</FONT>
    <FONT color="#008000">// RETURN VALUE:  None.</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// formatting (using wsprintf style formatting)</FONT>
    <FONT color="#0f4b95">#ifndef</FONT> SS_ANSI
    <FONT color="#0f4b95">void</FONT> Format(UINT nId, ...)
    {
        va_list argList;
        va_start(argList, nId);
        va_start(argList, nId);
          MYTYPE strFmt;
        <FONT color="#0f4b95">if</FONT> ( strFmt.Load(nId) )
            FormatV(strFmt, argList);
          va_end(argList);
    }
    <FONT color="#0f4b95">#endif</FONT>
    <FONT color="#0f4b95">void</FONT> Format(<FONT color="#0f4b95">const</FONT> CT* szFmt, ...)
    {
        va_list argList;
        va_start(argList, szFmt);
        FormatV(szFmt, argList);
        va_end(argList);
    }
    <FONT color="#0f4b95">void</FONT> AppendFormat(<FONT color="#0f4b95">const</FONT> CT* szFmt, ...)
    {
        va_list argList;
        va_start(argList, szFmt);
        AppendFormatV(szFmt, argList);
        va_end(argList);
    }
      <FONT color="#0f4b95">#define</FONT> MAX_FMT_TRIES       <FONT color="#a52a00">5</FONT>    <FONT color="#008000">// #of times we try </FONT>
    <FONT color="#0f4b95">#define</FONT> FMT_BLOCK_SIZE      <FONT color="#a52a00">2048</FONT> <FONT color="#008000">// # of bytes to increment per try</FONT>
    <FONT color="#0f4b95">#define</FONT> BUFSIZE_1ST <FONT color="#a52a00">256</FONT>
    <FONT color="#0f4b95">#define</FONT> BUFSIZE_2ND <FONT color="#a52a00">512</FONT>
    <FONT color="#0f4b95">#define</FONT> STD_BUF_SIZE        <FONT color="#a52a00">1024</FONT>
      <FONT color="#008000">// an efficient way to add formatted characters to the string.  You may only</FONT>
    <FONT color="#008000">// add up to STD_BUF_SIZE characters at a time, though</FONT>
    <FONT color="#0f4b95">void</FONT> AppendFormatV(<FONT color="#0f4b95">const</FONT> CT* szFmt, va_list argList)
    {
        CT szBuf[STD_BUF_SIZE];
    <FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
        <FONT color="#0f4b95">int</FONT> nLen = ssvsprintf(szBuf, STD_BUF_SIZE-<FONT color="#a52a00">1</FONT>, szFmt, argList);
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">int</FONT> nLen = ssnprintf(szBuf, STD_BUF_SIZE-<FONT color="#a52a00">1</FONT>, szFmt, argList);
    <FONT color="#0f4b95">#endif</FONT>
        <FONT color="#0f4b95">if</FONT> ( <FONT color="#a52a00">0</FONT> < nLen )
            append(szBuf, nLen);
    }
      <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// FUNCTION:  FormatV</FONT>
    <FONT color="#008000">//      void FormatV(PCSTR szFormat, va_list, argList);</FONT>
    <FONT color="#008000">//           </FONT>
    <FONT color="#008000">// DESCRIPTION:</FONT>
    <FONT color="#008000">//      This function formats the string with sprintf style format-specs. </FONT>
    <FONT color="#008000">//      It makes a general guess at required buffer size and then tries</FONT>
    <FONT color="#008000">//      successively larger buffers until it finds one big enough or a</FONT>
    <FONT color="#008000">//      threshold (MAX_FMT_TRIES) is exceeded.</FONT>
    <FONT color="#008000">//</FONT>
    <FONT color="#008000">// PARAMETERS: </FONT>
    <FONT color="#008000">//      szFormat - a PCSTR holding the format of the output</FONT>
    <FONT color="#008000">//      argList - a Microsoft specific va_list for variable argument lists</FONT>
    <FONT color="#008000">//</FONT>
    <FONT color="#008000">// RETURN VALUE: </FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#0f4b95">void</FONT> FormatV(<FONT color="#0f4b95">const</FONT> CT* szFormat, va_list argList)
    {
    <FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
          <FONT color="#0f4b95">int</FONT> nLen    = sslen(szFormat) + STD_BUF_SIZE;
        ssvsprintf(GetBuffer(nLen), nLen-<FONT color="#a52a00">1</FONT>, szFormat, argList);
        ReleaseBuffer();
      <FONT color="#0f4b95">#else</FONT>
          CT* pBuf            = NULL;
        <FONT color="#0f4b95">int</FONT> nChars          = <FONT color="#a52a00">1</FONT>;
        <FONT color="#0f4b95">int</FONT> nUsed           = <FONT color="#a52a00">0</FONT>;
        size_type nActual   = <FONT color="#a52a00">0</FONT>;
        <FONT color="#0f4b95">int</FONT> nTry            = <FONT color="#a52a00">0</FONT>;
          <FONT color="#0f4b95">do</FONT>  
        {
            <FONT color="#008000">// Grow more than linearly (e.g. 512, 1536, 3072, etc)</FONT>
            nChars          += (nTry+<FONT color="#a52a00">1</FONT> * FMT_BLOCK_SIZE);
            pBuf            = reinterpret_cast<CT*>(_alloca(<FONT color="#0f4b95">sizeof</FONT>(CT)*nChars));
            nUsed           = ssnprintf(pBuf, nChars-<FONT color="#a52a00">1</FONT>, szFormat, argList);
              <FONT color="#008000">// Ensure proper NULL termination.</FONT>
            nActual         = nUsed == -<FONT color="#a52a00">1</FONT> ? nChars-<FONT color="#a52a00">1</FONT> : SSMIN(nUsed, nChars-<FONT color="#a52a00">1</FONT>);
            pBuf[nActual+<FONT color="#a52a00">1</FONT>]= <FONT color="#a52a00">'\0'</FONT>;
  
        } <FONT color="#0f4b95">while</FONT> ( nUsed < <FONT color="#a52a00">0</FONT> && nTry++ < MAX_FMT_TRIES );
          <FONT color="#008000">// assign whatever we managed to format</FONT>
        assign(pBuf, nActual);
      <FONT color="#0f4b95">#endif</FONT>
    }
    
      <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// CString Facade Functions:</FONT>
    <FONT color="#008000">//</FONT>
    <FONT color="#008000">// The following methods are intended to allow you to use this class as a</FONT>
    <FONT color="#008000">// drop-in replacement for CString.</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#0f4b95">#ifndef</FONT> SS_ANSI
        BSTR AllocSysString() <FONT color="#0f4b95">const</FONT>
        {
            ostring os;
            ssasn(os, *<FONT color="#0f4b95">this</FONT>);
            <FONT color="#0f4b95">return</FONT> ::SysAllocString(os.c_str());
        }
    <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#0f4b95">int</FONT> Collate(PCMYSTR szThat) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> sscoll(c_str(), length(), szThat, sslen(szThat));
    }
      <FONT color="#0f4b95">int</FONT> CollateNoCase(PCMYSTR szThat) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> ssicoll(c_str(), length(), szThat, sslen(szThat));
    }
      <FONT color="#0f4b95">int</FONT> CompareNoCase(PCMYSTR szThat)   <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> ssicmp(c_str(), szThat);
    }
      <FONT color="#0f4b95">int</FONT> Delete(<FONT color="#0f4b95">int</FONT> nIdx, <FONT color="#0f4b95">int</FONT> nCount=<FONT color="#a52a00">1</FONT>)
    {
        <FONT color="#0f4b95">if</FONT> ( nIdx < GetLength() )
            erase(static_cast<MYSIZE>(nIdx), static_cast<MYSIZE>(nCount));
          <FONT color="#0f4b95">return</FONT> GetLength();
    }
      <FONT color="#0f4b95">void</FONT> Empty()
    {
        erase();
    }
      <FONT color="#0f4b95">int</FONT> Find(CT ch) <FONT color="#0f4b95">const</FONT>
    {
        MYSIZE nIdx = find_first_of(ch);
        <FONT color="#0f4b95">return</FONT> static_cast<<FONT color="#0f4b95">int</FONT>>(nIdx == npos ? -<FONT color="#a52a00">1</FONT> : nIdx);
    }
      <FONT color="#0f4b95">int</FONT> Find(PCMYSTR szSub) <FONT color="#0f4b95">const</FONT>
    {
        MYSIZE nIdx = find(szSub);
        <FONT color="#0f4b95">return</FONT> static_cast<<FONT color="#0f4b95">int</FONT>>(nIdx == npos ? -<FONT color="#a52a00">1</FONT> : nIdx);
    }
      <FONT color="#0f4b95">int</FONT> Find(CT ch, <FONT color="#0f4b95">int</FONT> nStart) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#008000">// CString::Find docs say add 1 to nStart when it's not zero</FONT>
        <FONT color="#008000">// CString::Find code doesn't do that however.  We'll stick</FONT>
        <FONT color="#008000">// with what the code does</FONT>
        MYSIZE nIdx = find_first_of(ch, static_cast<MYSIZE>(nStart));
        <FONT color="#0f4b95">return</FONT> static_cast<<FONT color="#0f4b95">int</FONT>>(nIdx == npos ? -<FONT color="#a52a00">1</FONT> : nIdx);
    }
      <FONT color="#0f4b95">int</FONT> Find(PCMYSTR szSub, <FONT color="#0f4b95">int</FONT> nStart) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#008000">// CString::Find docs say add 1 to nStart when it's not zero</FONT>
        <FONT color="#008000">// CString::Find code doesn't do that however.  We'll stick</FONT>
        <FONT color="#008000">// with what the code does</FONT>
        MYSIZE nIdx = find(szSub, static_cast<MYSIZE>(nStart));
        <FONT color="#0f4b95">return</FONT> static_cast<<FONT color="#0f4b95">int</FONT>>(nIdx == npos ? -<FONT color="#a52a00">1</FONT> : nIdx);
    }
      <FONT color="#0f4b95">int</FONT> FindOneOf(PCMYSTR szCharSet) <FONT color="#0f4b95">const</FONT>
    {
        MYSIZE nIdx = find_first_of(szCharSet);
        <FONT color="#0f4b95">return</FONT> static_cast<<FONT color="#0f4b95">int</FONT>>(nIdx == npos ? -<FONT color="#a52a00">1</FONT> : nIdx);
    }
  <FONT color="#0f4b95">#ifndef</FONT> SS_ANSI
    <FONT color="#0f4b95">void</FONT> FormatMessage(PCMYSTR szFormat, ...) throw(std::exception)
    {
        va_list argList;
        va_start(argList, szFormat);
        PMYSTR szTemp;
        <FONT color="#0f4b95">if</FONT> ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
                       szFormat, <FONT color="#a52a00">0</FONT>, <FONT color="#a52a00">0</FONT>,
                       reinterpret_cast<PMYSTR>(&szTemp), <FONT color="#a52a00">0</FONT>, &argList) == <FONT color="#a52a00">0</FONT> ||
             szTemp == NULL )
        {
            throw std::runtime_error(<FONT color="#a52a00">"out of memory"</FONT>);
        }
        *<FONT color="#0f4b95">this</FONT> = szTemp;
        <FONT color="#0f4b95">LocalFree</FONT>(szTemp);
        va_end(argList);
    }
      <FONT color="#0f4b95">void</FONT> FormatMessage(UINT nFormatId, ...) throw(std::exception)
    {
        MYTYPE sFormat;
        VERIFY(sFormat.LoadString(nFormatId) != <FONT color="#a52a00">0</FONT>);
        va_list argList;
        va_start(argList, nFormatId);
        PMYSTR szTemp;
        <FONT color="#0f4b95">if</FONT> ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
                       sFormat, <FONT color="#a52a00">0</FONT>, <FONT color="#a52a00">0</FONT>,
                       reinterpret_cast<PMYSTR>(&szTemp), <FONT color="#a52a00">0</FONT>, &argList) == <FONT color="#a52a00">0</FONT> ||
            szTemp == NULL)
        {
            throw std::runtime_error(<FONT color="#a52a00">"out of memory"</FONT>);
        }
        *<FONT color="#0f4b95">this</FONT> = szTemp;
        <FONT color="#0f4b95">LocalFree</FONT>(szTemp);
        va_end(argList);
    }
<FONT color="#0f4b95">#endif</FONT>
  
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// GetXXXX -- Direct access to character buffer</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    CT GetAt(<FONT color="#0f4b95">int</FONT> nIdx) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> at(static_cast<MYSIZE>(nIdx));
    }
      CT* GetBuffer(<FONT color="#0f4b95">int</FONT> nMinLen=-<FONT color="#a52a00">1</FONT>)
    {
        <FONT color="#0f4b95">return</FONT> GetBuf(nMinLen);
    }
      CT* GetBufferSetLength(<FONT color="#0f4b95">int</FONT> nLen)
    {
        <FONT color="#0f4b95">return</FONT> BufferSet(nLen);
    }
      <FONT color="#008000">// GetLength() -- MFC docs say this is the # of BYTES but</FONT>
    <FONT color="#008000">// in truth it is the number of CHARACTERs (chars or wchar_ts)</FONT>
    <FONT color="#0f4b95">int</FONT> GetLength() <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> static_cast<<FONT color="#0f4b95">int</FONT>>(length());
    }
      
    <FONT color="#0f4b95">int</FONT> Insert(<FONT color="#0f4b95">int</FONT> nIdx, CT ch)
    {
        <FONT color="#0f4b95">if</FONT> ( static_cast<MYSIZE>(nIdx) > size() -<FONT color="#a52a00">1</FONT> )
            append(<FONT color="#a52a00">1</FONT>, ch);
        <FONT color="#0f4b95">else</FONT>
            insert(static_cast<MYSIZE>(nIdx), <FONT color="#a52a00">1</FONT>, ch);
          <FONT color="#0f4b95">return</FONT> GetLength();
    }
      <FONT color="#0f4b95">int</FONT> Insert(<FONT color="#0f4b95">int</FONT> nIdx, PCMYSTR sz)
    {
        insert(static_cast<MYSIZE>(nIdx), sz);
        <FONT color="#0f4b95">return</FONT> GetLength();
    }
      <FONT color="#0f4b95">bool</FONT> IsEmpty() <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> empty();
    }
      MYTYPE Left(<FONT color="#0f4b95">int</FONT> nCount) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> substr(<FONT color="#a52a00">0</FONT>, static_cast<MYSIZE>(nCount)); 
    }
      <FONT color="#0f4b95">#ifndef</FONT> SS_ANSI
    <FONT color="#0f4b95">bool</FONT> <FONT color="#0f4b95">LoadString</FONT>(UINT nId)
    {
        <FONT color="#0f4b95">return</FONT> <FONT color="#0f4b95">this</FONT>->Load(nId);
    }
    <FONT color="#0f4b95">#endif</FONT>
      <FONT color="#0f4b95">void</FONT> MakeLower()
    {
        ToLower();
    }
      <FONT color="#0f4b95">void</FONT> MakeReverse()
    {
        std::reverse(begin(), end());
    }
      <FONT color="#0f4b95">void</FONT> MakeUpper()
    { 
        ToUpper();
    }
      MYTYPE Mid(<FONT color="#0f4b95">int</FONT> nFirst ) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> substr(static_cast<MYSIZE>(nFirst));
    }
      MYTYPE Mid(<FONT color="#0f4b95">int</FONT> nFirst, <FONT color="#0f4b95">int</FONT> nCount) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> substr(static_cast<MYSIZE>(nFirst), static_cast<MYSIZE>(nCount));
    }
      <FONT color="#0f4b95">void</FONT> ReleaseBuffer(<FONT color="#0f4b95">int</FONT> nNewLen=-<FONT color="#a52a00">1</FONT>)
    {
        RelBuf(nNewLen);
    }
      <FONT color="#0f4b95">int</FONT> Remove(CT ch)
    {
        MYSIZE nIdx     = <FONT color="#a52a00">0</FONT>;
        <FONT color="#0f4b95">int</FONT> nRemoved    = <FONT color="#a52a00">0</FONT>;
        <FONT color="#0f4b95">while</FONT> ( (nIdx=find_first_of(ch)) != npos )
        {
            erase(nIdx, <FONT color="#a52a00">1</FONT>);
            nRemoved++;
        }
        <FONT color="#0f4b95">return</FONT> nRemoved;
    }
      <FONT color="#0f4b95">int</FONT> Replace(CT chOld, CT chNew)
    {
        <FONT color="#0f4b95">int</FONT> nReplaced   = <FONT color="#a52a00">0</FONT>;
        <FONT color="#0f4b95">for</FONT> ( MYITER iter=begin(); iter != end(); iter++ )
        {
            <FONT color="#0f4b95">if</FONT> ( *iter == chOld )
            {
                *iter = chNew;
                nReplaced++;
            }
        }
        <FONT color="#0f4b95">return</FONT> nReplaced;
    }
      <FONT color="#0f4b95">int</FONT> Replace(PCMYSTR szOld, PCMYSTR szNew)
    {
        <FONT color="#0f4b95">int</FONT> nReplaced       = <FONT color="#a52a00">0</FONT>;
        MYSIZE nIdx         = <FONT color="#a52a00">0</FONT>;
        <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">const</FONT> CT _C  = CT(<FONT color="#a52a00">0</FONT>);
        MYSIZE nOldLen      = sslen(szOld);
        MYSIZE nNewLen      = sslen(szNew);
        PCMYSTR szRealNew   = szNew == NULL ? &_C : szNew;
        PCMYSTR szRealOld   = szOld == NULL ? &_C : szOld;
        <FONT color="#0f4b95">while</FONT> ( (nIdx=find(szRealOld, nIdx)) != npos )
        {
            replace(begin()+nIdx, begin()+nIdx+nOldLen, szRealNew);
            nReplaced++;
            nIdx += nNewLen;
        }
        <FONT color="#0f4b95">return</FONT> nReplaced;
    }
      <FONT color="#0f4b95">int</FONT> ReverseFind(CT ch) <FONT color="#0f4b95">const</FONT>
    {
        MYSIZE nIdx = find_last_of(ch);
        <FONT color="#0f4b95">return</FONT> static_cast<<FONT color="#0f4b95">int</FONT>>(nIdx == npos ? -<FONT color="#a52a00">1</FONT> : nIdx);
    }
      <FONT color="#008000">// ReverseFind overload that's not in CString but might be useful</FONT>
    <FONT color="#0f4b95">int</FONT> ReverseFind(PCMYSTR szFind, size_type pos=npos) <FONT color="#0f4b95">const</FONT>
    {
        MYSIZE nIdx = rfind(NULL == szFind ? MYTYPE() : szFind, pos);
        <FONT color="#0f4b95">return</FONT> static_cast<<FONT color="#0f4b95">int</FONT>>(nIdx == npos ? -<FONT color="#a52a00">1</FONT> : nIdx);
    }
      MYTYPE Right(<FONT color="#0f4b95">int</FONT> nCount) <FONT color="#0f4b95">const</FONT>
    {
        nCount = SSMIN(nCount, static_cast<<FONT color="#0f4b95">int</FONT>>(size()));
        <FONT color="#0f4b95">return</FONT> substr(size()-static_cast<MYSIZE>(nCount));
    }
      <FONT color="#0f4b95">void</FONT> SetAt(<FONT color="#0f4b95">int</FONT> nIndex, CT ch)
    {
        ASSERT(size() > static_cast<MYSIZE>(nIndex));
        at(static_cast<MYSIZE>(nIndex))     = ch;
    }
      <FONT color="#0f4b95">#ifndef</FONT> SS_ANSI
        BSTR SetSysString(BSTR* pbstr) <FONT color="#0f4b95">const</FONT>
        {
            ostring os;
            ssasn(os, *<FONT color="#0f4b95">this</FONT>);
            <FONT color="#0f4b95">if</FONT> ( !::SysReAllocStringLen(pbstr, os.c_str(), os.length()) )
                throw std::runtime_error(<FONT color="#a52a00">"out of memory"</FONT>);
              ASSERT(*pbstr != NULL);
            <FONT color="#0f4b95">return</FONT> *pbstr;
        }
    <FONT color="#0f4b95">#endif</FONT>
      MYTYPE SpanExcluding(PCMYSTR szCharSet) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> Left(find_first_of(szCharSet));
    }
      MYTYPE SpanIncluding(PCMYSTR szCharSet) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> Left(find_first_not_of(szCharSet));
    }
      <FONT color="#0f4b95">#if</FONT> !defined(UNICODE) && !defined(SS_ANSI)
          <FONT color="#008000">// CString's OemToAnsi and AnsiToOem functions are available only in</FONT>
        <FONT color="#008000">// Unicode builds.  However since we're a template we also need a</FONT>
        <FONT color="#008000">// runtime check of CT and a reinterpret_cast to account for the fact</FONT>
        <FONT color="#008000">// that CStdStringW gets instantiated even in non-Unicode builds.</FONT>
        <FONT color="#0f4b95">void</FONT> <FONT color="#0f4b95">AnsiToOem</FONT>()
        {
            <FONT color="#0f4b95">if</FONT> ( <FONT color="#0f4b95">sizeof</FONT>(CT) == <FONT color="#0f4b95">sizeof</FONT>(<FONT color="#0f4b95">char</FONT>) && !empty() )
            {
                ::CharToOem(reinterpret_cast<PCSTR>(c_str()),
                            reinterpret_cast<PSTR>(GetBuf()));
            }
            <FONT color="#0f4b95">else</FONT>
            {
                ASSERT(false);
            }
        }
          <FONT color="#0f4b95">void</FONT> <FONT color="#0f4b95">OemToAnsi</FONT>()
        {
            <FONT color="#0f4b95">if</FONT> ( <FONT color="#0f4b95">sizeof</FONT>(CT) == <FONT color="#0f4b95">sizeof</FONT>(<FONT color="#0f4b95">char</FONT>) && !empty() )
            {
                ::OemToChar(reinterpret_cast<PCSTR>(c_str()),
                            reinterpret_cast<PSTR>(GetBuf()));
            }
            <FONT color="#0f4b95">else</FONT>
            {
                ASSERT(false);
            }
        }
      <FONT color="#0f4b95">#endif</FONT>
    
      <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// Trim and its variants</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    MYTYPE& Trim()
    {
        <FONT color="#0f4b95">return</FONT> TrimLeft().TrimRight();
    }
      MYTYPE& TrimLeft()
    {
        erase(begin(), std::find_if(begin(),end(),NotSpace<CT>(std::locale())));
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE&  TrimLeft(CT tTrim)
    {
        erase(<FONT color="#a52a00">0</FONT>, find_first_not_of(tTrim));
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE&  TrimLeft(PCMYSTR szTrimChars)
    {
        erase(<FONT color="#a52a00">0</FONT>, find_first_not_of(szTrimChars));
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE& TrimRight()
    {
        std::locale loc;
        reverse_iterator it = std::find_if(rbegin(), rend(), NotSpace<CT>(loc));
        <FONT color="#0f4b95">if</FONT> ( rend() != it )
            erase(rend() - it);
          erase(it != rend() ? find_last_of(*it) + <FONT color="#a52a00">1</FONT> : <FONT color="#a52a00">0</FONT>);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE&  TrimRight(CT tTrim)
    {
        MYSIZE nIdx = find_last_not_of(tTrim);
        erase(npos == nIdx ? <FONT color="#a52a00">0</FONT> : ++nIdx);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      MYTYPE&  TrimRight(PCMYSTR szTrimChars)
    {
        MYSIZE nIdx = find_last_not_of(szTrimChars);
        erase(npos == nIdx ? <FONT color="#a52a00">0</FONT> : ++nIdx);
        <FONT color="#0f4b95">return</FONT> *<FONT color="#0f4b95">this</FONT>;
    }
      <FONT color="#0f4b95">void</FONT>            FreeExtra()
    {
        MYTYPE mt;
        swap(mt);
        <FONT color="#0f4b95">if</FONT> ( !mt.empty() )
            assign(mt.c_str(), mt.size());
    }
      <FONT color="#008000">// I have intentionally not implemented the following CString</FONT>
    <FONT color="#008000">// functions.   You cannot make them work without taking advantage</FONT>
    <FONT color="#008000">// of implementation specific behavior.  However if you absolutely</FONT>
    <FONT color="#008000">// MUST have them, uncomment out these lines for "sort-of-like"</FONT>
    <FONT color="#008000">// their behavior.  You're on your own.</FONT>
<FONT color="#008000">//  CT*             LockBuffer()    { return GetBuf(); }// won't really lock</FONT>
<FONT color="#008000">//  void            UnlockBuffer(); { } // why have UnlockBuffer w/o LockBuffer?</FONT>
    <FONT color="#008000">// Array-indexing operators.  Required because we defined an implicit cast</FONT>
    <FONT color="#008000">// to operator const CT* (Thanks to Julian Selman for pointing this out)</FONT>
    CT& <FONT color="#0f4b95">operator</FONT>[](<FONT color="#0f4b95">int</FONT> nIdx)
    {
        <FONT color="#0f4b95">return</FONT> MYBASE::<FONT color="#0f4b95">operator</FONT>[](static_cast<MYSIZE>(nIdx));
    }
      <FONT color="#0f4b95">const</FONT> CT& <FONT color="#0f4b95">operator</FONT>[](<FONT color="#0f4b95">int</FONT> nIdx) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> MYBASE::<FONT color="#0f4b95">operator</FONT>[](static_cast<MYSIZE>(nIdx));
    }
      CT& <FONT color="#0f4b95">operator</FONT>[](<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> nIdx)
    {
        <FONT color="#0f4b95">return</FONT> MYBASE::<FONT color="#0f4b95">operator</FONT>[](static_cast<MYSIZE>(nIdx));
    }
      <FONT color="#0f4b95">const</FONT> CT& <FONT color="#0f4b95">operator</FONT>[](<FONT color="#0f4b95">unsigned</FONT> <FONT color="#0f4b95">int</FONT> nIdx) <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> MYBASE::<FONT color="#0f4b95">operator</FONT>[](static_cast<MYSIZE>(nIdx));
    }
      <FONT color="#0f4b95">operator</FONT> <FONT color="#0f4b95">const</FONT> CT*() <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#0f4b95">return</FONT> c_str();
    }
      <FONT color="#008000">// IStream related functions.  Useful in IPersistStream implementations</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_INC_COMDEF
      <FONT color="#0f4b95">#define</FONT> SSSO_UNICODE    <FONT color="#a52a00">0x01</FONT>    <FONT color="#008000">// the string is a wide string</FONT>
    <FONT color="#0f4b95">#define</FONT> SSSO_COMPRESS   <FONT color="#a52a00">0x02</FONT>    <FONT color="#008000">// the string is compressed</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// FUNCTION: StreamSize</FONT>
    <FONT color="#008000">// REMARKS:</FONT>
    <FONT color="#008000">//      Returns how many bytes it will take to StreamSave() this CStdString</FONT>
    <FONT color="#008000">//      object to an IStream.</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    ULONG StreamSize() <FONT color="#0f4b95">const</FONT>
    {
        <FONT color="#008000">// Control header plus string</FONT>
        ASSERT(size()*<FONT color="#0f4b95">sizeof</FONT>(CT) < 0xffffffffUL - <FONT color="#0f4b95">sizeof</FONT>(SSSHDR));
        <FONT color="#0f4b95">return</FONT> (size() * <FONT color="#0f4b95">sizeof</FONT>(CT)) + <FONT color="#0f4b95">sizeof</FONT>(SSSHDR);
    }
      <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// FUNCTION: StreamSave</FONT>
    <FONT color="#008000">// REMARKS:</FONT>
    <FONT color="#008000">//      Saves this CStdString object to a COM IStream.</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    HRESULT StreamSave(IStream* pStream) <FONT color="#0f4b95">const</FONT>
    {
        ASSERT(size()*<FONT color="#0f4b95">sizeof</FONT>(CT) < 0xffffffffUL - <FONT color="#0f4b95">sizeof</FONT>(SSSHDR));
        HRESULT hr      = E_FAIL;
        ASSERT(pStream != NULL);
        SSSHDR hdr;
        hdr.byCtrl      = <FONT color="#0f4b95">sizeof</FONT>(CT) == <FONT color="#a52a00">2</FONT> ? SSSO_UNICODE : <FONT color="#a52a00">0</FONT>;
        hdr.nChars      = size();
  
        <FONT color="#0f4b95">if</FONT> ( FAILED(hr=pStream->Write(&hdr, <FONT color="#0f4b95">sizeof</FONT>(SSSHDR), NULL)) )
            TRACE(_T(<FONT color="#a52a00">"StreamSave: Cannot write control header, ERR=0x%X\n"</FONT>),hr);
        <FONT color="#0f4b95">else</FONT> <FONT color="#0f4b95">if</FONT> ( empty() )
            ;       <FONT color="#008000">// nothing to write</FONT>
        <FONT color="#0f4b95">else</FONT> <FONT color="#0f4b95">if</FONT> ( FAILED(hr=pStream->Write(c_str(), size()*<FONT color="#0f4b95">sizeof</FONT>(CT), NULL)) )
            TRACE(_T(<FONT color="#a52a00">"StreamSave: Cannot write string to stream 0x%X\n"</FONT>), hr);
          <FONT color="#0f4b95">return</FONT> hr;
    }
  
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// FUNCTION: StreamLoad</FONT>
    <FONT color="#008000">// REMARKS:</FONT>
    <FONT color="#008000">//      This method loads the object from an IStream.</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    HRESULT StreamLoad(IStream* pStream)
    {
        ASSERT(pStream != NULL);
        SSSHDR hdr;
        HRESULT hr          = E_FAIL;
          <FONT color="#0f4b95">if</FONT> ( FAILED(hr=pStream->Read(&hdr, <FONT color="#0f4b95">sizeof</FONT>(SSSHDR), NULL)) )
        {
            TRACE(_T(<FONT color="#a52a00">"StreamLoad: Cant read control header, ERR=0x%X\n"</FONT>), hr);
        }
        <FONT color="#0f4b95">else</FONT> <FONT color="#0f4b95">if</FONT> ( hdr.nChars > <FONT color="#a52a00">0</FONT> )
        {
            ULONG nRead     = <FONT color="#a52a00">0</FONT>;
            PMYSTR pMyBuf   = BufferSet(hdr.nChars);
              <FONT color="#008000">// If our character size matches the character size of the string</FONT>
            <FONT color="#008000">// we're trying to read, then we can read it directly into our</FONT>
            <FONT color="#008000">// buffer. Otherwise, we have to read into an intermediate buffer</FONT>
            <FONT color="#008000">// and convert.</FONT>
            
            <FONT color="#0f4b95">if</FONT> ( (hdr.byCtrl & SSSO_UNICODE) != <FONT color="#a52a00">0</FONT> )
            {
                ULONG nBytes    = hdr.nChars * <FONT color="#0f4b95">sizeof</FONT>(wchar_t);
                <FONT color="#0f4b95">if</FONT> ( <FONT color="#0f4b95">sizeof</FONT>(CT) == <FONT color="#0f4b95">sizeof</FONT>(wchar_t) )
                {
                    <FONT color="#0f4b95">if</FONT> ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) )
                        TRACE(_T(<FONT color="#a52a00">"StreamLoad: Cannot read string: 0x%X\n"</FONT>), hr);
                }
                <FONT color="#0f4b95">else</FONT>
                {   
                    PWSTR pBufW = reinterpret_cast<PWSTR>(_alloca((nBytes)+<FONT color="#a52a00">1</FONT>));
                    <FONT color="#0f4b95">if</FONT> ( FAILED(hr=pStream->Read(pBufW, nBytes, &nRead)) )
                        TRACE(_T(<FONT color="#a52a00">"StreamLoad: Cannot read string: 0x%X\n"</FONT>), hr);
                    <FONT color="#0f4b95">else</FONT>
                        sscpy(pMyBuf, pBufW, hdr.nChars*<FONT color="#0f4b95">sizeof</FONT>(wchar_t));
                }
            }
            <FONT color="#0f4b95">else</FONT>
            {
                ULONG nBytes    = hdr.nChars * <FONT color="#0f4b95">sizeof</FONT>(<FONT color="#0f4b95">char</FONT>);
                <FONT color="#0f4b95">if</FONT> ( <FONT color="#0f4b95">sizeof</FONT>(CT) == <FONT color="#0f4b95">sizeof</FONT>(<FONT color="#0f4b95">char</FONT>) )
                {
                    <FONT color="#0f4b95">if</FONT> ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) )
                        TRACE(_T(<FONT color="#a52a00">"StreamLoad: Cannot read string: 0x%X\n"</FONT>), hr);
                }
                <FONT color="#0f4b95">else</FONT>
                {
                    PSTR pBufA = reinterpret_cast<PSTR>(_alloca(nBytes));
                    <FONT color="#0f4b95">if</FONT> ( FAILED(hr=pStream->Read(pBufA, hdr.nChars, &nRead)) )
                        TRACE(_T(<FONT color="#a52a00">"StreamLoad: Cannot read string: 0x%X\n"</FONT>), hr);
                    <FONT color="#0f4b95">else</FONT>
                        sscpy(pMyBuf, pBufA, hdr.nChars);
                }
            }
        }
        <FONT color="#0f4b95">else</FONT>
        {
            <FONT color="#0f4b95">this</FONT>->erase();
        }
        <FONT color="#0f4b95">return</FONT> hr;
    }
<FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifdef SS_INC_COMDEF</FONT>
    <FONT color="#008000">// SetResourceHandle/GetResourceHandle.  In MFC builds, these map directly</FONT>
    <FONT color="#008000">// to AfxSetResourceHandle and AfxGetResourceHandle.  In non-MFC builds they</FONT>
    <FONT color="#008000">// point to a single static HINST so that those who call the member</FONT>
    <FONT color="#008000">// functions that take resource IDs can provide an alternate HINST of a DLL</FONT>
    <FONT color="#008000">// to search.  This is not exactly the list of HMODULES that MFC provides</FONT>
    <FONT color="#008000">// but it's better than nothing.</FONT>
    <FONT color="#0f4b95">#ifdef</FONT> _MFC_VER
        <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">void</FONT> SetResourceHandle(HMODULE hNew)
        {
            AfxSetResourceHandle(hNew);
        }
        <FONT color="#0f4b95">static</FONT> HMODULE GetResourceHandle()
        {
            <FONT color="#0f4b95">return</FONT> AfxGetResourceHandle();
        }
    <FONT color="#0f4b95">#else</FONT>
        <FONT color="#0f4b95">static</FONT> <FONT color="#0f4b95">void</FONT> SetResourceHandle(HMODULE hNew)
        {
            SSResourceHandle() = hNew;
        }
        <FONT color="#0f4b95">static</FONT> HMODULE GetResourceHandle()
        {
            <FONT color="#0f4b95">return</FONT> SSResourceHandle();
        }
    <FONT color="#0f4b95">#endif</FONT>
};
 
 
  <FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// CStdStr friend addition functions defined as inline</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">template</FONT><typename CT>
<FONT color="#0f4b95">inline</FONT>
CStdStr<CT> <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT>  CStdStr<CT>& str1, <FONT color="#0f4b95">const</FONT>  CStdStr<CT>& str2)
{
    CStdStr<CT> strRet(SSREF(str1));
    strRet.append(str2);
    <FONT color="#0f4b95">return</FONT> strRet;
}
  <FONT color="#0f4b95">template</FONT><typename CT>   
<FONT color="#0f4b95">inline</FONT>
CStdStr<CT> <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT>  CStdStr<CT>& str, CT t)
{
    <FONT color="#008000">// this particular overload is needed for disabling reference counting</FONT>
    <FONT color="#008000">// though it's only an issue from line 1 to line 2</FONT>
    CStdStr<CT> strRet(SSREF(str)); <FONT color="#008000">// 1</FONT>
    strRet.append(<FONT color="#a52a00">1</FONT>, t);                <FONT color="#008000">// 2</FONT>
    <FONT color="#0f4b95">return</FONT> strRet;
}
  <FONT color="#0f4b95">template</FONT><typename CT>
<FONT color="#0f4b95">inline</FONT>
CStdStr<CT> <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT>  CStdStr<CT>& str, PCSTR pA)
{
    <FONT color="#0f4b95">return</FONT> CStdStr<CT>(str) + CStdStr<CT>(pA);
}
  <FONT color="#0f4b95">template</FONT><typename CT>
<FONT color="#0f4b95">inline</FONT>
CStdStr<CT> <FONT color="#0f4b95">operator</FONT>+(PCSTR pA, <FONT color="#0f4b95">const</FONT>  CStdStr<CT>& str)
{
    CStdStr<CT> strRet(pA);
    strRet.append(str);
    <FONT color="#0f4b95">return</FONT> strRet;
}
  <FONT color="#0f4b95">template</FONT><typename CT>
<FONT color="#0f4b95">inline</FONT>
CStdStr<CT> <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT> CStdStr<CT>& str, PCWSTR pW)
{ 
    <FONT color="#0f4b95">return</FONT> CStdStr<CT>(SSREF(str)) + CStdStr<CT>(pW);
}
  <FONT color="#0f4b95">template</FONT><typename CT>
<FONT color="#0f4b95">inline</FONT>
CStdStr<CT> <FONT color="#0f4b95">operator</FONT>+(PCWSTR pW, <FONT color="#0f4b95">const</FONT> CStdStr<CT>& str)
{
    CStdStr<CT> strRet(pW);
    strRet.append(str);
    <FONT color="#0f4b95">return</FONT> strRet;
}
  <FONT color="#0f4b95">#ifdef</FONT> SS_INC_COMDEF
    <FONT color="#0f4b95">template</FONT><typename CT>
    <FONT color="#0f4b95">inline</FONT>
    CStdStr<CT> <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT> _bstr_t& bstr, <FONT color="#0f4b95">const</FONT> CStdStr<CT>& str)
    {
        <FONT color="#0f4b95">return</FONT> static_cast<<FONT color="#0f4b95">const</FONT> CT*>(bstr) + str;
    }
      <FONT color="#0f4b95">template</FONT><typename CT>
    <FONT color="#0f4b95">inline</FONT>
    CStdStr<CT> <FONT color="#0f4b95">operator</FONT>+(<FONT color="#0f4b95">const</FONT> CStdStr<CT>& str, <FONT color="#0f4b95">const</FONT> _bstr_t& bstr)
    {
        <FONT color="#0f4b95">return</FONT> str + static_cast<<FONT color="#0f4b95">const</FONT> CT*>(bstr);
    }
<FONT color="#0f4b95">#endif</FONT>
  
<FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">//                      END OF CStdStr INLINE FUNCTION DEFINITIONS</FONT>
<FONT color="#008000">// =============================================================================</FONT>
<FONT color="#008000">//  Now typedef our class names based upon this humongous template</FONT>
<FONT color="#0f4b95">typedef</FONT> CStdStr<<FONT color="#0f4b95">char</FONT>>       CStdStringA;    <FONT color="#008000">// a better std::string</FONT>
<FONT color="#0f4b95">typedef</FONT> CStdStr<wchar_t>    CStdStringW;    <FONT color="#008000">// a better std::wstring</FONT>
<FONT color="#0f4b95">typedef</FONT> CStdStr<OLECHAR>    CStdStringO;    <FONT color="#008000">// almost always CStdStringW</FONT>
<FONT color="#008000">// SSResourceHandle: our MFC-like resource handle</FONT>
<FONT color="#0f4b95">inline</FONT> HMODULE& SSResourceHandle()
{
    <FONT color="#0f4b95">static</FONT> HMODULE hModuleSS    = <FONT color="#0f4b95">GetModuleHandle</FONT>(NULL);
    <FONT color="#0f4b95">return</FONT> hModuleSS;
}
  
<FONT color="#008000">// In MFC builds, define some global serialization operators</FONT>
<FONT color="#008000">// Special operators that allow us to serialize CStdStrings to CArchives.</FONT>
<FONT color="#008000">// Note that we use an intermediate CString object in order to ensure that</FONT>
<FONT color="#008000">// we use the exact same format.</FONT>
<FONT color="#0f4b95">#ifdef</FONT> _MFC_VER
    <FONT color="#0f4b95">inline</FONT> CArchive& AFXAPI <FONT color="#0f4b95">operator</FONT><<(CArchive& ar, <FONT color="#0f4b95">const</FONT> CStdStringA& strA)
    {
        CString strTemp = strA;
        <FONT color="#0f4b95">return</FONT> ar << strTemp;
    }
    <FONT color="#0f4b95">inline</FONT> CArchive& AFXAPI <FONT color="#0f4b95">operator</FONT><<(CArchive& ar, <FONT color="#0f4b95">const</FONT> CStdStringW& strW)
    {
        CString strTemp = strW;
        <FONT color="#0f4b95">return</FONT> ar << strTemp;
    }
      <FONT color="#0f4b95">inline</FONT> CArchive& AFXAPI <FONT color="#0f4b95">operator</FONT>>>(CArchive& ar, CStdStringA& strA)
    {
        CString strTemp;
        ar >> strTemp;
        strA = strTemp;
        <FONT color="#0f4b95">return</FONT> ar;
    }
    <FONT color="#0f4b95">inline</FONT> CArchive& AFXAPI <FONT color="#0f4b95">operator</FONT>>>(CArchive& ar, CStdStringW& strW)
    {
        CString strTemp;
        ar >> strTemp;
        strW = strTemp;
        <FONT color="#0f4b95">return</FONT> ar;
    }
<FONT color="#0f4b95">#endif</FONT>  <FONT color="#008000">// #ifdef _MFC_VER -- (i.e. is this MFC?)</FONT>
<FONT color="#008000">// WUSysMessage -- return the system string corresponding to a system error or</FONT>
<FONT color="#008000">// HRESULT value.</FONT>
<FONT color="#0f4b95">#define</FONT> SS_DEFLANGID MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
  
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// HOW TO EXPORT CSTDSTRING FROM A DLL</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// If you want to export CStdStringA and CStdStringW from a DLL, then all you</FONT>
<FONT color="#008000">// need to</FONT>
<FONT color="#008000">//      1.  make sure that all components link to the same DLL version</FONT>
<FONT color="#008000">//          of the CRT (not the static one).</FONT>
<FONT color="#008000">//      2.  Uncomment the 3 lines of code below</FONT>
<FONT color="#008000">//      3.  #define 2 macros per the instructions in MS KnowledgeBase</FONT>
<FONT color="#008000">//          article Q168958.  The macros are:</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      MACRO       DEFINTION WHEN EXPORTING        DEFINITION WHEN IMPORTING</FONT>
<FONT color="#008000">//      -----       ------------------------        -------------------------</FONT>
<FONT color="#008000">//      SSDLLEXP    (nothing, just #define it)      extern</FONT>
<FONT color="#008000">//      SSDLLSPEC   __declspec(dllexport)           __declspec(dllimport)</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">//      Note that these macros must be available to ALL clients who want to </FONT>
<FONT color="#008000">//      link to the DLL and use the class.  If they </FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">//#pragma warning(disable:4231) // non-standard extension ("extern template")</FONT>
<FONT color="#008000">//  SSDLLEXP template class SSDLLSPEC CStdStr<char>;</FONT>
<FONT color="#008000">//  SSDLLEXP template class SSDLLSPEC CStdStr<wchar_t>;</FONT>
  <FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// GLOBAL FUNCTION:  WUFormat</FONT>
<FONT color="#008000">//      CStdStringA WUFormat(UINT nId, ...);</FONT>
<FONT color="#008000">//      CStdStringA WUFormat(PCSTR szFormat, ...);</FONT>
<FONT color="#008000">//</FONT>
<FONT color="#008000">// REMARKS:</FONT>
<FONT color="#008000">//      This function allows the caller for format and return a CStdStringA</FONT>
<FONT color="#008000">//      object with a single line of code.</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">inline</FONT> CStdStringA WUFormatA(UINT nId, ...)
    {
        va_list argList;
        va_start(argList, nId);
          CStdStringA strFmt;
        CStdStringA strOut;
        <FONT color="#0f4b95">if</FONT> ( strFmt.Load(nId) )
            strOut.FormatV(strFmt, argList);
          va_end(argList);
        <FONT color="#0f4b95">return</FONT> strOut;
    }
    <FONT color="#0f4b95">inline</FONT> CStdStringA WUFormatA(PCSTR szFormat, ...)
    {
        va_list argList;
        va_start(argList, szFormat);
        CStdStringA strOut;
        strOut.FormatV(szFormat, argList);
        va_end(argList);
        <FONT color="#0f4b95">return</FONT> strOut;
    }
      <FONT color="#0f4b95">inline</FONT> CStdStringW WUFormatW(UINT nId, ...)
    {
        va_list argList;
        va_start(argList, nId);
          CStdStringW strFmt;
        CStdStringW strOut;
        <FONT color="#0f4b95">if</FONT> ( strFmt.Load(nId) )
            strOut.FormatV(strFmt, argList);
          va_end(argList);
        <FONT color="#0f4b95">return</FONT> strOut;
    }
    <FONT color="#0f4b95">inline</FONT> CStdStringW WUFormatW(PCWSTR szwFormat, ...)
    {
        va_list argList;
        va_start(argList, szwFormat);
        CStdStringW strOut;
        strOut.FormatV(szwFormat, argList);
        va_end(argList);
        <FONT color="#0f4b95">return</FONT> strOut;
    }
<FONT color="#0f4b95">#endif</FONT> <FONT color="#008000">// #ifdef SS_ANSI</FONT>
<FONT color="#0f4b95">#ifdef</FONT> SS_ANSI
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#008000">// FUNCTION: WUSysMessage</FONT>
    <FONT color="#008000">//   CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID);</FONT>
    <FONT color="#008000">//   CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID);</FONT>
    <FONT color="#008000">//           </FONT>
    <FONT color="#008000">// DESCRIPTION:</FONT>
    <FONT color="#008000">//   This function simplifies the process of obtaining a string equivalent</FONT>
    <FONT color="#008000">//   of a system error code returned from GetLastError().  You simply</FONT>
    <FONT color="#008000">//   supply the value returned by GetLastError() to this function and the</FONT>
    <FONT color="#008000">//   corresponding system string is returned in the form of a CStdStringA.</FONT>
    <FONT color="#008000">//</FONT>
    <FONT color="#008000">// PARAMETERS: </FONT>
    <FONT color="#008000">//   dwError - a DWORD value representing the error code to be translated</FONT>
    <FONT color="#008000">//   dwLangId - the language id to use.  defaults to english.</FONT>
    <FONT color="#008000">//</FONT>
    <FONT color="#008000">// RETURN VALUE: </FONT>
    <FONT color="#008000">//   a CStdStringA equivalent of the error code.  Currently, this function</FONT>
    <FONT color="#008000">//   only returns either English of the system default language strings.  </FONT>
    <FONT color="#008000">// -------------------------------------------------------------------------</FONT>
    <FONT color="#0f4b95">#define</FONT> SS_DEFLANGID MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
    <FONT color="#0f4b95">inline</FONT> CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID)
    {
        CHAR szBuf[<FONT color="#a52a00">512</FONT>];
          <FONT color="#0f4b95">if</FONT> ( <FONT color="#a52a00">0</FONT> != ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
                                   dwLangId, szBuf, <FONT color="#a52a00">511</FONT>, NULL) )
            <FONT color="#0f4b95">return</FONT> WUFormatA(<FONT color="#a52a00">"%s (0x%X)"</FONT>, szBuf, dwError);
        <FONT color="#0f4b95">else</FONT>
            <FONT color="#0f4b95">return</FONT> WUFormatA(<FONT color="#a52a00">"Unknown error (0x%X)"</FONT>, dwError);
    }
    <FONT color="#0f4b95">inline</FONT> CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID)
    {
        WCHAR szBuf[<FONT color="#a52a00">512</FONT>];
          <FONT color="#0f4b95">if</FONT> ( <FONT color="#a52a00">0</FONT> != ::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
                                   dwLangId, szBuf, <FONT color="#a52a00">511</FONT>, NULL) )
            <FONT color="#0f4b95">return</FONT> WUFormatW(L<FONT color="#a52a00">"%s (0x%X)"</FONT>, szBuf, dwError);
        <FONT color="#0f4b95">else</FONT>
            <FONT color="#0f4b95">return</FONT> WUFormatW(L<FONT color="#a52a00">"Unknown error (0x%X)"</FONT>, dwError);
    }
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// Define TCHAR based friendly names for some of these functions</FONT>
<FONT color="#0f4b95">#ifdef</FONT> UNICODE
    <FONT color="#0f4b95">#define</FONT> CStdString              CStdStringW
    <FONT color="#0f4b95">#define</FONT> WUSysMessage            WUSysMessageW
    <FONT color="#0f4b95">#define</FONT> WUFormat                WUFormatW
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">#define</FONT> CStdString              CStdStringA
    <FONT color="#0f4b95">#define</FONT> WUSysMessage            WUSysMessageA
    <FONT color="#0f4b95">#define</FONT> WUFormat                WUFormatA
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#008000">// ...and some shorter names for the space-efficient</FONT>
<FONT color="#0f4b95">#define</FONT> WUSysMsg                    WUSysMessage
<FONT color="#0f4b95">#define</FONT> WUSysMsgA                   WUSysMessageA
<FONT color="#0f4b95">#define</FONT> WUSysMsgW                   WUSysMessageW
<FONT color="#0f4b95">#define</FONT> WUFmtA                      WUFormatA
<FONT color="#0f4b95">#define</FONT> WUFmtW                      WUFormatW
<FONT color="#0f4b95">#define</FONT> WUFmt                       WUFormat
<FONT color="#0f4b95">#define</FONT> WULastErrMsg()              WUSysMessage(::GetLastError())
<FONT color="#0f4b95">#define</FONT> WULastErrMsgA()             WUSysMessageA(::GetLastError())
<FONT color="#0f4b95">#define</FONT> WULastErrMsgW()             WUSysMessageW(::GetLastError())
  
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#008000">// FUNCTIONAL COMPARATORS:</FONT>
<FONT color="#008000">// REMARKS:</FONT>
<FONT color="#008000">//      These structs are derived from the std::binary_function template.  They</FONT>
<FONT color="#008000">//      give us functional classes (which may be used in Standard C++ Library</FONT>
<FONT color="#008000">//      collections and algorithms) that perform case-insensitive comparisons of</FONT>
<FONT color="#008000">//      CStdString objects.  This is useful for maps in which the key may be the</FONT>
<FONT color="#008000">//       proper string but in the wrong case.</FONT>
<FONT color="#008000">// -----------------------------------------------------------------------------</FONT>
<FONT color="#0f4b95">#define</FONT> StdStringLessNoCaseW        SSLNCW  <FONT color="#008000">// avoid VC compiler warning 4786</FONT>
<FONT color="#0f4b95">#define</FONT> StdStringEqualsNoCaseW      SSENCW      
<FONT color="#0f4b95">#define</FONT> StdStringLessNoCaseA        SSLNCA      
<FONT color="#0f4b95">#define</FONT> StdStringEqualsNoCaseA      SSENCA      
  <FONT color="#0f4b95">#ifdef</FONT> UNICODE
    <FONT color="#0f4b95">#define</FONT> StdStringLessNoCase     SSLNCW      
    <FONT color="#0f4b95">#define</FONT> StdStringEqualsNoCase   SSENCW      
<FONT color="#0f4b95">#else</FONT>
    <FONT color="#0f4b95">#define</FONT> StdStringLessNoCase     SSLNCA      
    <FONT color="#0f4b95">#define</FONT> StdStringEqualsNoCase   SSENCA      
<FONT color="#0f4b95">#endif</FONT>
  <FONT color="#0f4b95">struct</FONT> StdStringLessNoCaseW
    : std::binary_function<CStdStringW, CStdStringW, <FONT color="#0f4b95">bool</FONT>>
{
    <FONT color="#0f4b95">inline</FONT>
    <FONT color="#0f4b95">bool</FONT> <FONT color="#0f4b95">operator</FONT>()(<FONT color="#0f4b95">const</FONT> CStdStringW& sLeft, <FONT color="#0f4b95">const</FONT> CStdStringW& sRight) <FONT color="#0f4b95">const</FONT>
    { <FONT color="#0f4b95">return</FONT> ssicmp(sLeft.c_str(), sRight.c_str()) < <FONT color="#a52a00">0</FONT>; }
};
<FONT color="#0f4b95">struct</FONT> StdStringEqualsNoCaseW
    : std::binary_function<CStdStringW, CStdStringW, <FONT color="#0f4b95">bool</FONT>>
{
    <FONT color="#0f4b95">inline</FONT>
    <FONT color="#0f4b95">bool</FONT> <FONT color="#0f4b95">operator</FONT>()(<FONT color="#0f4b95">const</FONT> CStdStringW& sLeft, <FONT color="#0f4b95">const</FONT> CStdStringW& sRight) <FONT color="#0f4b95">const</FONT>
    { <FONT color="#0f4b95">return</FONT> ssicmp(sLeft.c_str(), sRight.c_str()) == <FONT color="#a52a00">0</FONT>; }
};
<FONT color="#0f4b95">struct</FONT> StdStringLessNoCaseA
    : std::binary_function<CStdStringA, CStdStringA, <FONT color="#0f4b95">bool</FONT>>
{
    <FONT color="#0f4b95">inline</FONT>
    <FONT color="#0f4b95">bool</FONT> <FONT color="#0f4b95">operator</FONT>()(<FONT color="#0f4b95">const</FONT> CStdStringA& sLeft, <FONT color="#0f4b95">const</FONT> CStdStringA& sRight) <FONT color="#0f4b95">const</FONT>
    { <FONT color="#0f4b95">return</FONT> ssicmp(sLeft.c_str(), sRight.c_str()) < <FONT color="#a52a00">0</FONT>; }
};
<FONT color="#0f4b95">struct</FONT> StdStringEqualsNoCaseA
    : std::binary_function<CStdStringA, CStdStringA, <FONT color="#0f4b95">bool</FONT>>
{
    <FONT color="#0f4b95">inline</FONT>
    <FONT color="#0f4b95">bool</FONT> <FONT color="#0f4b95">operator</FONT>()(<FONT color="#0f4b95">const</FONT> CStdStringA& sLeft, <FONT color="#0f4b95">const</FONT> CStdStringA& sRight) <FONT color="#0f4b95">const</FONT>
    { <FONT color="#0f4b95">return</FONT> ssicmp(sLeft.c_str(), sRight.c_str()) == <FONT color="#a52a00">0</FONT>; }
};
  <FONT color="#008000">// If we had to define our own version of TRACE above, get rid of it now</FONT>
<FONT color="#0f4b95">#ifdef</FONT> TRACE_DEFINED_HERE
    <FONT color="#0f4b95">#undef</FONT> TRACE
    <FONT color="#0f4b95">#undef</FONT> TRACE_DEFINED_HERE
<FONT color="#0f4b95">#endif</FONT>
  
<FONT color="#0f4b95">#endif</FONT>  <FONT color="#008000">// #ifndef STDSTRING_H</FONT>
</PRE><P><HR></P>  |  
  
 | 
 
 
 
The zip file viewer built into the Developer Toolbox made use
of the zlib library, as well as the zlibdll source additions.
 
 
 |