+++ /dev/null
-// =============================================================================\r
-// FILE: StdString.h\r
-// AUTHOR: Joe O'Leary (with outside help noted in comments)\r
-// REMARKS:\r
-// This header file declares the CStdStr template. This template derives\r
-// the Standard C++ Library basic_string<> template and add to it the\r
-// the following conveniences:\r
-// - The full MFC CString set of functions (including implicit cast)\r
-// - writing to/reading from COM IStream interfaces\r
-// - Functional objects for use in STL algorithms\r
-//\r
-// From this template, we intstantiate two classes: CStdStringA and\r
-// CStdStringW. The name "CStdString" is just a #define of one of these,\r
-// based upone the _UNICODE macro setting\r
-//\r
-// This header also declares our own version of the MFC/ATL UNICODE-MBCS\r
-// conversion macros. Our version looks exactly like the Microsoft's to\r
-// facilitate portability.\r
-//\r
-// NOTE:\r
-// If you you use this in an MFC or ATL build, you should include either\r
-// afx.h or atlbase.h first, as appropriate.\r
-//\r
-// PEOPLE WHO HAVE CONTRIBUTED TO THIS CLASS:\r
-//\r
-// Several people have helped me iron out problems and othewise improve\r
-// this class. OK, this is a long list but in my own defense, this code\r
-// has undergone two major rewrites. Many of the improvements became\r
-// necessary after I rewrote the code as a template. Others helped me\r
-// improve the CString facade.\r
-//\r
-// Anyway, these people are (in chronological order):\r
-//\r
-// - Pete the Plumber (???)\r
-// - Julian Selman\r
-// - Chris (of Melbsys)\r
-// - Dave Plummer\r
-// - John C Sipos\r
-// - Chris Sells\r
-// - Nigel Nunn\r
-// - Fan Xia\r
-// - Matthew Williams\r
-// - Carl Engman\r
-// - Mark Zeren\r
-// - Craig Watson\r
-// - Rich Zuris\r
-// - Karim Ratib\r
-// - Chris Conti\r
-// - Baptiste Lepilleur\r
-// - Greg Pickles\r
-// - Jim Cline\r
-// - Jeff Kohn\r
-// - Todd Heckel\r
-// - Ullrich Pollähne\r
-// - Joe Vitaterna\r
-// - Joe Woodbury\r
-// - Aaron (no last name)\r
-// - Joldakowski (???)\r
-// - Scott Hathaway\r
-// - Eric Nitzche\r
-// - Pablo Presedo\r
-// - Farrokh Nejadlotfi\r
-// - Jason Mills\r
-// - Igor Kholodov\r
-// - Mike Crusader\r
-// - John James\r
-// - Wang Haifeng\r
-// - Tim Dowty\r
-// - Arnt Witteveen\r
-// - Glen Maynard\r
-// - Paul DeMarco\r
-// - Bagira (full name?)\r
-// - Ronny Schulz\r
-// - Jakko Van Hunen\r
-// - Charles G\r
-//\r
-// REVISION HISTORY\r
-// 2003-JUL-10 - Thanks to Charles G for making me realize my 'FmtArg' fixes\r
-// had inadvertently broken the DLL-export code (which is\r
-// normally commented out. I had to move it up higher. Also\r
-// this helped me catch a bug in ssicoll that would prevent\r
-// compilation, otherwise.\r
-//\r
-// 2003-MAR-14 - Thanks to Jakko Van Hunen for pointing out a copy-and-paste\r
-// bug in one of the overloads of FmtArg.\r
-//\r
-// 2003-MAR-10 - Thanks to Ronny Schulz for (twice!) sending me some changes\r
-// to help CStdString build on SGI and for pointing out an\r
-// error in placement of my preprocessor macros for ssfmtmsg.\r
-//\r
-// 2002-NOV-26 - Thanks to Bagira for pointing out that my implementation of\r
-// SpanExcluding was not properly handling the case in which\r
-// the string did NOT contain any of the given characters\r
-//\r
-// 2002-OCT-21 - Many thanks to Paul DeMarco who was invaluable in helping me\r
-// get this code working with Borland's free compiler as well\r
-// as the Dev-C++ compiler (available free at SourceForge).\r
-//\r
-// 2002-SEP-13 - Thanks to Glen Maynard who helped me get rid of some loud\r
-// but harmless warnings that were showing up on g++. Glen\r
-// also pointed out that some pre-declarations of FmtArg<>\r
-// specializations were unnecessary (and no good on G++)\r
-//\r
-// 2002-JUN-26 - Thanks to Arnt Witteveen for pointing out that I was using\r
-// static_cast<> in a place in which I should have been using\r
-// reinterpret_cast<> (the ctor for unsigned char strings).\r
-// That's what happens when I don't unit-test properly!\r
-// Arnt also noticed that CString was silently correcting the\r
-// 'nCount' argument to Left() and Right() where CStdString was\r
-// not (and crashing if it was bad). That is also now fixed!\r
-//\r
-// 2002-FEB-25 - Thanks to Tim Dowty for pointing out (and giving me the fix\r
-// for) a conversion problem with non-ASCII MBCS characters.\r
-// CStdString is now used in my favorite commercial MP3 player!\r
-//\r
-// 2001-DEC-06 - Thanks to Wang Haifeng for spotting a problem in one of the\r
-// assignment operators (for _bstr_t) that would cause compiler\r
-// errors when refcounting protection was turned off.\r
-//\r
-// 2001-NOV-27 - Remove calls to operator!= which involve reverse_iterators\r
-// due to a conflict with the rel_ops operator!=. Thanks to\r
-// John James for pointing this out.\r
-//\r
-// 2001-OCT-29 - Added a minor range checking fix for the Mid function to\r
-// make it as forgiving as CString's version is. Thanks to\r
-// Igor Kholodov for noticing this. \r
-// - Added a specialization of std::swap for CStdString. Thanks\r
-// to Mike Crusader for suggesting this! It's commented out\r
-// because you're not supposed to inject your own code into the\r
-// 'std' namespace. But if you don't care about that, it's\r
-// there if you want it\r
-// - Thanks to Jason Mills for catching a case where CString was\r
-// more forgiving in the Delete() function than I was.\r
-//\r
-// 2001-JUN-06 - I was violating the Standard name lookup rules stated\r
-// in [14.6.2(3)]. None of the compilers I've tried so\r
-// far apparently caught this but HP-UX aCC 3.30 did. The\r
-// fix was to add 'this->' prefixes in many places.\r
-// Thanks to Farrokh Nejadlotfi for this!\r
-//\r
-// 2001-APR-27 - StreamLoad was calculating the number of BYTES in one\r
-// case, not characters. Thanks to Pablo Presedo for this.\r
-//\r
-// 2001-FEB-23 - Replace() had a bug which caused infinite loops if the\r
-// source string was empty. Fixed thanks to Eric Nitzsche.\r
-//\r
-// 2001-FEB-23 - Scott Hathaway was a huge help in providing me with the\r
-// ability to build CStdString on Sun Unix systems. He\r
-// sent me detailed build reports about what works and what\r
-// does not. If CStdString compiles on your Unix box, you\r
-// can thank Scott for it.\r
-//\r
-// 2000-DEC-29 - Joldakowski noticed one overload of Insert failed to do a\r
-// range check as CString's does. Now fixed -- thanks!\r
-//\r
-// 2000-NOV-07 - Aaron pointed out that I was calling static member\r
-// functions of char_traits via a temporary. This was not\r
-// technically wrong, but it was unnecessary and caused\r
-// problems for poor old buggy VC5. Thanks Aaron!\r
-//\r
-// 2000-JUL-11 - Joe Woodbury noted that the CString::Find docs don't match\r
-// what the CString::Find code really ends up doing. I was\r
-// trying to match the docs. Now I match the CString code\r
-// - Joe also caught me truncating strings for GetBuffer() calls\r
-// when the supplied length was less than the current length.\r
-//\r
-// 2000-MAY-25 - Better support for STLPORT's Standard library distribution\r
-// - Got rid of the NSP macro - it interfered with Koenig lookup\r
-// - Thanks to Joe Woodbury for catching a TrimLeft() bug that\r
-// I introduced in January. Empty strings were not getting\r
-// trimmed\r
-//\r
-// 2000-APR-17 - Thanks to Joe Vitaterna for pointing out that ReverseFind\r
-// is supposed to be a const function.\r
-//\r
-// 2000-MAR-07 - Thanks to Ullrich Pollähne for catching a range bug in one\r
-// of the overloads of assign.\r
-//\r
-// 2000-FEB-01 - You can now use CStdString on the Mac with CodeWarrior!\r
-// Thanks to Todd Heckel for helping out with this.\r
-//\r
-// 2000-JAN-23 - Thanks to Jim Cline for pointing out how I could make the\r
-// Trim() function more efficient.\r
-// - Thanks to Jeff Kohn for prompting me to find and fix a typo\r
-// in one of the addition operators that takes _bstr_t.\r
-// - Got rid of the .CPP file - you only need StdString.h now!\r
-//\r
-// 1999-DEC-22 - Thanks to Greg Pickles for helping me identify a problem\r
-// with my implementation of CStdString::FormatV in which\r
-// resulting string might not be properly NULL terminated.\r
-//\r
-// 1999-DEC-06 - Chris Conti pointed yet another basic_string<> assignment\r
-// bug that MS has not fixed. CStdString did nothing to fix\r
-// it either but it does now! The bug was: create a string\r
-// longer than 31 characters, get a pointer to it (via c_str())\r
-// and then assign that pointer to the original string object.\r
-// The resulting string would be empty. Not with CStdString!\r
-//\r
-// 1999-OCT-06 - BufferSet was erasing the string even when it was merely\r
-// supposed to shrink it. Fixed. Thanks to Chris Conti.\r
-// - Some of the Q172398 fixes were not checking for assignment-\r
-// to-self. Fixed. Thanks to Baptiste Lepilleur.\r
-//\r
-// 1999-AUG-20 - Improved Load() function to be more efficient by using \r
-// SizeOfResource(). Thanks to Rich Zuris for this.\r
-// - Corrected resource ID constructor, again thanks to Rich.\r
-// - Fixed a bug that occurred with UNICODE characters above\r
-// the first 255 ANSI ones. Thanks to Craig Watson. \r
-// - Added missing overloads of TrimLeft() and TrimRight().\r
-// Thanks to Karim Ratib for pointing them out\r
-//\r
-// 1999-JUL-21 - Made all calls to GetBuf() with no args check length first.\r
-//\r
-// 1999-JUL-10 - Improved MFC/ATL independence of conversion macros\r
-// - Added SS_NO_REFCOUNT macro to allow you to disable any\r
-// reference-counting your basic_string<> impl. may do.\r
-// - Improved ReleaseBuffer() to be as forgiving as CString.\r
-// Thanks for Fan Xia for helping me find this and to\r
-// Matthew Williams for pointing it out directly.\r
-//\r
-// 1999-JUL-06 - Thanks to Nigel Nunn for catching a very sneaky bug in\r
-// ToLower/ToUpper. They should call GetBuf() instead of\r
-// data() in order to ensure the changed string buffer is not\r
-// reference-counted (in those implementations that refcount).\r
-//\r
-// 1999-JUL-01 - Added a true CString facade. Now you can use CStdString as\r
-// a drop-in replacement for CString. If you find this useful,\r
-// you can thank Chris Sells for finally convincing me to give\r
-// in and implement it.\r
-// - Changed operators << and >> (for MFC CArchive) to serialize\r
-// EXACTLY as CString's do. So now you can send a CString out\r
-// to a CArchive and later read it in as a CStdString. I have\r
-// no idea why you would want to do this but you can. \r
-//\r
-// 1999-JUN-21 - Changed the CStdString class into the CStdStr template.\r
-// - Fixed FormatV() to correctly decrement the loop counter.\r
-// This was harmless bug but a bug nevertheless. Thanks to\r
-// Chris (of Melbsys) for pointing it out\r
-// - Changed Format() to try a normal stack-based array before\r
-// using to _alloca().\r
-// - Updated the text conversion macros to properly use code\r
-// pages and to fit in better in MFC/ATL builds. In other\r
-// words, I copied Microsoft's conversion stuff again. \r
-// - Added equivalents of CString::GetBuffer, GetBufferSetLength\r
-// - new sscpy() replacement of CStdString::CopyString()\r
-// - a Trim() function that combines TrimRight() and TrimLeft().\r
-//\r
-// 1999-MAR-13 - Corrected the "NotSpace" functional object to use _istpace()\r
-// instead of _isspace() Thanks to Dave Plummer for this.\r
-//\r
-// 1999-FEB-26 - Removed errant line (left over from testing) that #defined\r
-// _MFC_VER. Thanks to John C Sipos for noticing this.\r
-//\r
-// 1999-FEB-03 - Fixed a bug in a rarely-used overload of operator+() that\r
-// caused infinite recursion and stack overflow\r
-// - Added member functions to simplify the process of\r
-// persisting CStdStrings to/from DCOM IStream interfaces \r
-// - Added functional objects (e.g. StdStringLessNoCase) that\r
-// allow CStdStrings to be used as keys STL map objects with\r
-// case-insensitive comparison \r
-// - Added array indexing operators (i.e. operator[]). I\r
-// originally assumed that these were unnecessary and would be\r
-// inherited from basic_string. However, without them, Visual\r
-// C++ complains about ambiguous overloads when you try to use\r
-// them. Thanks to Julian Selman to pointing this out. \r
-//\r
-// 1998-FEB-?? - Added overloads of assign() function to completely account\r
-// for Q172398 bug. Thanks to "Pete the Plumber" for this\r
-//\r
-// 1998-FEB-?? - Initial submission\r
-//\r
-// COPYRIGHT:\r
-// 2002 Joseph M. O'Leary. This code is 100% free. Use it anywhere you\r
-// want. Rewrite it, restructure it, whatever. If you can write software\r
-// that makes money off of it, good for you. I kinda like capitalism. \r
-// Please don't blame me if it causes your $30 billion dollar satellite\r
-// explode in orbit. If you redistribute it in any form, I'd appreciate it\r
-// if you would leave this notice here.\r
-//\r
-// If you find any bugs, please let me know:\r
-//\r
-// jmoleary@earthlink.net\r
-// http://www.joeo.net\r
-//\r
-// The latest version of this code should always be available at the\r
-// following link:\r
-//\r
-// http://www.joeo.net/code/StdString.zip\r
-// =============================================================================\r
-\r
-// Avoid multiple inclusion the VC++ way,\r
-// Turn off browser references\r
-// Turn off unavoidable compiler warnings\r
-\r
-#if defined(_MSC_VER) && (_MSC_VER > 1100)\r
- #pragma once\r
- #pragma component(browser, off, references, "CStdString")\r
- #pragma warning (disable : 4290) // C++ Exception Specification ignored\r
- #pragma warning (disable : 4127) // Conditional expression is constant\r
- #pragma warning (disable : 4097) // typedef name used as synonym for class name\r
-#endif\r
-\r
-// Borland warnings to turn off\r
-#ifdef __BORLANDC__\r
- #pragma option push -w-inl\r
-// #pragma warn -inl // Turn off inline function warnings\r
-#endif\r
-\r
-#ifndef STDSTRING_H\r
-#define STDSTRING_H\r
-\r
-// MACRO: SS_UNSIGNED\r
-// ------------------\r
-// This macro causes the addition of a constructor and assignment operator\r
-// which take unsigned characters. CString has such functions and in order\r
-// to provide maximum CString-compatability, this code needs them as well.\r
-// In practice you will likely never need these functions...\r
-\r
-//#define SS_UNSIGNED\r
-\r
-#ifdef SS_ALLOW_UNSIGNED_CHARS\r
- #define SS_UNSIGNED\r
-#endif\r
-\r
-// MACRO: SS_SAFE_FORMAT\r
-// ---------------------\r
-// This macro provides limited compatability with a questionable CString\r
-// "feature". You can define it in order to avoid a common problem that\r
-// people encounter when switching from CString to CStdString.\r
-//\r
-// To illustrate the problem -- With CString, you can do this:\r
-//\r
-// CString sName("Joe");\r
-// CString sTmp;\r
-// sTmp.Format("My name is %s", sName); // WORKS!\r
-//\r
-// However if you were to try this with CStdString, your program would\r
-// crash.\r
-//\r
-// CStdString sName("Joe");\r
-// CStdString sTmp;\r
-// sTmp.Format("My name is %s", sName); // CRASHES!\r
-//\r
-// You must explicitly call c_str() or cast the object to the proper type\r
-//\r
-// sTmp.Format("My name is %s", sName.c_str()); // WORKS!\r
-// sTmp.Format("My name is %s", static_cast<PCSTR>(sName));// WORKS!\r
-// sTmp.Format("My name is %s", (PCSTR)sName);// WORKS!\r
-//\r
-// This is because it is illegal to pass anything but a POD type as a\r
-// variadic argument to a variadic function (i.e. as one of the "..."\r
-// arguments). The type const char* is a POD type. The type CStdString\r
-// is not. Of course, neither is the type CString, but CString lets you do\r
-// it anyway due to the way they laid out the class in binary. I have no\r
-// control over this in CStdString since I derive from whatever\r
-// implementation of basic_string is available.\r
-//\r
-// However if you have legacy code (which does this) that you want to take\r
-// out of the MFC world and you don't want to rewrite all your calls to\r
-// Format(), then you can define this flag and it will no longer crash.\r
-//\r
-// Note however that this ONLY works for Format(), not sprintf, fprintf, \r
-// etc. If you pass a CStdString object to one of those functions, your\r
-// program will crash. Not much I can do to get around this, short of\r
-// writing substitutes for those functions as well.\r
-\r
-#define SS_SAFE_FORMAT // use new template style Format() function\r
-\r
-\r
-// MACRO: SS_NO_IMPLICIT_CAST\r
-// --------------------------\r
-// Some people don't like the implicit cast to const char* (or rather to\r
-// const CT*) that CStdString (and MFC's CString) provide. That was the\r
-// whole reason I created this class in the first place, but hey, whatever\r
-// bakes your cake. Just #define this macro to get rid of the the implicit\r
-// cast.\r
-\r
-//#define SS_NO_IMPLICIT_CAST // gets rid of operator const CT*()\r
-\r
-\r
-// MACRO: SS_NO_REFCOUNT\r
-// ---------------------\r
-// turns off reference counting at the assignment level. Only needed\r
-// for the version of basic_string<> that comes with Visual C++ versions\r
-// 6.0 or earlier, and only then in some heavily multithreaded scenarios.\r
-// Uncomment it if you feel you need it.\r
-\r
-//#define SS_NO_REFCOUNT\r
-\r
-// MACRO: SS_WIN32\r
-// ---------------\r
-// When this flag is set, we are building code for the Win32 platform and\r
-// may use Win32 specific functions (such as LoadString). This gives us\r
-// a couple of nice extras for the code.\r
-//\r
-// Obviously, Microsoft's is not the only compiler available for Win32 out\r
-// there. So I can't just check to see if _MSC_VER is defined to detect\r
-// if I'm building on Win32. So for now, if you use MS Visual C++ or\r
-// Borland's compiler, I turn this on. Otherwise you may turn it on\r
-// yourself, if you prefer\r
-#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WIN32)\r
- #define SS_WIN32\r
-#endif\r
-\r
-// MACRO: SS_ANSI\r
-// --------------\r
-// When this macro is defined, the code attempts only to use ANSI/ISO\r
-// standard library functions to do it's work. It will NOT attempt to use\r
-// any Win32 of Visual C++ specific functions -- even if they are\r
-// available. You may define this flag yourself to prevent any Win32\r
-// of VC++ specific functions from being called.\r
-\r
-// If we're not on Win32, we MUST use an ANSI build\r
-#ifndef SS_WIN32\r
- #if !defined(SS_NO_ANSI)\r
- #define SS_ANSI\r
- #endif\r
-#endif\r
-\r
-// MACRO: SS_ALLOCA\r
-// ----------------\r
-// Some implementations of the Standard C Library have a non-standard\r
-// function known as alloca(). This functions allows one to allocate a\r
-// variable amount of memory on the stack. It comes in very useful for\r
-// the ASCII/MBCS conversion macros.\r
-//\r
-// Here we attempt to determine automatically if alloca() is available on\r
-// this platform. If so we define SS_ALLOCA to be the name of the alloca\r
-// function. If SS_ALLOCA is undefined later on, then the conversion\r
-// macros will not be compiled.\r
-//\r
-// You may prevent SS_ALLOCA\r
-\r
-\r
-\r
-// Avoid legacy code screw up: if _UNICODE is defined, UNICODE must be as well\r
-\r
-#if defined (_UNICODE) && !defined (UNICODE)\r
- #define UNICODE\r
-#endif\r
-#if defined (UNICODE) && !defined (_UNICODE)\r
- #define _UNICODE\r
-#endif\r
-\r
-// -----------------------------------------------------------------------------\r
-// MIN and MAX. The Standard C++ template versions go by so many names (at\r
-// at least in the MS implementation) that you never know what's available\r
-// -----------------------------------------------------------------------------\r
-template<class Type>\r
-inline const Type& SSMIN(const Type& arg1, const Type& arg2)\r
-{\r
- return arg2 < arg1 ? arg2 : arg1;\r
-}\r
-template<class Type>\r
-inline const Type& SSMAX(const Type& arg1, const Type& arg2)\r
-{\r
- return arg2 > arg1 ? arg2 : arg1;\r
-}\r
-\r
-// If they have not #included W32Base.h (part of my W32 utility library) then\r
-// we need to define some stuff. Otherwise, this is all defined there.\r
-\r
-#if !defined(W32BASE_H)\r
-\r
- // If they want us to use only standard C++ stuff (no Win32 stuff)\r
-\r
- #ifdef SS_ANSI\r
-\r
- // On Win32 we have TCHAR.H so just include it. This is NOT violating\r
- // the spirit of SS_ANSI as we are not calling any Win32 functions here.\r
- \r
- #ifdef SS_WIN32\r
-\r
- #include <TCHAR.H>\r
- #include <WTYPES.H>\r
- #ifndef STRICT\r
- #define STRICT\r
- #endif\r
-\r
- // ... but on non-Win32 platforms, we must #define the types we need.\r
-\r
- #else\r
-\r
- typedef const char* PCSTR;\r
- typedef char* PSTR;\r
- typedef const wchar_t* PCWSTR;\r
- typedef wchar_t* PWSTR;\r
- #ifdef UNICODE\r
- typedef wchar_t TCHAR;\r
- #else\r
- typedef char TCHAR;\r
- #endif\r
- typedef wchar_t OLECHAR;\r
-\r
- #endif // #ifndef _WIN32\r
-\r
-\r
- // Make sure ASSERT and verify are defined using only ANSI stuff\r
-\r
- #ifndef ASSERT\r
- #include <assert.h>\r
- #define ASSERT(f) assert((f))\r
- #endif\r
- #ifndef VERIFY\r
- #ifdef _DEBUG\r
- #define VERIFY(x) ASSERT((x))\r
- #else\r
- #define VERIFY(x) x\r
- #endif\r
- #endif\r
-\r
- #else // ...else SS_ANSI is NOT defined\r
-\r
- #include <TCHAR.H>\r
- #include <WTYPES.H>\r
- #ifndef STRICT\r
- #define STRICT\r
- #endif\r
-\r
- // Make sure ASSERT and verify are defined\r
-\r
- #ifndef ASSERT\r
- #include <crtdbg.h>\r
- #define ASSERT(f) _ASSERTE((f))\r
- #endif\r
- #ifndef VERIFY\r
- #ifdef _DEBUG\r
- #define VERIFY(x) ASSERT((x))\r
- #else\r
- #define VERIFY(x) x\r
- #endif\r
- #endif\r
-\r
- #endif // #ifdef SS_ANSI\r
-\r
- #ifndef UNUSED\r
- #define UNUSED(x) x\r
- #endif\r
-\r
-#endif // #ifndef W32BASE_H\r
-\r
-// Standard headers needed\r
-\r
-#include <string> // basic_string\r
-#include <algorithm> // for_each, etc.\r
-#include <functional> // for StdStringLessNoCase, et al\r
-#include <locale> // for various facets\r
-\r
-// If this is a recent enough version of VC include comdef.h, so we can write\r
-// member functions to deal with COM types & compiler support classes e.g. _bstr_t\r
-\r
-#if defined (_MSC_VER) && (_MSC_VER >= 1100)\r
- #include <comdef.h>\r
- #define SS_INC_COMDEF // signal that we #included MS comdef.h file\r
- #define STDSTRING_INC_COMDEF\r
- #define SS_NOTHROW __declspec(nothrow)\r
-#else\r
- #define SS_NOTHROW\r
-#endif\r
-\r
-#ifndef TRACE\r
- #define TRACE_DEFINED_HERE\r
- #define TRACE\r
-#endif\r
-\r
-// Microsoft defines PCSTR, PCWSTR, etc, but no PCTSTR. I hate to use the\r
-// versions with the "L" in front of them because that's a leftover from Win 16\r
-// days, even though it evaluates to the same thing. Therefore, Define a PCSTR\r
-// as an LPCTSTR.\r
-\r
-#if !defined(PCTSTR) && !defined(PCTSTR_DEFINED)\r
- typedef const TCHAR* PCTSTR;\r
- #define PCTSTR_DEFINED\r
-#endif\r
-\r
-#if !defined(PCOLESTR) && !defined(PCOLESTR_DEFINED)\r
- typedef const OLECHAR* PCOLESTR;\r
- #define PCOLESTR_DEFINED\r
-#endif\r
-\r
-#if !defined(POLESTR) && !defined(POLESTR_DEFINED)\r
- typedef OLECHAR* POLESTR;\r
- #define POLESTR_DEFINED\r
-#endif\r
-\r
-#if !defined(PCUSTR) && !defined(PCUSTR_DEFINED)\r
- typedef const unsigned char* PCUSTR;\r
- typedef unsigned char* PUSTR;\r
- #define PCUSTR_DEFINED\r
-#endif\r
-\r
-\r
-// SGI compiler 7.3 doesnt know these types - oh and btw, remember to use\r
-// -LANG:std in the CXX Flags\r
-#if defined(__sgi)\r
- typedef unsigned long DWORD;\r
- typedef void * LPCVOID;\r
-#endif\r
-\r
-\r
-// SS_USE_FACET macro and why we need it:\r
-//\r
-// Since I'm a good little Standard C++ programmer, I use locales. Thus, I\r
-// need to make use of the use_facet<> template function here. Unfortunately,\r
-// this need is complicated by the fact the MS' implementation of the Standard\r
-// C++ Library has a non-standard version of use_facet that takes more\r
-// arguments than the standard dictates. Since I'm trying to write CStdString\r
-// to work with any version of the Standard library, this presents a problem.\r
-//\r
-// The upshot of this is that I can't do 'use_facet' directly. The MS' docs\r
-// tell me that I have to use a macro, _USE() instead. Since _USE obviously\r
-// won't be available in other implementations, this means that I have to write\r
-// my OWN macro -- SS_USE_FACET -- that evaluates either to _USE or to the\r
-// standard, use_facet.\r
-//\r
-// If you are having trouble with the SS_USE_FACET macro, in your implementation\r
-// of the Standard C++ Library, you can define your own version of SS_USE_FACET.\r
-#ifndef schMSG\r
- #define schSTR(x) #x\r
- #define schSTR2(x) schSTR(x)\r
- #define schMSG(desc) message(__FILE__ "(" schSTR2(__LINE__) "):" #desc)\r
-#endif\r
-\r
-#ifndef SS_USE_FACET\r
- // STLPort #defines a macro (__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) for\r
- // all MSVC builds, erroneously in my opinion. It causes problems for\r
- // my SS_ANSI builds. In my code, I always comment out that line. You'll\r
- // find it in \stlport\config\stl_msvc.h\r
- #if defined(__SGI_STL_PORT) && (__SGI_STL_PORT >= 0x400 )\r
- #if defined(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) && defined(_MSC_VER)\r
- #ifdef SS_ANSI\r
- #pragma schMSG(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS defined!!)\r
- #endif\r
- #endif\r
- #define SS_USE_FACET(loc, fac) std::use_facet<fac >(loc)\r
- #elif defined(_MSC_VER )\r
- #define SS_USE_FACET(loc, fac) std::_USE(loc, fac)\r
-\r
- // ...and\r
- #elif defined(_RWSTD_NO_TEMPLATE_ON_RETURN_TYPE)\r
- #define SS_USE_FACET(loc, fac) std::use_facet(loc, (fac*)0)\r
- #else\r
- #define SS_USE_FACET(loc, fac) std::use_facet<fac >(loc)\r
- #endif\r
-#endif\r
-\r
-// =============================================================================\r
-// UNICODE/MBCS conversion macros. Made to work just like the MFC/ATL ones.\r
-// =============================================================================\r
-\r
-#include <wchar.h> // Added to Std Library with Amendment #1.\r
-\r
-// First define the conversion helper functions. We define these regardless of\r
-// any preprocessor macro settings since their names won't collide. \r
-\r
-// Not sure if we need all these headers. I believe ANSI says we do.\r
-\r
-#include <stdio.h>\r
-#include <stdarg.h>\r
-#include <wctype.h>\r
-#include <ctype.h>\r
-#include <stdlib.h>\r
-#ifndef va_start\r
- #include <varargs.h>\r
-#endif\r
-\r
-// StdCodeCvt - made to look like Win32 functions WideCharToMultiByte\r
-// and MultiByteToWideChar but uses locales in SS_ANSI\r
-// builds\r
-//typedef int mbstate_t;\r
-#if defined (SS_ANSI) || !defined (SS_WIN32)\r
-\r
- typedef std::codecvt<wchar_t, char, std::mbstate_t> SSCodeCvt;\r
-\r
-\r
- inline PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, int nChars,\r
- const std::locale& loc=std::locale())\r
- {\r
- ASSERT(0 != pA);\r
- ASSERT(0 != pW);\r
- pW[0] = '\0';\r
- PCSTR pBadA = 0;\r
- PWSTR pBadW = 0;\r
- SSCodeCvt::result res = SSCodeCvt::ok;\r
- const SSCodeCvt& conv = SS_USE_FACET(loc, SSCodeCvt);\r
- SSCodeCvt::state_type st= { 0 };\r
- res = conv.in(st,\r
- pA, pA + nChars, pBadA,\r
- pW, pW + nChars, pBadW);\r
- ASSERT(SSCodeCvt::ok == res);\r
- return pW;\r
- }\r
- inline PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, int nChars,\r
- const std::locale& loc=std::locale())\r
- {\r
- return StdCodeCvt(pW, (PCSTR)pA, nChars, loc);\r
- }\r
-\r
- inline PSTR StdCodeCvt(PSTR pA, PCWSTR pW, int nChars,\r
- const std::locale& loc=std::locale())\r
- {\r
- ASSERT(0 != pA);\r
- ASSERT(0 != pW);\r
- pA[0] = '\0';\r
- PSTR pBadA = 0;\r
- PCWSTR pBadW = 0;\r
- SSCodeCvt::result res = SSCodeCvt::ok;\r
- const SSCodeCvt& conv = SS_USE_FACET(loc, SSCodeCvt);\r
- SSCodeCvt::state_type st= { 0 };\r
- res = conv.out(st,\r
- pW, pW + nChars, pBadW,\r
- pA, pA + nChars, pBadA);\r
- ASSERT(SSCodeCvt::ok == res);\r
- return pA;\r
- }\r
- inline PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, int nChars,\r
- const std::locale& loc=std::locale())\r
- {\r
- return (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, loc);\r
- }\r
-\r
-#else // ...or are we doing things assuming win32 and Visual C++?\r
-\r
- #include <malloc.h> // needed for _alloca\r
-\r
- inline PWSTR StdCodeCvt(PWSTR pW, PCSTR pA, int nChars, UINT acp=CP_ACP)\r
- {\r
- ASSERT(0 != pA);\r
- ASSERT(0 != pW);\r
- pW[0] = '\0';\r
- MultiByteToWideChar(acp, 0, pA, -1, pW, nChars);\r
- return pW;\r
- }\r
- inline PWSTR StdCodeCvt(PWSTR pW, PCUSTR pA, int nChars, UINT acp=CP_ACP)\r
- {\r
- return StdCodeCvt(pW, (PCSTR)pA, nChars, acp);\r
- }\r
-\r
- inline PSTR StdCodeCvt(PSTR pA, PCWSTR pW, int nChars, UINT acp=CP_ACP)\r
- {\r
- ASSERT(0 != pA);\r
- ASSERT(0 != pW);\r
- pA[0] = '\0';\r
- WideCharToMultiByte(acp, 0, pW, -1, pA, nChars, 0, 0);\r
- return pA;\r
- }\r
- inline PUSTR StdCodeCvt(PUSTR pA, PCWSTR pW, int nChars, UINT acp=CP_ACP)\r
- {\r
- return (PUSTR)StdCodeCvt((PSTR)pA, pW, nChars, acp);\r
- }\r
-\r
-#endif\r
-// Unicode/MBCS conversion macros are only available on implementations of\r
-// the "C" library that have the non-standard _alloca function. As far as I\r
-// know that's only Microsoft's though I've hear that the function exits\r
-// elsewhere. \r
- \r
-#if defined(SS_ALLOCA) && !defined SS_NO_CONVERSION\r
-\r
- #include <malloc.h> // needed for _alloca\r
-\r
-\r
- // Define our conversion macros to look exactly like Microsoft's to\r
- // facilitate using this stuff both with and without MFC/ATL\r
-\r
- #ifdef _CONVERSION_USES_THREAD_LOCALE\r
- #ifndef _DEBUG\r
- #define SSCVT int _cvt; _cvt; UINT _acp=GetACP(); \\r
- _acp; PCWSTR _pw; _pw; PCSTR _pa; _pa\r
- #else\r
- #define SSCVT int _cvt = 0; _cvt; UINT _acp=GetACP();\\r
- _acp; PCWSTR _pw=0; _pw; PCSTR _pa=0; _pa\r
- #endif\r
- #else\r
- #ifndef _DEBUG\r
- #define SSCVT int _cvt; _cvt; UINT _acp=CP_ACP; _acp;\\r
- PCWSTR _pw; _pw; PCSTR _pa; _pa\r
- #else\r
- #define SSCVT int _cvt = 0; _cvt; UINT _acp=CP_ACP; \\r
- _acp; PCWSTR _pw=0; _pw; PCSTR _pa=0; _pa\r
- #endif\r
- #endif\r
-\r
- #ifdef _CONVERSION_USES_THREAD_LOCALE\r
- #define SSA2W(pa) (\\r
- ((_pa = pa) == 0) ? 0 : (\\r
- _cvt = (sslen(_pa)+1),\\r
- StdCodeCvt((PWSTR) _alloca(_cvt*2), _pa, _cvt, _acp)))\r
- #define SSW2A(pw) (\\r
- ((_pw = pw) == 0) ? 0 : (\\r
- _cvt = (sslen(_pw)+1)*2,\\r
- StdW2AHelper((LPSTR) _alloca(_cvt), _pw, _cvt, _acp)))\r
- #else\r
- #define SSA2W(pa) (\\r
- ((_pa = pa) == 0) ? 0 : (\\r
- _cvt = (sslen(_pa)+1),\\r
- StdCodeCvt((PWSTR) _alloca(_cvt*2), _pa, _cvt)))\r
- #define SSW2A(pw) (\\r
- ((_pw = pw) == 0) ? 0 : (\\r
- _cvt = (sslen(_pw)+1)*2,\\r
- StdCodeCvt((LPSTR) _alloca(_cvt), _pw, _cvt)))\r
- #endif\r
-\r
- #define SSA2CW(pa) ((PCWSTR)SSA2W((pa)))\r
- #define SSW2CA(pw) ((PCSTR)SSW2A((pw)))\r
-\r
- #ifdef UNICODE\r
- #define SST2A SSW2A\r
- #define SSA2T SSA2W\r
- #define SST2CA SSW2CA\r
- #define SSA2CT SSA2CW\r
- inline PWSTR SST2W(PTSTR p) { return p; }\r
- inline PTSTR SSW2T(PWSTR p) { return p; }\r
- inline PCWSTR SST2CW(PCTSTR p) { return p; }\r
- inline PCTSTR SSW2CT(PCWSTR p) { return p; }\r
- #else\r
- #define SST2W SSA2W\r
- #define SSW2T SSW2A\r
- #define SST2CW SSA2CW\r
- #define SSW2CT SSW2CA\r
- inline PSTR SST2A(PTSTR p) { return p; }\r
- inline PTSTR SSA2T(PSTR p) { return p; }\r
- inline PCSTR SST2CA(PCTSTR p) { return p; }\r
- inline PCTSTR SSA2CT(PCSTR p) { return p; }\r
- #endif // #ifdef UNICODE\r
-\r
- #if defined(UNICODE)\r
- // in these cases the default (TCHAR) is the same as OLECHAR\r
- inline PCOLESTR SST2COLE(PCTSTR p) { return p; }\r
- inline PCTSTR SSOLE2CT(PCOLESTR p) { return p; }\r
- inline POLESTR SST2OLE(PTSTR p) { return p; }\r
- inline PTSTR SSOLE2T(POLESTR p) { return p; }\r
- #elif defined(OLE2ANSI)\r
- // in these cases the default (TCHAR) is the same as OLECHAR\r
- inline PCOLESTR SST2COLE(PCTSTR p) { return p; }\r
- inline PCTSTR SSOLE2CT(PCOLESTR p) { return p; }\r
- inline POLESTR SST2OLE(PTSTR p) { return p; }\r
- inline PTSTR SSOLE2T(POLESTR p) { return p; }\r
- #else\r
- //CharNextW doesn't work on Win95 so we use this\r
- #define SST2COLE(pa) SSA2CW((pa))\r
- #define SST2OLE(pa) SSA2W((pa))\r
- #define SSOLE2CT(po) SSW2CA((po))\r
- #define SSOLE2T(po) SSW2A((po))\r
- #endif\r
-\r
- #ifdef OLE2ANSI\r
- #define SSW2OLE SSW2A\r
- #define SSOLE2W SSA2W\r
- #define SSW2COLE SSW2CA\r
- #define SSOLE2CW SSA2CW\r
- inline POLESTR SSA2OLE(PSTR p) { return p; }\r
- inline PSTR SSOLE2A(POLESTR p) { return p; }\r
- inline PCOLESTR SSA2COLE(PCSTR p) { return p; }\r
- inline PCSTR SSOLE2CA(PCOLESTR p){ return p; }\r
- #else\r
- #define SSA2OLE SSA2W\r
- #define SSOLE2A SSW2A\r
- #define SSA2COLE SSA2CW\r
- #define SSOLE2CA SSW2CA\r
- inline POLESTR SSW2OLE(PWSTR p) { return p; }\r
- inline PWSTR SSOLE2W(POLESTR p) { return p; }\r
- inline PCOLESTR SSW2COLE(PCWSTR p) { return p; }\r
- inline PCWSTR SSOLE2CW(PCOLESTR p){ return p; }\r
- #endif\r
-\r
- // Above we've defined macros that look like MS' but all have\r
- // an 'SS' prefix. Now we need the real macros. We'll either\r
- // get them from the macros above or from MFC/ATL. \r
-\r
- #if defined (USES_CONVERSION)\r
-\r
- #define _NO_STDCONVERSION // just to be consistent\r
-\r
- #else\r
-\r
- #ifdef _MFC_VER\r
-\r
- #include <afxconv.h>\r
- #define _NO_STDCONVERSION // just to be consistent\r
-\r
- #else\r
-\r
- #define USES_CONVERSION SSCVT\r
- #define A2CW SSA2CW\r
- #define W2CA SSW2CA\r
- #define T2A SST2A\r
- #define A2T SSA2T\r
- #define T2W SST2W\r
- #define W2T SSW2T\r
- #define T2CA SST2CA\r
- #define A2CT SSA2CT\r
- #define T2CW SST2CW\r
- #define W2CT SSW2CT\r
- #define ocslen sslen\r
- #define ocscpy sscpy\r
- #define T2COLE SST2COLE\r
- #define OLE2CT SSOLE2CT\r
- #define T2OLE SST2COLE\r
- #define OLE2T SSOLE2CT\r
- #define A2OLE SSA2OLE\r
- #define OLE2A SSOLE2A\r
- #define W2OLE SSW2OLE\r
- #define OLE2W SSOLE2W\r
- #define A2COLE SSA2COLE\r
- #define OLE2CA SSOLE2CA\r
- #define W2COLE SSW2COLE\r
- #define OLE2CW SSOLE2CW\r
- \r
- #endif // #ifdef _MFC_VER\r
- #endif // #ifndef USES_CONVERSION\r
-#endif // #ifndef SS_NO_CONVERSION\r
-\r
-// Define ostring - generic name for std::basic_string<OLECHAR>\r
-\r
-#if !defined(ostring) && !defined(OSTRING_DEFINED)\r
- typedef std::basic_string<OLECHAR> ostring;\r
- #define OSTRING_DEFINED\r
-#endif\r
-\r
-// StdCodeCvt when there's no conversion to be done\r
-inline PSTR StdCodeCvt(PSTR pDst, PCSTR pSrc, int nChars)\r
-{\r
- if ( nChars > 0 )\r
- {\r
- pDst[0] = '\0';\r
- std::basic_string<char>::traits_type::copy(pDst, pSrc, nChars);\r
-// std::char_traits<char>::copy(pDst, pSrc, nChars);\r
- if ( nChars > 0 )\r
- pDst[nChars] = '\0';\r
- }\r
-\r
- return pDst;\r
-}\r
-inline PSTR StdCodeCvt(PSTR pDst, PCUSTR pSrc, int nChars)\r
-{\r
- return StdCodeCvt(pDst, (PCSTR)pSrc, nChars);\r
-}\r
-inline PUSTR StdCodeCvt(PUSTR pDst, PCSTR pSrc, int nChars)\r
-{\r
- return (PUSTR)StdCodeCvt((PSTR)pDst, pSrc, nChars);\r
-}\r
-\r
-inline PWSTR StdCodeCvt(PWSTR pDst, PCWSTR pSrc, int nChars)\r
-{\r
- if ( nChars > 0 )\r
- {\r
- pDst[0] = '\0';\r
- std::basic_string<wchar_t>::traits_type::copy(pDst, pSrc, nChars);\r
-// std::char_traits<wchar_t>::copy(pDst, pSrc, nChars);\r
- if ( nChars > 0 )\r
- pDst[nChars] = '\0';\r
- }\r
-\r
- return pDst;\r
-}\r
-\r
-\r
-// Define tstring -- generic name for std::basic_string<TCHAR>\r
-\r
-#if !defined(tstring) && !defined(TSTRING_DEFINED)\r
- typedef std::basic_string<TCHAR> tstring;\r
- #define TSTRING_DEFINED\r
-#endif\r
-\r
-// a very shorthand way of applying the fix for KB problem Q172398\r
-// (basic_string assignment bug)\r
-\r
-#if defined ( _MSC_VER ) && ( _MSC_VER < 1200 )\r
- #define Q172398(x) (x).erase()\r
-#else\r
- #define Q172398(x)\r
-#endif\r
-\r
-// =============================================================================\r
-// INLINE FUNCTIONS ON WHICH CSTDSTRING RELIES\r
-//\r
-// Usually for generic text mapping, we rely on preprocessor macro definitions\r
-// to map to string functions. However the CStdStr<> template cannot use\r
-// macro-based generic text mappings because its character types do not get\r
-// resolved until template processing which comes AFTER macro processing. In\r
-// other words, UNICODE is of little help to us in the CStdStr template\r
-//\r
-// Therefore, to keep the CStdStr declaration simple, we have these inline\r
-// functions. The template calls them often. Since they are inline (and NOT\r
-// exported when this is built as a DLL), they will probably be resolved away\r
-// to nothing. \r
-//\r
-// Without these functions, the CStdStr<> template would probably have to broken\r
-// out into two, almost identical classes. Either that or it would be a huge,\r
-// convoluted mess, with tons of "if" statements all over the place checking the\r
-// size of template parameter CT.\r
-// \r
-// In several cases, you will see two versions of each function. One version is\r
-// the more portable, standard way of doing things, while the other is the\r
-// non-standard, but often significantly faster Visual C++ way.\r
-// =============================================================================\r
-\r
-// If they defined SS_NO_REFCOUNT, then we must convert all assignments\r
-\r
-#ifdef SS_NO_REFCOUNT\r
- #define SSREF(x) (x).c_str()\r
-#else\r
- #define SSREF(x) (x)\r
-#endif\r
-\r
-// -----------------------------------------------------------------------------\r
-// sslen: strlen/wcslen wrappers\r
-// -----------------------------------------------------------------------------\r
-template<typename CT> inline int sslen(const CT* pT)\r
-{\r
- return 0 == pT ? 0 : std::basic_string<CT>::traits_type::length(pT);\r
-// return 0 == pT ? 0 : std::char_traits<CT>::length(pT);\r
-}\r
-inline SS_NOTHROW int sslen(const std::string& s)\r
-{\r
- return s.length();\r
-}\r
-inline SS_NOTHROW int sslen(const std::wstring& s)\r
-{\r
- return s.length();\r
-}\r
-\r
-// -----------------------------------------------------------------------------\r
-// sstolower/sstoupper -- convert characters to upper/lower case\r
-// -----------------------------------------------------------------------------\r
-template<typename CT>\r
-inline CT sstolower(const CT& t, const std::locale& loc = std::locale())\r
-{\r
- return std::tolower<CT>(t, loc);\r
-}\r
-template<typename CT>\r
-inline CT sstoupper(const CT& t, const std::locale& loc = std::locale())\r
-{\r
- return std::toupper<CT>(t, loc);\r
-}\r
-\r
-// -----------------------------------------------------------------------------\r
-// ssasn: assignment functions -- assign "sSrc" to "sDst"\r
-// -----------------------------------------------------------------------------\r
-typedef std::string::size_type SS_SIZETYPE; // just for shorthand, really\r
-typedef std::string::pointer SS_PTRTYPE; \r
-typedef std::wstring::size_type SW_SIZETYPE;\r
-typedef std::wstring::pointer SW_PTRTYPE; \r
-\r
-inline void ssasn(std::string& sDst, const std::string& sSrc)\r
-{\r
- if ( sDst.c_str() != sSrc.c_str() )\r
- {\r
- sDst.erase();\r
- sDst.assign(SSREF(sSrc));\r
- }\r
-}\r
-inline void ssasn(std::string& sDst, PCSTR pA)\r
-{\r
- // Watch out for NULLs, as always.\r
-\r
- if ( 0 == pA )\r
- {\r
- sDst.erase();\r
- }\r
-\r
- // If pA actually points to part of sDst, we must NOT erase(), but\r
- // rather take a substring\r
-\r
- else if ( pA >= sDst.c_str() && pA <= sDst.c_str() + sDst.size() )\r
- {\r
- sDst =sDst.substr(static_cast<SS_SIZETYPE>(pA-sDst.c_str()));\r
- }\r
-\r
- // Otherwise (most cases) apply the assignment bug fix, if applicable\r
- // and do the assignment\r
-\r
- else\r
- {\r
- Q172398(sDst);\r
- sDst.assign(pA);\r
- }\r
-}\r
-inline void ssasn(std::string& sDst, const std::wstring& sSrc)\r
-{\r
- int nLen = sSrc.size();\r
- sDst.resize(nLen * sizeof(wchar_t) + 1);\r
- StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()), sSrc.c_str(), nLen);\r
- sDst.resize(nLen);\r
- //sDst.resize(sslen(sDst.c_str()));\r
-}\r
-inline void ssasn(std::string& sDst, PCWSTR pW)\r
-{\r
- int nLen = sslen(pW);\r
- sDst.resize(nLen * sizeof(wchar_t) + 1);\r
- StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()), pW, nLen);\r
- sDst.resize(nLen);\r
- //sDst.resize(sslen(sDst.c_str()));\r
-}\r
-inline void ssasn(std::string& sDst, const int nNull)\r
-{\r
- UNUSED(nNull);\r
- ASSERT(nNull==0);\r
- sDst.assign("");\r
-} \r
-inline void ssasn(std::wstring& sDst, const std::wstring& sSrc)\r
-{\r
- if ( sDst.c_str() != sSrc.c_str() )\r
- {\r
- sDst.erase();\r
- sDst.assign(SSREF(sSrc));\r
- }\r
-}\r
-inline void ssasn(std::wstring& sDst, PCWSTR pW)\r
-{\r
- // Watch out for NULLs, as always.\r
-\r
- if ( 0 == pW )\r
- {\r
- sDst.erase();\r
- }\r
-\r
- // If pW actually points to part of sDst, we must NOT erase(), but\r
- // rather take a substring\r
-\r
- else if ( pW >= sDst.c_str() && pW <= sDst.c_str() + sDst.size() )\r
- {\r
- sDst = sDst.substr(static_cast<SW_SIZETYPE>(pW-sDst.c_str()));\r
- }\r
-\r
- // Otherwise (most cases) apply the assignment bug fix, if applicable\r
- // and do the assignment\r
-\r
- else\r
- {\r
- Q172398(sDst);\r
- sDst.assign(pW);\r
- }\r
-}\r
-#undef StrSizeType\r
-inline void ssasn(std::wstring& sDst, const std::string& sSrc)\r
-{\r
- int nLen = sSrc.size();\r
- sDst.resize(nLen+1);\r
- StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()), sSrc.c_str(), nLen+1);\r
- sDst.resize(sslen(sDst.c_str()));\r
-}\r
-inline void ssasn(std::wstring& sDst, PCSTR pA)\r
-{\r
- int nLen = sslen(pA);\r
- sDst.resize(nLen+1);\r
- StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()), pA, nLen+1);\r
- sDst.resize(sslen(sDst.c_str()));\r
-}\r
-inline void ssasn(std::wstring& sDst, const int nNull)\r
-{\r
- UNUSED(nNull);\r
- ASSERT(nNull==0);\r
- sDst.assign(L"");\r
-}\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// ssadd: string object concatenation -- add second argument to first\r
-// -----------------------------------------------------------------------------\r
-inline void ssadd(std::string& sDst, const std::wstring& sSrc)\r
-{\r
- int nSrcLen = sSrc.size();\r
- int nDstLen = sDst.size();\r
- int nEndLen = nSrcLen + nDstLen;\r
- sDst.resize(nEndLen + 1);\r
- StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()+nDstLen), sSrc.c_str(), nSrcLen);\r
- sDst.resize(nEndLen);\r
-}\r
-inline void ssadd(std::string& sDst, const std::string& sSrc)\r
-{\r
- if ( &sDst == &sSrc )\r
- sDst.reserve(2*sDst.size());\r
-\r
- sDst.append(sSrc.c_str());\r
-}\r
-inline void ssadd(std::string& sDst, PCWSTR pW)\r
-{\r
- int nSrcLen = sslen(pW);\r
- int nDstLen = sDst.size();\r
- int nEndLen = nSrcLen + nDstLen;\r
- sDst.resize(nEndLen + 1);\r
- StdCodeCvt(const_cast<SS_PTRTYPE>(sDst.data()+nDstLen), pW, nSrcLen+1);\r
- sDst.resize(nEndLen);\r
-}\r
-inline void ssadd(std::string& sDst, PCSTR pA)\r
-{\r
- if ( pA )\r
- {\r
- // If the string being added is our internal string or a part of our\r
- // internal string, then we must NOT do any reallocation without\r
- // first copying that string to another object (since we're using a\r
- // direct pointer)\r
-\r
- if ( pA >= sDst.c_str() && pA <= sDst.c_str()+sDst.length())\r
- {\r
- if ( sDst.capacity() <= sDst.size()+sslen(pA) )\r
- sDst.append(std::string(pA));\r
- else\r
- sDst.append(pA);\r
- }\r
- else\r
- {\r
- sDst.append(pA); \r
- }\r
- }\r
-}\r
-inline void ssadd(std::wstring& sDst, const std::wstring& sSrc)\r
-{\r
- if ( &sDst == &sSrc )\r
- sDst.reserve(2*sDst.size());\r
-\r
- sDst.append(sSrc.c_str());\r
-}\r
-inline void ssadd(std::wstring& sDst, const std::string& sSrc)\r
-{\r
- int nSrcLen = sSrc.size();\r
- int nDstLen = sDst.size();\r
- int nEndLen = nSrcLen + nDstLen;\r
- sDst.resize(nEndLen+1);\r
- StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()+nDstLen), sSrc.c_str(), nSrcLen+1);\r
- sDst.resize(nEndLen);\r
-}\r
-inline void ssadd(std::wstring& sDst, PCSTR pA)\r
-{\r
- int nSrcLen = sslen(pA);\r
- int nDstLen = sDst.size();\r
- int nEndLen = nSrcLen + nDstLen;\r
- sDst.resize(nEndLen + 1);\r
- StdCodeCvt(const_cast<SW_PTRTYPE>(sDst.data()+nDstLen), pA, nSrcLen+1);\r
- sDst.resize(nEndLen);\r
-}\r
-inline void ssadd(std::wstring& sDst, PCWSTR pW)\r
-{\r
- if ( pW )\r
- {\r
- // If the string being added is our internal string or a part of our\r
- // internal string, then we must NOT do any reallocation without\r
- // first copying that string to another object (since we're using a\r
- // direct pointer)\r
-\r
- if ( pW >= sDst.c_str() && pW <= sDst.c_str()+sDst.length())\r
- {\r
- if ( sDst.capacity() <= sDst.size()+sslen(pW) )\r
- sDst.append(std::wstring(pW));\r
- else\r
- sDst.append(pW);\r
- }\r
- else\r
- {\r
- sDst.append(pW);\r
- }\r
- }\r
-}\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// ssicmp: comparison (case insensitive )\r
-// -----------------------------------------------------------------------------\r
-template<typename CT>\r
-inline int ssicmp(const CT* pA1, const CT* pA2)\r
-{\r
- std::locale loc;\r
- const std::ctype<CT>& ct = SS_USE_FACET(loc, std::ctype<CT>);\r
- CT f;\r
- CT l;\r
-\r
- do \r
- {\r
- f = ct.tolower(*(pA1++));\r
- l = ct.tolower(*(pA2++));\r
- } while ( (f) && (f == l) );\r
-\r
- return (int)(f - l);\r
-}\r
-\r
-// -----------------------------------------------------------------------------\r
-// ssupr/sslwr: Uppercase/Lowercase conversion functions\r
-// -----------------------------------------------------------------------------\r
-\r
-template<typename CT>\r
-inline void sslwr(CT* pT, size_t nLen)\r
-{\r
- SS_USE_FACET(std::locale(), std::ctype<CT>).tolower(pT, pT+nLen);\r
-}\r
-template<typename CT>\r
-inline void ssupr(CT* pT, size_t nLen)\r
-{\r
- SS_USE_FACET(std::locale(), std::ctype<CT>).toupper(pT, pT+nLen);\r
-}\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// vsprintf/vswprintf or _vsnprintf/_vsnwprintf equivalents. In standard\r
-// builds we can't use _vsnprintf/_vsnwsprintf because they're MS extensions.\r
-// -----------------------------------------------------------------------------\r
-#if defined(SS_ANSI) || !defined(_MSC_VER)\r
-\r
- // Borland's headers put some ANSI "C" functions in the 'std' namespace.\r
- // Promote them to the global namespace so we can use them here.\r
-\r
- #if defined(__BORLANDC__)\r
- using std::vsprintf;\r
- using std::vswprintf;\r
- #endif\r
- inline int ssvsprintf(PSTR pA, size_t /*nCount*/, PCSTR pFmtA, va_list vl)\r
- {\r
- return vsprintf(pA, pFmtA, vl);\r
- }\r
- inline int ssvsprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl)\r
- {\r
- // JMO: Some distributions of the "C" have a version of vswprintf that\r
- // takes 3 arguments (e.g. Microsoft, Borland, GNU). Others have a \r
- // version which takes 4 arguments (an extra "count" argument in the\r
- // second position. The best stab I can take at this so far is that if\r
- // you are NOT running with MS, Borland, or GNU, then I'll assume you\r
- // have the version that takes 4 arguments.\r
- //\r
- // I'm sure that these checks don't catch every platform correctly so if\r
- // you get compiler errors on one of the lines immediately below, it's\r
- // probably because your implemntation takes a different number of\r
- // arguments. You can comment out the offending line (and use the\r
- // alternate version) or you can figure out what compiler flag to check\r
- // and add that preprocessor check in. Regardless, if you get an error\r
- // on these lines, I'd sure like to hear from you about it.\r
- //\r
- // Thanks to Ronny Schulz for the SGI-specific checks here.\r
-\r
-// #if !defined(__MWERKS__) && !defined(__SUNPRO_CC_COMPAT) && !defined(__SUNPRO_CC)\r
- #if !defined(_MSC_VER) \\r
- && !defined (__BORLANDC__) \\r
- && !defined(__GNUC__) \\r
- && !defined(__sgi)\r
-\r
- return vswprintf(pW, nCount, pFmtW, vl);\r
-\r
- // suddenly with the current SGI 7.3 compiler there is no such function as\r
- // vswprintf and the substitute needs explicit casts to compile\r
-\r
- #elif defined(__sgi)\r
-\r
- nCount;\r
- return vsprintf( (char *)pW, (char *)pFmtW, vl);\r
-\r
- #else\r
-\r
- nCount;\r
- return vswprintf(pW, pFmtW, vl);\r
-\r
- #endif\r
-\r
- }\r
-#else\r
- inline int ssnprintf(PSTR pA, size_t nCount, PCSTR pFmtA, va_list vl)\r
- {\r
- return _vsnprintf(pA, nCount, pFmtA, vl);\r
- }\r
- inline int ssnprintf(PWSTR pW, size_t nCount, PCWSTR pFmtW, va_list vl)\r
- {\r
- return _vsnwprintf(pW, nCount, pFmtW, vl);\r
- }\r
-#endif\r
-\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// ssload: Type safe, overloaded ::LoadString wrappers\r
-// There is no equivalent of these in non-Win32-specific builds. However, I'm\r
-// thinking that with the message facet, there might eventually be one\r
-// -----------------------------------------------------------------------------\r
-#if defined (SS_WIN32) && !defined(SS_ANSI)\r
- inline int ssload(HMODULE hInst, UINT uId, PSTR pBuf, int nMax)\r
- {\r
- return ::LoadStringA(hInst, uId, pBuf, nMax);\r
- }\r
- inline int ssload(HMODULE hInst, UINT uId, PWSTR pBuf, int nMax)\r
- {\r
- return ::LoadStringW(hInst, uId, pBuf, nMax);\r
- }\r
-#endif\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// sscoll/ssicoll: Collation wrappers\r
-// Note -- with MSVC I have reversed the arguments order here because the\r
-// functions appear to return the opposite of what they should\r
-// -----------------------------------------------------------------------------\r
-template <typename CT>\r
-inline int sscoll(const CT* sz1, int nLen1, const CT* sz2, int nLen2)\r
-{\r
- const std::collate<CT>& coll =\r
- SS_USE_FACET(std::locale(), std::collate<CT>);\r
-\r
- return coll.compare(sz2, sz2+nLen2, sz1, sz1+nLen1);\r
-}\r
-template <typename CT>\r
-inline int ssicoll(const CT* sz1, int nLen1, const CT* sz2, int nLen2)\r
-{\r
- const std::locale loc;\r
- const std::collate<CT>& coll = SS_USE_FACET(loc, std::collate<CT>);\r
-\r
- // Some implementations seem to have trouble using the collate<>\r
- // facet typedefs so we'll just default to basic_string and hope\r
- // that's what the collate facet uses (which it generally should)\r
-\r
-// std::collate<CT>::string_type s1(sz1);\r
-// std::collate<CT>::string_type s2(sz2);\r
- const std::basic_string<CT> sEmpty;\r
- std::basic_string<CT> s1(sz1 ? sz1 : sEmpty.c_str());\r
- std::basic_string<CT> s2(sz2 ? sz2 : sEmpty.c_str());\r
-\r
- sslwr(const_cast<CT*>(s1.c_str()), nLen1);\r
- sslwr(const_cast<CT*>(s2.c_str()), nLen2);\r
- return coll.compare(s2.c_str(), s2.c_str()+nLen2,\r
- s1.c_str(), s1.c_str()+nLen1);\r
-}\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// ssfmtmsg: FormatMessage equivalents. Needed because I added a CString facade\r
-// Again -- no equivalent of these on non-Win32 builds but their might one day\r
-// be one if the message facet gets implemented\r
-// -----------------------------------------------------------------------------\r
-#if defined (SS_WIN32) && !defined(SS_ANSI)\r
- inline DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId,\r
- DWORD dwLangId, PSTR pBuf, DWORD nSize,\r
- va_list* vlArgs)\r
- { \r
- return FormatMessageA(dwFlags, pSrc, dwMsgId, dwLangId,\r
- pBuf, nSize,vlArgs);\r
- }\r
- inline DWORD ssfmtmsg(DWORD dwFlags, LPCVOID pSrc, DWORD dwMsgId,\r
- DWORD dwLangId, PWSTR pBuf, DWORD nSize,\r
- va_list* vlArgs)\r
- {\r
- return FormatMessageW(dwFlags, pSrc, dwMsgId, dwLangId,\r
- pBuf, nSize,vlArgs);\r
- }\r
-#else\r
-#endif\r
- \r
-\r
-\r
-// FUNCTION: sscpy. Copies up to 'nMax' characters from pSrc to pDst.\r
-// -----------------------------------------------------------------------------\r
-// FUNCTION: sscpy\r
-// inline int sscpy(PSTR pDst, PCSTR pSrc, int nMax=-1);\r
-// inline int sscpy(PUSTR pDst, PCSTR pSrc, int nMax=-1)\r
-// inline int sscpy(PSTR pDst, PCWSTR pSrc, int nMax=-1);\r
-// inline int sscpy(PWSTR pDst, PCWSTR pSrc, int nMax=-1);\r
-// inline int sscpy(PWSTR pDst, PCSTR pSrc, int nMax=-1);\r
-//\r
-// DESCRIPTION:\r
-// This function is very much (but not exactly) like strcpy. These\r
-// overloads simplify copying one C-style string into another by allowing\r
-// the caller to specify two different types of strings if necessary.\r
-//\r
-// The strings must NOT overlap\r
-//\r
-// "Character" is expressed in terms of the destination string, not\r
-// the source. If no 'nMax' argument is supplied, then the number of\r
-// characters copied will be sslen(pSrc). A NULL terminator will\r
-// also be added so pDst must actually be big enough to hold nMax+1\r
-// characters. The return value is the number of characters copied,\r
-// not including the NULL terminator.\r
-//\r
-// PARAMETERS: \r
-// pSrc - the string to be copied FROM. May be a char based string, an\r
-// MBCS string (in Win32 builds) or a wide string (wchar_t).\r
-// pSrc - the string to be copied TO. Also may be either MBCS or wide\r
-// nMax - the maximum number of characters to be copied into szDest. Note\r
-// that this is expressed in whatever a "character" means to pDst.\r
-// If pDst is a wchar_t type string than this will be the maximum\r
-// number of wchar_ts that my be copied. The pDst string must be\r
-// large enough to hold least nMaxChars+1 characters.\r
-// If the caller supplies no argument for nMax this is a signal to\r
-// the routine to copy all the characters in pSrc, regardless of\r
-// how long it is.\r
-//\r
-// RETURN VALUE: none\r
-// -----------------------------------------------------------------------------\r
-template<typename CT1, typename CT2>\r
-inline int sscpycvt(CT1* pDst, const CT2* pSrc, int nChars)\r
-{\r
- StdCodeCvt(pDst, pSrc, nChars);\r
- pDst[SSMAX(nChars, 0)] = '\0';\r
- return nChars;\r
-}\r
-\r
-template<typename CT1, typename CT2>\r
-inline int sscpy(CT1* pDst, const CT2* pSrc, int nMax, int nLen)\r
-{\r
- return sscpycvt(pDst, pSrc, SSMIN(nMax, nLen));\r
-}\r
-template<typename CT1, typename CT2>\r
-inline int sscpy(CT1* pDst, const CT2* pSrc, int nMax)\r
-{\r
- return sscpycvt(pDst, pSrc, SSMIN(nMax, sslen(pSrc)));\r
-}\r
-template<typename CT1, typename CT2>\r
-inline int sscpy(CT1* pDst, const CT2* pSrc)\r
-{\r
- return sscpycvt(pDst, pSrc, sslen(pSrc));\r
-}\r
-template<typename CT1, typename CT2>\r
-inline int sscpy(CT1* pDst, const std::basic_string<CT2>& sSrc, int nMax)\r
-{\r
- return sscpycvt(pDst, sSrc.c_str(), SSMIN(nMax, (int)sSrc.length()));\r
-}\r
-template<typename CT1, typename CT2>\r
-inline int sscpy(CT1* pDst, const std::basic_string<CT2>& sSrc)\r
-{\r
- return sscpycvt(pDst, sSrc.c_str(), (int)sSrc.length());\r
-}\r
-\r
-#ifdef SS_INC_COMDEF\r
- template<typename CT1>\r
- inline int sscpy(CT1* pDst, const _bstr_t& bs, int nMax)\r
- {\r
- return sscpycvt(pDst, static_cast<PCOLESTR>(bs),\r
- SSMIN(nMax, static_cast<int>(bs.length())));\r
- }\r
- template<typename CT1>\r
- inline int sscpy(CT1* pDst, const _bstr_t& bs)\r
- {\r
- return sscpy(pDst, bs, static_cast<int>(bs.length()));\r
- }\r
-#endif\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// Functional objects for changing case. They also let you pass locales\r
-// -----------------------------------------------------------------------------\r
-\r
-#ifdef SS_ANSI\r
- template<typename CT>\r
- struct SSToUpper : public std::binary_function<CT, std::locale, CT>\r
- {\r
- inline CT operator()(const CT& t, const std::locale& loc) const\r
- {\r
- return sstoupper<CT>(t, loc);\r
- }\r
- };\r
- template<typename CT>\r
- struct SSToLower : public std::binary_function<CT, std::locale, CT>\r
- {\r
- inline CT operator()(const CT& t, const std::locale& loc) const\r
- {\r
- return sstolower<CT>(t, loc);\r
- }\r
- };\r
-#endif\r
-\r
-// This struct is used for TrimRight() and TrimLeft() function implementations.\r
-//template<typename CT>\r
-//struct NotSpace : public std::unary_function<CT, bool>\r
-//{\r
-// const std::locale& loc;\r
-// inline NotSpace(const std::locale& locArg) : loc(locArg) {}\r
-// inline bool operator() (CT t) { return !std::isspace(t, loc); }\r
-//};\r
-template<typename CT>\r
-struct NotSpace : public std::unary_function<CT, bool>\r
-{\r
-\r
- // DINKUMWARE BUG:\r
- // Note -- using std::isspace in a COM DLL gives us access violations\r
- // because it causes the dynamic addition of a function to be called\r
- // when the library shuts down. Unfortunately the list is maintained\r
- // in DLL memory but the function is in static memory. So the COM DLL\r
- // goes away along with the function that was supposed to be called,\r
- // and then later when the DLL CRT shuts down it unloads the list and\r
- // tries to call the long-gone function.\r
- // This is DinkumWare's implementation problem. Until then, we will\r
- // use good old isspace and iswspace from the CRT unless they\r
- // specify SS_ANSI\r
- \r
- const std::locale loc;\r
- NotSpace(const std::locale& locArg=std::locale()) : loc(locArg) {}\r
- bool operator() (CT t) const { return !std::isspace(t, loc); }\r
-};\r
-\r
-\r
-\r
-\r
-// Now we can define the template (finally!)\r
-// =============================================================================\r
-// TEMPLATE: CStdStr\r
-// template<typename CT> class CStdStr : public std::basic_string<CT>\r
-//\r
-// REMARKS:\r
-// This template derives from basic_string<CT> and adds some MFC CString-\r
-// like functionality\r
-//\r
-// Basically, this is my attempt to make Standard C++ library strings as\r
-// easy to use as the MFC CString class.\r
-//\r
-// Note that although this is a template, it makes the assumption that the\r
-// template argument (CT, the character type) is either char or wchar_t. \r
-// =============================================================================\r
-\r
-//#define CStdStr _SS // avoid compiler warning 4786\r
-\r
-// template<typename ARG> ARG& FmtArg(ARG& arg) { return arg; }\r
-// PCSTR FmtArg(const std::string& arg) { return arg.c_str(); }\r
-// PCWSTR FmtArg(const std::wstring& arg) { return arg.c_str(); }\r
-\r
-template<typename ARG>\r
-struct FmtArg\r
-{\r
- explicit FmtArg(const ARG& arg) : a_(arg) {}\r
- const ARG& Val() const { return a_; }\r
- const ARG& a_;\r
-private:\r
- FmtArg& operator=(const FmtArg&) { return *this; }\r
-};\r
-\r
-template<typename CT>\r
-class CStdStr : public std::basic_string<CT>\r
-{\r
- // Typedefs for shorter names. Using these names also appears to help\r
- // us avoid some ambiguities that otherwise arise on some platforms\r
-\r
- typedef typename std::basic_string<CT> MYBASE; // my base class\r
- typedef CStdStr<CT> MYTYPE; // myself\r
- typedef typename MYBASE::const_pointer PCMYSTR; // PCSTR or PCWSTR \r
- typedef typename MYBASE::pointer PMYSTR; // PSTR or PWSTR\r
- typedef typename MYBASE::iterator MYITER; // my iterator type\r
- typedef typename MYBASE::const_iterator MYCITER; // you get the idea...\r
- typedef typename MYBASE::reverse_iterator MYRITER;\r
- typedef typename MYBASE::size_type MYSIZE; \r
- typedef typename MYBASE::value_type MYVAL; \r
- typedef typename MYBASE::allocator_type MYALLOC;\r
- \r
-public:\r
-\r
- // shorthand conversion from PCTSTR to string resource ID\r
- #define _TRES(pctstr) (LOWORD((DWORD)(pctstr))) \r
-\r
- // CStdStr inline constructors\r
- CStdStr()\r
- {\r
- }\r
-\r
- CStdStr(const MYTYPE& str) : MYBASE(SSREF(str))\r
- {\r
- }\r
-\r
- CStdStr(const std::string& str)\r
- {\r
- ssasn(*this, SSREF(str));\r
- }\r
-\r
- CStdStr(const std::wstring& str)\r
- {\r
- ssasn(*this, SSREF(str));\r
- }\r
-\r
- CStdStr(PCMYSTR pT, MYSIZE n) : MYBASE(pT, n)\r
- {\r
- }\r
-\r
-#ifdef SS_UNSIGNED\r
- CStdStr(PCUSTR pU)\r
- {\r
- *this = reinterpret_cast<PCSTR>(pU);\r
- }\r
-#endif\r
-\r
- CStdStr(PCSTR pA)\r
- {\r
- #ifdef SS_ANSI\r
- *this = pA;\r
- #else\r
- if ( 0 != HIWORD(pA) )\r
- *this = pA;\r
- else if ( 0 != pA && !Load(_TRES(pA)) )\r
- TRACE(_T("Can't load string %u\n"), _TRES(pA));\r
- #endif\r
- }\r
-\r
- CStdStr(PCWSTR pW)\r
- {\r
- #ifdef SS_ANSI\r
- *this = pW;\r
- #else\r
- if ( 0 != HIWORD(pW) )\r
- *this = pW;\r
- else if ( 0 != pW && !Load(_TRES(pW)) )\r
- TRACE(_T("Can't load string %u\n"), _TRES(pW));\r
- #endif\r
- }\r
-\r
- CStdStr(MYCITER first, MYCITER last)\r
- : MYBASE(first, last)\r
- {\r
- }\r
-\r
- CStdStr(MYSIZE nSize, MYVAL ch, const MYALLOC& al=MYALLOC())\r
- : MYBASE(nSize, ch, al)\r
- {\r
- }\r
-\r
- #ifdef SS_INC_COMDEF\r
- CStdStr(const _bstr_t& bstr)\r
- {\r
- if ( bstr.length() > 0 )\r
- this->append(static_cast<PCMYSTR>(bstr), bstr.length());\r
- }\r
- #endif\r
-\r
- // CStdStr inline assignment operators -- the ssasn function now takes care\r
- // of fixing the MSVC assignment bug (see knowledge base article Q172398).\r
- MYTYPE& operator=(const MYTYPE& str)\r
- { \r
- ssasn(*this, str); \r
- return *this;\r
- }\r
-\r
- MYTYPE& operator=(const std::string& str)\r
- {\r
- ssasn(*this, str);\r
- return *this;\r
- }\r
-\r
- MYTYPE& operator=(const std::wstring& str)\r
- {\r
- ssasn(*this, str);\r
- return *this;\r
- }\r
-\r
- MYTYPE& operator=(PCSTR pA)\r
- {\r
- ssasn(*this, pA);\r
- return *this;\r
- }\r
-\r
- MYTYPE& operator=(PCWSTR pW)\r
- {\r
- ssasn(*this, pW);\r
- return *this;\r
- }\r
-\r
-#ifdef SS_UNSIGNED\r
- MYTYPE& operator=(PCUSTR pU)\r
- {\r
- ssasn(*this, reinterpret_cast<PCSTR>(pU)):\r
- return *this;\r
- }\r
-#endif\r
-\r
- MYTYPE& operator=(CT t)\r
- {\r
- Q172398(*this);\r
- this->assign(1, t);\r
- return *this;\r
- }\r
-\r
- #ifdef SS_INC_COMDEF\r
- MYTYPE& operator=(const _bstr_t& bstr)\r
- {\r
- if ( bstr.length() > 0 )\r
- {\r
- this->assign(static_cast<PCMYSTR>(bstr), bstr.length());\r
- return *this;\r
- }\r
- else\r
- {\r
- this->erase();\r
- return *this;\r
- }\r
- }\r
- #endif\r
-\r
-\r
- // Overloads also needed to fix the MSVC assignment bug (KB: Q172398)\r
- // *** Thanks to Pete The Plumber for catching this one ***\r
- // They also are compiled if you have explicitly turned off refcounting\r
- #if ( defined(_MSC_VER) && ( _MSC_VER < 1200 ) ) || defined(SS_NO_REFCOUNT) \r
-\r
- MYTYPE& assign(const MYTYPE& str)\r
- {\r
- ssasn(*this, str);\r
- return *this;\r
- }\r
-\r
- MYTYPE& assign(const MYTYPE& str, MYSIZE nStart, MYSIZE nChars)\r
- {\r
- // This overload of basic_string::assign is supposed to assign up to\r
- // <nChars> or the NULL terminator, whichever comes first. Since we\r
- // are about to call a less forgiving overload (in which <nChars>\r
- // must be a valid length), we must adjust the length here to a safe\r
- // value. Thanks to Ullrich Pollähne for catching this bug\r
-\r
- nChars = SSMIN(nChars, str.length() - nStart);\r
-\r
- // Watch out for assignment to self\r
-\r
- if ( this == &str )\r
- {\r
- MYTYPE strTemp(str.c_str()+nStart, nChars);\r
- MYBASE::assign(strTemp);\r
- }\r
- else\r
- {\r
- Q172398(*this);\r
- MYBASE::assign(str.c_str()+nStart, nChars);\r
- }\r
- return *this;\r
- }\r
-\r
- MYTYPE& assign(const MYBASE& str)\r
- {\r
- ssasn(*this, str);\r
- return *this;\r
- }\r
-\r
- MYTYPE& assign(const MYBASE& str, MYSIZE nStart, MYSIZE nChars)\r
- {\r
- // This overload of basic_string::assign is supposed to assign up to\r
- // <nChars> or the NULL terminator, whichever comes first. Since we\r
- // are about to call a less forgiving overload (in which <nChars>\r
- // must be a valid length), we must adjust the length here to a safe\r
- // value. Thanks to Ullrich Pollähne for catching this bug\r
-\r
- nChars = SSMIN(nChars, str.length() - nStart);\r
-\r
- // Watch out for assignment to self\r
-\r
- if ( this == &str ) // watch out for assignment to self\r
- {\r
- MYTYPE strTemp(str.c_str() + nStart, nChars);\r
- MYBASE::assign(strTemp);\r
- }\r
- else\r
- {\r
- Q172398(*this);\r
- MYBASE::assign(str.c_str()+nStart, nChars);\r
- }\r
- return *this;\r
- }\r
-\r
- MYTYPE& assign(const CT* pC, MYSIZE nChars)\r
- {\r
- // Q172398 only fix -- erase before assigning, but not if we're\r
- // assigning from our own buffer\r
-\r
- #if defined ( _MSC_VER ) && ( _MSC_VER < 1200 )\r
- if ( !this->empty() &&\r
- ( pC < this->data() || pC > this->data() + this->capacity() ) )\r
- {\r
- this->erase();\r
- }\r
- #endif\r
- Q172398(*this);\r
- MYBASE::assign(pC, nChars);\r
- return *this;\r
- }\r
-\r
- MYTYPE& assign(MYSIZE nChars, MYVAL val)\r
- {\r
- Q172398(*this);\r
- MYBASE::assign(nChars, val);\r
- return *this;\r
- }\r
-\r
- MYTYPE& assign(const CT* pT)\r
- {\r
- return this->assign(pT, MYBASE::traits_type::length(pT));\r
- }\r
-\r
- MYTYPE& assign(MYCITER iterFirst, MYCITER iterLast)\r
- {\r
- #if defined ( _MSC_VER ) && ( _MSC_VER < 1200 ) \r
- // Q172398 fix. don't call erase() if we're assigning from ourself\r
- if ( iterFirst < this->begin() ||\r
- iterFirst > this->begin() + this->size() )\r
- {\r
- this->erase()\r
- }\r
- #endif\r
- this->replace(this->begin(), this->end(), iterFirst, iterLast);\r
- return *this;\r
- }\r
- #endif\r
-\r
-\r
- // -------------------------------------------------------------------------\r
- // CStdStr inline concatenation.\r
- // -------------------------------------------------------------------------\r
- MYTYPE& operator+=(const MYTYPE& str)\r
- {\r
- ssadd(*this, str);\r
- return *this;\r
- }\r
-\r
- MYTYPE& operator+=(const std::string& str)\r
- {\r
- ssadd(*this, str);\r
- return *this; \r
- }\r
-\r
- MYTYPE& operator+=(const std::wstring& str)\r
- {\r
- ssadd(*this, str);\r
- return *this;\r
- }\r
-\r
- MYTYPE& operator+=(PCSTR pA)\r
- {\r
- ssadd(*this, pA);\r
- return *this;\r
- }\r
-\r
- MYTYPE& operator+=(PCWSTR pW)\r
- {\r
- ssadd(*this, pW);\r
- return *this;\r
- }\r
-\r
- MYTYPE& operator+=(CT t)\r
- {\r
- this->append(1, t);\r
- return *this;\r
- }\r
- #ifdef SS_INC_COMDEF // if we have _bstr_t, define a += for it too.\r
- MYTYPE& operator+=(const _bstr_t& bstr)\r
- {\r
- return this->operator+=(static_cast<PCMYSTR>(bstr));\r
- }\r
- #endif\r
-\r
-\r
- // -------------------------------------------------------------------------\r
- // Case changing functions\r
- // -------------------------------------------------------------------------\r
-\r
- MYTYPE& ToUpper()\r
- {\r
- // Strictly speaking, this would be about the most portable way\r
-\r
- // std::transform(begin(),\r
- // end(),\r
- // begin(),\r
- // std::bind2nd(SSToUpper<CT>(), std::locale()));\r
-\r
- // But practically speaking, this works faster\r
-\r
- if ( !empty() )\r
- ssupr(GetBuf(), this->size());\r
-\r
- return *this;\r
- }\r
-\r
-\r
-\r
- MYTYPE& ToLower()\r
- {\r
- // Strictly speaking, this would be about the most portable way\r
-\r
- // std::transform(begin(),\r
- // end(),\r
- // begin(),\r
- // std::bind2nd(SSToLower<CT>(), std::locale()));\r
-\r
- // But practically speaking, this works faster\r
-\r
- if ( !empty() )\r
- sslwr(GetBuf(), this->size());\r
-\r
- return *this;\r
- }\r
-\r
-\r
-\r
- MYTYPE& Normalize()\r
- {\r
- return Trim().ToLower();\r
- }\r
-\r
-\r
- // -------------------------------------------------------------------------\r
- // CStdStr -- Direct access to character buffer. In the MS' implementation,\r
- // the at() function that we use here also calls _Freeze() providing us some\r
- // protection from multithreading problems associated with ref-counting.\r
- // In VC 7 and later, of course, the ref-counting stuff is gone.\r
- // -------------------------------------------------------------------------\r
-\r
- CT* GetBuf(int nMinLen=-1)\r
- {\r
- if ( static_cast<int>(size()) < nMinLen )\r
- this->resize(static_cast<MYSIZE>(nMinLen));\r
-\r
- return this->empty() ? const_cast<CT*>(this->data()) : &(this->at(0));\r
- }\r
-\r
- CT* SetBuf(int nLen)\r
- {\r
- nLen = ( nLen > 0 ? nLen : 0 );\r
- if ( this->capacity() < 1 && nLen == 0 )\r
- this->resize(1);\r
-\r
- this->resize(static_cast<MYSIZE>(nLen));\r
- return const_cast<CT*>(this->data());\r
- }\r
- void RelBuf(int nNewLen=-1)\r
- {\r
- this->resize(static_cast<MYSIZE>(nNewLen > -1 ? nNewLen :\r
- sslen(this->c_str())));\r
- }\r
-\r
- void BufferRel() { RelBuf(); } // backwards compatability\r
- CT* Buffer() { return GetBuf(); } // backwards compatability\r
- CT* BufferSet(int nLen) { return SetBuf(nLen);}// backwards compatability\r
-\r
- bool Equals(const CT* pT, bool bUseCase=false) const\r
- { // get copy, THEN compare (thread safe)\r
- return bUseCase ? this->compare(pT) == 0 :\r
- ssicmp(MYTYPE(*this).c_str(), pT) == 0;\r
- } \r
-\r
- // -------------------------------------------------------------------------\r
- // FUNCTION: CStdStr::Load\r
- // REMARKS:\r
- // Loads string from resource specified by nID\r
- //\r
- // PARAMETERS:\r
- // nID - resource Identifier. Purely a Win32 thing in this case\r
- //\r
- // RETURN VALUE:\r
- // true if successful, false otherwise\r
- // -------------------------------------------------------------------------\r
-\r
-#ifndef SS_ANSI\r
-\r
- bool Load(UINT nId, HMODULE hModule=NULL)\r
- {\r
- bool bLoaded = false; // set to true of we succeed.\r
-\r
- #ifdef _MFC_VER // When in Rome (or MFC land)...\r
-\r
- CString strRes;\r
- bLoaded = FALSE != strRes.LoadString(nId);\r
- if ( bLoaded )\r
- *this = strRes;\r
-\r
- #else // otherwise make our own hackneyed version of CString's Load\r
- \r
- // Get the resource name and module handle\r
-\r
- if ( NULL == hModule )\r
- hModule = GetResourceHandle();\r
-\r
- PCTSTR szName = MAKEINTRESOURCE((nId>>4)+1); // lifted \r
- DWORD dwSize = 0;\r
-\r
- // No sense continuing if we can't find the resource\r
-\r
- HRSRC hrsrc = ::FindResource(hModule, szName, RT_STRING);\r
-\r
- if ( NULL == hrsrc )\r
- {\r
- TRACE(_T("Cannot find resource %d: 0x%X"), nId, ::GetLastError());\r
- }\r
- else if ( 0 == (dwSize = ::SizeofResource(hModule, hrsrc) / sizeof(CT)))\r
- {\r
- TRACE(_T("Cant get size of resource %d 0x%X\n"),nId,GetLastError());\r
- }\r
- else\r
- {\r
- bLoaded = 0 != ssload(hModule, nId, GetBuf(dwSize), dwSize);\r
- ReleaseBuffer();\r
- }\r
-\r
- #endif // #ifdef _MFC_VER\r
-\r
- if ( !bLoaded )\r
- TRACE(_T("String not loaded 0x%X\n"), ::GetLastError());\r
-\r
- return bLoaded;\r
- }\r
-\r
-#endif // #ifdef SS_ANSI\r
- \r
- // -------------------------------------------------------------------------\r
- // FUNCTION: CStdStr::Format\r
- // void _cdecl Formst(CStdStringA& PCSTR szFormat, ...)\r
- // void _cdecl Format(PCSTR szFormat);\r
- // \r
- // DESCRIPTION:\r
- // This function does sprintf/wsprintf style formatting on CStdStringA\r
- // objects. It looks a lot like MFC's CString::Format. Some people\r
- // might even call this identical. Fortunately, these people are now\r
- // dead... heh heh.\r
- //\r
- // PARAMETERS: \r
- // nId - ID of string resource holding the format string\r
- // szFormat - a PCSTR holding the format specifiers\r
- // argList - a va_list holding the arguments for the format specifiers.\r
- //\r
- // RETURN VALUE: None.\r
- // -------------------------------------------------------------------------\r
- // formatting (using wsprintf style formatting)\r
-\r
- // If they want a Format() function that safely handles string objects\r
- // without casting\r
- \r
-#ifdef SS_SAFE_FORMAT \r
- \r
- // Question: Joe, you wacky coder you, why do you have so many overloads\r
- // of the Format() function\r
- // Answer: One reason only - CString compatability. In short, by making\r
- // the Format() function a template this way, I can do strong typing\r
- // and allow people to pass CStdString arguments as fillers for\r
- // "%s" format specifiers without crashing their program! The downside\r
- // is that I need to overload on the number of arguments. If you are\r
- // passing more arguments than I have listed below in any of my\r
- // overloads, just add another one.\r
- //\r
- // Yes, yes, this is really ugly. In essence what I am doing here is\r
- // protecting people from a bad (and incorrect) programming practice\r
- // that they should not be doing anyway. I am protecting them from\r
- // themselves. Why am I doing this? Well, if you had any idea the\r
- // number of times I've been emailed by people about this\r
- // "incompatability" in my code, you wouldn't ask.\r
-\r
- void Fmt(const CT* szFmt, ...)\r
- {\r
- va_list argList;\r
- va_start(argList, szFmt);\r
- FormatV(szFmt, argList);\r
- va_end(argList);\r
- }\r
-\r
-#ifndef SS_ANSI\r
-\r
- void Format(UINT nId)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) ) \r
- this->swap(strFmt);\r
- }\r
- template<class A1>\r
- void Format(UINT nId, const A1& v)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- Fmt(strFmt, FmtArg<A1>(v).Val());\r
- }\r
- template<class A1, class A2>\r
- void Format(UINT nId, const A1& v1, const A2& v2)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val());\r
- }\r
- template<class A1, class A2, class A3>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(),FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(),FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(),FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(), FmtArg<A13>(v13).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13, class A14>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13, const A14& v14)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(), FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13, class A14, class A15>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13, const A14& v14, const A15& v15)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),\r
- FmtArg<A15>(v15).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13, class A14, class A15, class A16>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13, const A14& v14, const A15& v15,\r
- const A16& v16)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),\r
- FmtArg<A15>(v15).Val(), FmtArg<A16>(v16).Val());\r
- }\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13, class A14, class A15, class A16, class A17>\r
- void Format(UINT nId, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13, const A14& v14, const A15& v15,\r
- const A16& v16, const A17& v17)\r
- {\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- {\r
- Fmt(strFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),\r
- FmtArg<A15>(v15).Val(),FmtArg<A16>(v16).Val(),FmtArg<A17>(v17).Val());\r
- }\r
- }\r
- \r
-#endif // #ifndef SS_ANSI\r
-\r
- // ...now the other overload of Format: the one that takes a string literal\r
-\r
- void Format(const CT* szFmt)\r
- {\r
- *this = szFmt;\r
- }\r
- template<class A1>\r
- void Format(const CT* szFmt, A1 v)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v).Val());\r
- }\r
- template<class A1, class A2>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val());\r
- }\r
- template<class A1, class A2, class A3>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(),FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(), FmtArg<A13>(v13).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13, class A14>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13, const A14& v14)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(), FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13, class A14, class A15>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13, const A14& v14, const A15& v15)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),\r
- FmtArg<A15>(v15).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13, class A14, class A15, class A16>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13, const A14& v14, const A15& v15,\r
- const A16& v16)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),\r
- FmtArg<A15>(v15).Val(), FmtArg<A16>(v16).Val());\r
- }\r
- template<class A1, class A2, class A3, class A4, class A5, class A6,\r
- class A7, class A8, class A9, class A10, class A11, class A12,\r
- class A13, class A14, class A15, class A16, class A17>\r
- void Format(const CT* szFmt, const A1& v1, const A2& v2, const A3& v3,\r
- const A4& v4, const A5& v5, const A6& v6, const A7& v7,\r
- const A8& v8, const A9& v9, const A10& v10, const A11& v11,\r
- const A12& v12, const A13& v13, const A14& v14, const A15& v15,\r
- const A16& v16, const A17& v17)\r
- {\r
- Fmt(szFmt, FmtArg<A1>(v1).Val(), FmtArg<A2>(v2).Val(),\r
- FmtArg<A3>(v3).Val(), FmtArg<A4>(v4).Val(), FmtArg<A5>(v5).Val(),\r
- FmtArg<A6>(v6).Val(), FmtArg<A7>(v7).Val(), FmtArg<A8>(v8).Val(),\r
- FmtArg<A9>(v9).Val(), FmtArg<A10>(v10).Val(),FmtArg<A11>(v11).Val(),\r
- FmtArg<A12>(v12).Val(),FmtArg<A13>(v13).Val(),FmtArg<A14>(v14).Val(),\r
- FmtArg<A15>(v15).Val(),FmtArg<A16>(v16).Val(),FmtArg<A17>(v17).Val());\r
- }\r
-\r
-#else // #ifdef SS_SAFE_FORMAT\r
-\r
-\r
-#ifndef SS_ANSI\r
-\r
- void Format(UINT nId, ...)\r
- {\r
- va_list argList;\r
- va_start(argList, nId);\r
- va_start(argList, nId);\r
-\r
- MYTYPE strFmt;\r
- if ( strFmt.Load(nId) )\r
- FormatV(strFmt, argList);\r
-\r
- va_end(argList);\r
- }\r
- \r
-#endif // #ifdef SS_ANSI\r
-\r
- void Format(const CT* szFmt, ...)\r
- {\r
- va_list argList;\r
- va_start(argList, szFmt);\r
- FormatV(szFmt, argList);\r
- va_end(argList);\r
- }\r
-\r
-#endif // #ifdef SS_SAFE_FORMAT\r
-\r
- void AppendFormat(const CT* szFmt, ...)\r
- {\r
- va_list argList;\r
- va_start(argList, szFmt);\r
- AppendFormatV(szFmt, argList);\r
- va_end(argList);\r
- }\r
-\r
- #define MAX_FMT_TRIES 5 // #of times we try \r
- #define FMT_BLOCK_SIZE 2048 // # of bytes to increment per try\r
- #define BUFSIZE_1ST 256\r
- #define BUFSIZE_2ND 512\r
- #define STD_BUF_SIZE 1024\r
-\r
- // an efficient way to add formatted characters to the string. You may only\r
- // add up to STD_BUF_SIZE characters at a time, though\r
- void AppendFormatV(const CT* szFmt, va_list argList)\r
- {\r
- CT szBuf[STD_BUF_SIZE];\r
- #if defined(SS_ANSI) || !defined(_MSC_VER)\r
- int nLen = ssvsprintf(szBuf, STD_BUF_SIZE-1, szFmt, argList);\r
- #else\r
- int nLen = ssnprintf(szBuf, STD_BUF_SIZE-1, szFmt, argList);\r
- #endif\r
- if ( 0 < nLen )\r
- this->append(szBuf, nLen);\r
- }\r
-\r
- // -------------------------------------------------------------------------\r
- // FUNCTION: FormatV\r
- // void FormatV(PCSTR szFormat, va_list, argList);\r
- // \r
- // DESCRIPTION:\r
- // This function formats the string with sprintf style format-specs. \r
- // It makes a general guess at required buffer size and then tries\r
- // successively larger buffers until it finds one big enough or a\r
- // threshold (MAX_FMT_TRIES) is exceeded.\r
- //\r
- // PARAMETERS:\r
- // szFormat - a PCSTR holding the format of the output\r
- // argList - a Microsoft specific va_list for variable argument lists\r
- //\r
- // RETURN VALUE:\r
- // -------------------------------------------------------------------------\r
-\r
- void FormatV(const CT* szFormat, va_list argList)\r
- {\r
- #if defined(SS_ANSI) || !defined(_MSC_VER)\r
- int nLen = sslen(szFormat) + STD_BUF_SIZE;\r
- ssvsprintf(GetBuffer(nLen), nLen-1, szFormat, argList);\r
- ReleaseBuffer();\r
-\r
- #else\r
-\r
- CT* pBuf = NULL;\r
- int nChars = 1;\r
- int nUsed = 0;\r
- size_type nActual = 0;\r
- int nTry = 0;\r
-\r
- do\r
- {\r
- // Grow more than linearly (e.g. 512, 1536, 3072, etc)\r
-\r
- nChars += ((nTry+1) * FMT_BLOCK_SIZE);\r
- pBuf = reinterpret_cast<CT*>(_alloca(sizeof(CT)*nChars));\r
- nUsed = ssnprintf(pBuf, nChars-1, szFormat, argList);\r
-\r
- // Ensure proper NULL termination.\r
-\r
- nActual = nUsed == -1 ? nChars-1 : SSMIN(nUsed, nChars-1);\r
- pBuf[nActual+1]= '\0';\r
-\r
-\r
- } while ( nUsed < 0 && nTry++ < MAX_FMT_TRIES );\r
-\r
- // assign whatever we managed to format\r
-\r
- this->assign(pBuf, nActual);\r
-\r
- #endif\r
- }\r
- \r
-\r
- // -------------------------------------------------------------------------\r
- // CString Facade Functions:\r
- //\r
- // The following methods are intended to allow you to use this class as a\r
- // drop-in replacement for CString.\r
- // -------------------------------------------------------------------------\r
- #ifdef SS_WIN32\r
- BSTR AllocSysString() const\r
- {\r
- ostring os;\r
- ssasn(os, *this);\r
- return ::SysAllocString(os.c_str());\r
- }\r
- #endif\r
-\r
- int Collate(PCMYSTR szThat) const\r
- {\r
- return sscoll(this->c_str(), this->length(), szThat, sslen(szThat));\r
- }\r
-\r
- int CollateNoCase(PCMYSTR szThat) const\r
- {\r
- return ssicoll(this->c_str(), this->length(), szThat, sslen(szThat));\r
- }\r
-\r
- int Compare(PCMYSTR szThat) const\r
- {\r
- return this->compare(szThat); \r
- }\r
-\r
- int CompareNoCase(PCMYSTR szThat) const\r
- {\r
- return ssicmp(this->c_str(), szThat);\r
- }\r
-\r
- int Delete(int nIdx, int nCount=1)\r
- {\r
- if ( nIdx < 0 )\r
- nIdx = 0;\r
-\r
- if ( nIdx < GetLength() )\r
- this->erase(static_cast<MYSIZE>(nIdx), static_cast<MYSIZE>(nCount));\r
-\r
- return GetLength();\r
- }\r
-\r
- void Empty()\r
- {\r
- this->erase();\r
- }\r
-\r
- int Find(CT ch) const\r
- {\r
- MYSIZE nIdx = this->find_first_of(ch);\r
- return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);\r
- }\r
-\r
- int Find(PCMYSTR szSub) const\r
- {\r
- MYSIZE nIdx = this->find(szSub);\r
- return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);\r
- }\r
-\r
- int Find(CT ch, int nStart) const\r
- {\r
- // CString::Find docs say add 1 to nStart when it's not zero\r
- // CString::Find code doesn't do that however. We'll stick\r
- // with what the code does\r
-\r
- MYSIZE nIdx = this->find_first_of(ch, static_cast<MYSIZE>(nStart));\r
- return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);\r
- }\r
-\r
- int Find(PCMYSTR szSub, int nStart) const\r
- {\r
- // CString::Find docs say add 1 to nStart when it's not zero\r
- // CString::Find code doesn't do that however. We'll stick\r
- // with what the code does\r
-\r
- MYSIZE nIdx = this->find(szSub, static_cast<MYSIZE>(nStart));\r
- return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);\r
- }\r
-\r
- int FindOneOf(PCMYSTR szCharSet) const\r
- {\r
- MYSIZE nIdx = this->find_first_of(szCharSet);\r
- return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);\r
- }\r
-\r
-#ifndef SS_ANSI\r
- void FormatMessage(PCMYSTR szFormat, ...) throw(std::exception)\r
- {\r
- va_list argList;\r
- va_start(argList, szFormat);\r
- PMYSTR szTemp;\r
- if ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,\r
- szFormat, 0, 0,\r
- reinterpret_cast<PMYSTR>(&szTemp), 0, &argList) == 0 ||\r
- szTemp == 0 )\r
- {\r
- throw std::runtime_error("out of memory");\r
- }\r
- *this = szTemp;\r
- LocalFree(szTemp);\r
- va_end(argList);\r
- }\r
-\r
- void FormatMessage(UINT nFormatId, ...) throw(std::exception)\r
- {\r
- MYTYPE sFormat;\r
- VERIFY(sFormat.LoadString(nFormatId) != 0);\r
- va_list argList;\r
- va_start(argList, nFormatId);\r
- PMYSTR szTemp;\r
- if ( ssfmtmsg(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,\r
- sFormat, 0, 0,\r
- reinterpret_cast<PMYSTR>(&szTemp), 0, &argList) == 0 ||\r
- szTemp == 0)\r
- {\r
- throw std::runtime_error("out of memory");\r
- }\r
- *this = szTemp;\r
- LocalFree(szTemp);\r
- va_end(argList);\r
- }\r
-#endif\r
-\r
-\r
- // -------------------------------------------------------------------------\r
- // GetXXXX -- Direct access to character buffer\r
- // -------------------------------------------------------------------------\r
- CT GetAt(int nIdx) const\r
- {\r
- return this->at(static_cast<MYSIZE>(nIdx));\r
- }\r
-\r
- CT* GetBuffer(int nMinLen=-1)\r
- {\r
- return GetBuf(nMinLen);\r
- }\r
-\r
- CT* GetBufferSetLength(int nLen)\r
- {\r
- return BufferSet(nLen);\r
- }\r
-\r
- // GetLength() -- MFC docs say this is the # of BYTES but\r
- // in truth it is the number of CHARACTERs (chars or wchar_ts)\r
- int GetLength() const\r
- {\r
- return static_cast<int>(this->length());\r
- }\r
-\r
- \r
- int Insert(int nIdx, CT ch)\r
- {\r
- if ( static_cast<MYSIZE>(nIdx) > this->size() -1 )\r
- this->append(1, ch);\r
- else\r
- this->insert(static_cast<MYSIZE>(nIdx), 1, ch);\r
-\r
- return GetLength();\r
- }\r
- int Insert(int nIdx, PCMYSTR sz)\r
- {\r
- if ( nIdx >= this->size() )\r
- this->append(sz, sslen(sz));\r
- else\r
- this->insert(static_cast<MYSIZE>(nIdx), sz);\r
-\r
- return GetLength();\r
- }\r
-\r
- bool IsEmpty() const\r
- {\r
- return this->empty();\r
- }\r
-\r
- MYTYPE Left(int nCount) const\r
- {\r
- // Range check the count.\r
-\r
- nCount = SSMAX(0, SSMIN(nCount, static_cast<int>(this->size())));\r
- return this->substr(0, static_cast<MYSIZE>(nCount)); \r
- }\r
-\r
-#ifndef SS_ANSI\r
- bool LoadString(UINT nId)\r
- {\r
- return this->Load(nId);\r
- }\r
-#endif\r
-\r
- void MakeLower()\r
- {\r
- ToLower();\r
- }\r
-\r
- void MakeReverse()\r
- {\r
- std::reverse(this->begin(), this->end());\r
- }\r
-\r
- void MakeUpper()\r
- { \r
- ToUpper();\r
- }\r
-\r
- MYTYPE Mid(int nFirst ) const\r
- {\r
- return Mid(nFirst, size()-nFirst);\r
- }\r
-\r
- MYTYPE Mid(int nFirst, int nCount) const\r
- {\r
- // CString does range checking here. Since we're trying to emulate it,\r
- // we must check too.\r
-\r
- if ( nFirst < 0 )\r
- nFirst = 0;\r
- if ( nCount < 0 )\r
- nCount = 0;\r
-\r
- if ( nFirst + nCount > size() )\r
- nCount = size() - nFirst;\r
-\r
- if ( nFirst > size() )\r
- return MYTYPE();\r
-\r
- ASSERT(nFirst >= 0);\r
- ASSERT(nFirst + nCount <= size());\r
-\r
- return this->substr(static_cast<MYSIZE>(nFirst),\r
- static_cast<MYSIZE>(nCount));\r
- }\r
-\r
- void ReleaseBuffer(int nNewLen=-1)\r
- {\r
- RelBuf(nNewLen);\r
- }\r
-\r
- int Remove(CT ch)\r
- {\r
- MYSIZE nIdx = 0;\r
- int nRemoved = 0;\r
- while ( (nIdx=this->find_first_of(ch)) != MYBASE::npos )\r
- {\r
- this->erase(nIdx, 1);\r
- nRemoved++;\r
- }\r
- return nRemoved;\r
- }\r
-\r
- int Replace(CT chOld, CT chNew)\r
- {\r
- int nReplaced = 0;\r
- for ( MYITER iter=this->begin(); iter != this->end(); iter++ )\r
- {\r
- if ( *iter == chOld )\r
- {\r
- *iter = chNew;\r
- nReplaced++;\r
- }\r
- }\r
- return nReplaced;\r
- }\r
-\r
- int Replace(PCMYSTR szOld, PCMYSTR szNew)\r
- {\r
- int nReplaced = 0;\r
- MYSIZE nIdx = 0;\r
- MYSIZE nOldLen = sslen(szOld);\r
- if ( 0 == nOldLen )\r
- return 0;\r
-\r
- static const CT ch = CT(0);\r
- MYSIZE nNewLen = sslen(szNew);\r
- PCMYSTR szRealNew = szNew == 0 ? &ch : szNew;\r
-\r
- while ( (nIdx=this->find(szOld, nIdx)) != MYBASE::npos )\r
- {\r
- replace(this->begin()+nIdx, this->begin()+nIdx+nOldLen, szRealNew);\r
- nReplaced++;\r
- nIdx += nNewLen;\r
- }\r
- return nReplaced;\r
- }\r
-\r
- int ReverseFind(CT ch) const\r
- {\r
- MYSIZE nIdx = this->find_last_of(ch);\r
- return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);\r
- }\r
-\r
- // ReverseFind overload that's not in CString but might be useful\r
- int ReverseFind(PCMYSTR szFind, MYSIZE pos=MYBASE::npos) const\r
- {\r
- MYSIZE nIdx = this->rfind(0 == szFind ? MYTYPE() : szFind, pos);\r
- return static_cast<int>(MYBASE::npos == nIdx ? -1 : nIdx);\r
- }\r
-\r
- MYTYPE Right(int nCount) const\r
- {\r
- // Range check the count.\r
-\r
- nCount = SSMAX(0, SSMIN(nCount, static_cast<int>(this->size())));\r
- return this->substr(this->size()-static_cast<MYSIZE>(nCount));\r
- }\r
-\r
- void SetAt(int nIndex, CT ch)\r
- {\r
- ASSERT(this->size() > static_cast<MYSIZE>(nIndex));\r
- this->at(static_cast<MYSIZE>(nIndex)) = ch;\r
- }\r
-\r
-#ifndef SS_ANSI\r
- BSTR SetSysString(BSTR* pbstr) const\r
- {\r
- ostring os;\r
- ssasn(os, *this);\r
- if ( !::SysReAllocStringLen(pbstr, os.c_str(), os.length()) )\r
- throw std::runtime_error("out of memory");\r
-\r
- ASSERT(*pbstr != 0);\r
- return *pbstr;\r
- }\r
-#endif\r
-\r
- MYTYPE SpanExcluding(PCMYSTR szCharSet) const\r
- {\r
- MYSIZE pos = this->find_first_of(szCharSet);\r
- return pos == MYBASE::npos ? *this : Left(pos);\r
- }\r
-\r
- MYTYPE SpanIncluding(PCMYSTR szCharSet) const\r
- {\r
- MYSIZE pos = this->find_first_not_of(szCharSet);\r
- return pos == MYBASE::npos ? *this : Left(pos);\r
- }\r
-\r
-#if !defined(UNICODE) && !defined(SS_ANSI)\r
-\r
- // CString's OemToAnsi and AnsiToOem functions are available only in\r
- // Unicode builds. However since we're a template we also need a\r
- // runtime check of CT and a reinterpret_cast to account for the fact\r
- // that CStdStringW gets instantiated even in non-Unicode builds.\r
-\r
- void AnsiToOem()\r
- {\r
- if ( sizeof(CT) == sizeof(char) && !empty() )\r
- {\r
- ::CharToOem(reinterpret_cast<PCSTR>(this->c_str()),\r
- reinterpret_cast<PSTR>(GetBuf()));\r
- }\r
- else\r
- {\r
- ASSERT(false);\r
- }\r
- }\r
-\r
- void OemToAnsi()\r
- {\r
- if ( sizeof(CT) == sizeof(char) && !empty() )\r
- {\r
- ::OemToChar(reinterpret_cast<PCSTR>(this->c_str()),\r
- reinterpret_cast<PSTR>(GetBuf()));\r
- }\r
- else\r
- {\r
- ASSERT(false);\r
- }\r
- }\r
-\r
-#endif\r
- \r
-\r
- // -------------------------------------------------------------------------\r
- // Trim and its variants\r
- // -------------------------------------------------------------------------\r
- MYTYPE& Trim()\r
- {\r
- return TrimLeft().TrimRight();\r
- }\r
-\r
- MYTYPE& TrimLeft()\r
- {\r
- this->erase(this->begin(),\r
- std::find_if(this->begin(), this->end(), NotSpace<CT>()));\r
-\r
- return *this;\r
- }\r
-\r
- MYTYPE& TrimLeft(CT tTrim)\r
- {\r
- this->erase(0, this->find_first_not_of(tTrim));\r
- return *this;\r
- }\r
-\r
- MYTYPE& TrimLeft(PCMYSTR szTrimChars)\r
- {\r
- this->erase(0, this->find_first_not_of(szTrimChars));\r
- return *this;\r
- }\r
-\r
- MYTYPE& TrimRight()\r
- {\r
- // NOTE: When comparing reverse_iterators here (MYRITER), I avoid using\r
- // operator!=. This is because namespace rel_ops also has a template\r
- // operator!= which conflicts with the global operator!= already defined\r
- // for reverse_iterator in the header <utility>.\r
- // Thanks to John James for alerting me to this.\r
-\r
- MYRITER it = std::find_if(this->rbegin(), this->rend(), NotSpace<CT>());\r
- if ( !(this->rend() == it) )\r
- this->erase(this->rend() - it);\r
-\r
- this->erase(!(it == this->rend()) ? this->find_last_of(*it) + 1 : 0);\r
- return *this;\r
- }\r
-\r
- MYTYPE& TrimRight(CT tTrim)\r
- {\r
- MYSIZE nIdx = this->find_last_not_of(tTrim);\r
- this->erase(MYBASE::npos == nIdx ? 0 : ++nIdx);\r
- return *this;\r
- }\r
-\r
- MYTYPE& TrimRight(PCMYSTR szTrimChars)\r
- {\r
- MYSIZE nIdx = this->find_last_not_of(szTrimChars);\r
- this->erase(MYBASE::npos == nIdx ? 0 : ++nIdx);\r
- return *this;\r
- }\r
-\r
- void FreeExtra()\r
- {\r
- MYTYPE mt;\r
- this->swap(mt);\r
- if ( !mt.empty() )\r
- this->assign(mt.c_str(), mt.size());\r
- }\r
-\r
- // I have intentionally not implemented the following CString\r
- // functions. You cannot make them work without taking advantage\r
- // of implementation specific behavior. However if you absolutely\r
- // MUST have them, uncomment out these lines for "sort-of-like"\r
- // their behavior. You're on your own.\r
-\r
-// CT* LockBuffer() { return GetBuf(); }// won't really lock\r
-// void UnlockBuffer(); { } // why have UnlockBuffer w/o LockBuffer?\r
-\r
- // Array-indexing operators. Required because we defined an implicit cast\r
- // to operator const CT* (Thanks to Julian Selman for pointing this out)\r
- CT& operator[](int nIdx)\r
- {\r
- return MYBASE::operator[](static_cast<MYSIZE>(nIdx));\r
- }\r
-\r
- const CT& operator[](int nIdx) const\r
- {\r
- return MYBASE::operator[](static_cast<MYSIZE>(nIdx));\r
- }\r
-\r
- CT& operator[](unsigned int nIdx)\r
- {\r
- return MYBASE::operator[](static_cast<MYSIZE>(nIdx));\r
- }\r
-\r
- const CT& operator[](unsigned int nIdx) const\r
- {\r
- return MYBASE::operator[](static_cast<MYSIZE>(nIdx));\r
- }\r
-\r
-#ifndef SS_NO_IMPLICIT_CAST\r
- operator const CT*() const\r
- {\r
- return this->c_str();\r
- }\r
-#endif\r
-\r
- // IStream related functions. Useful in IPersistStream implementations\r
-\r
-#ifdef SS_INC_COMDEF\r
-\r
- // struct SSSHDR - useful for non Std C++ persistence schemes.\r
- typedef struct SSSHDR\r
- {\r
- BYTE byCtrl;\r
- ULONG nChars;\r
- } SSSHDR; // as in "Standard String Stream Header"\r
-\r
- #define SSSO_UNICODE 0x01 // the string is a wide string\r
- #define SSSO_COMPRESS 0x02 // the string is compressed\r
-\r
- // -------------------------------------------------------------------------\r
- // FUNCTION: StreamSize\r
- // REMARKS:\r
- // Returns how many bytes it will take to StreamSave() this CStdString\r
- // object to an IStream.\r
- // -------------------------------------------------------------------------\r
- ULONG StreamSize() const\r
- {\r
- // Control header plus string\r
- ASSERT(this->size()*sizeof(CT) < 0xffffffffUL - sizeof(SSSHDR));\r
- return (this->size() * sizeof(CT)) + sizeof(SSSHDR);\r
- }\r
-\r
- // -------------------------------------------------------------------------\r
- // FUNCTION: StreamSave\r
- // REMARKS:\r
- // Saves this CStdString object to a COM IStream.\r
- // -------------------------------------------------------------------------\r
- HRESULT StreamSave(IStream* pStream) const\r
- {\r
- ASSERT(size()*sizeof(CT) < 0xffffffffUL - sizeof(SSSHDR));\r
- HRESULT hr = E_FAIL;\r
- ASSERT(pStream != 0);\r
- SSSHDR hdr;\r
- hdr.byCtrl = sizeof(CT) == 2 ? SSSO_UNICODE : 0;\r
- hdr.nChars = this->size();\r
-\r
-\r
- if ( FAILED(hr=pStream->Write(&hdr, sizeof(SSSHDR), 0)) )\r
- TRACE(_T("StreamSave: Cannot write control header, ERR=0x%X\n"),hr);\r
- else if ( empty() )\r
- ; // nothing to write\r
- else if ( FAILED(hr=pStream->Write(this->c_str(), this->size()*sizeof(CT), 0)) )\r
- TRACE(_T("StreamSave: Cannot write string to stream 0x%X\n"), hr);\r
-\r
- return hr;\r
- }\r
-\r
-\r
- // -------------------------------------------------------------------------\r
- // FUNCTION: StreamLoad\r
- // REMARKS:\r
- // This method loads the object from an IStream.\r
- // -------------------------------------------------------------------------\r
- HRESULT StreamLoad(IStream* pStream)\r
- {\r
- ASSERT(pStream != 0);\r
- SSSHDR hdr;\r
- HRESULT hr = E_FAIL;\r
-\r
- if ( FAILED(hr=pStream->Read(&hdr, sizeof(SSSHDR), 0)) )\r
- {\r
- TRACE(_T("StreamLoad: Cant read control header, ERR=0x%X\n"), hr);\r
- }\r
- else if ( hdr.nChars > 0 )\r
- {\r
- ULONG nRead = 0;\r
- PMYSTR pMyBuf = BufferSet(hdr.nChars);\r
-\r
- // If our character size matches the character size of the string\r
- // we're trying to read, then we can read it directly into our\r
- // buffer. Otherwise, we have to read into an intermediate buffer\r
- // and convert.\r
- \r
- if ( (hdr.byCtrl & SSSO_UNICODE) != 0 )\r
- {\r
- ULONG nBytes = hdr.nChars * sizeof(wchar_t);\r
- if ( sizeof(CT) == sizeof(wchar_t) )\r
- {\r
- if ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) )\r
- TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);\r
- }\r
- else\r
- { \r
- PWSTR pBufW = reinterpret_cast<PWSTR>(_alloca((nBytes)+1));\r
- if ( FAILED(hr=pStream->Read(pBufW, nBytes, &nRead)) )\r
- TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);\r
- else\r
- sscpy(pMyBuf, pBufW, hdr.nChars);\r
- }\r
- }\r
- else\r
- {\r
- ULONG nBytes = hdr.nChars * sizeof(char);\r
- if ( sizeof(CT) == sizeof(char) )\r
- {\r
- if ( FAILED(hr=pStream->Read(pMyBuf, nBytes, &nRead)) )\r
- TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);\r
- }\r
- else\r
- {\r
- PSTR pBufA = reinterpret_cast<PSTR>(_alloca(nBytes));\r
- if ( FAILED(hr=pStream->Read(pBufA, hdr.nChars, &nRead)) )\r
- TRACE(_T("StreamLoad: Cannot read string: 0x%X\n"), hr);\r
- else\r
- sscpy(pMyBuf, pBufA, hdr.nChars);\r
- }\r
- }\r
- }\r
- else\r
- {\r
- this->erase();\r
- }\r
- return hr;\r
- }\r
-#endif // #ifdef SS_INC_COMDEF\r
-\r
-#ifndef SS_ANSI\r
-\r
- // SetResourceHandle/GetResourceHandle. In MFC builds, these map directly\r
- // to AfxSetResourceHandle and AfxGetResourceHandle. In non-MFC builds they\r
- // point to a single static HINST so that those who call the member\r
- // functions that take resource IDs can provide an alternate HINST of a DLL\r
- // to search. This is not exactly the list of HMODULES that MFC provides\r
- // but it's better than nothing.\r
-\r
-#ifdef _MFC_VER\r
- static void SetResourceHandle(HMODULE hNew)\r
- {\r
- AfxSetResourceHandle(hNew);\r
- }\r
- static HMODULE GetResourceHandle()\r
- {\r
- return AfxGetResourceHandle();\r
- }\r
-#else\r
- static void SetResourceHandle(HMODULE hNew)\r
- {\r
- SSResourceHandle() = hNew;\r
- }\r
- static HMODULE GetResourceHandle()\r
- {\r
- return SSResourceHandle();\r
- }\r
-#endif\r
-\r
-\r
- template<typename CT2>\r
- MYTYPE operator+(const CStdStr<CT2>& s2)\r
- {\r
- MYTYPE strRet(SSREF(*this));\r
- strRet += s2.c_str();\r
- return strRet;\r
- }\r
-\r
-\r
-#endif\r
-};\r
-\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// CStdStr friend addition functions defined as inline\r
-// -----------------------------------------------------------------------------\r
-template<typename CT>\r
-inline\r
-CStdStr<CT> operator+(const CStdStr<CT>& str1, const CStdStr<CT>& str2)\r
-{\r
- CStdStr<CT> strRet(SSREF(str1));\r
- strRet.append(str2);\r
- return strRet;\r
-}\r
-\r
-template<typename CT> \r
-inline\r
-CStdStr<CT> operator+(const CStdStr<CT>& str, CT t)\r
-{\r
- // this particular overload is needed for disabling reference counting\r
- // though it's only an issue from line 1 to line 2\r
-\r
- CStdStr<CT> strRet(SSREF(str)); // 1\r
- strRet.append(1, t); // 2\r
- return strRet;\r
-}\r
-\r
-template<typename CT>\r
-inline\r
-CStdStr<CT> operator+(const CStdStr<CT>& str, PCSTR pA)\r
-{\r
- return CStdStr<CT>(str) + CStdStr<CT>(pA);\r
-}\r
-\r
-template<typename CT>\r
-inline\r
-CStdStr<CT> operator+(PCSTR pA, const CStdStr<CT>& str)\r
-{\r
- CStdStr<CT> strRet(pA);\r
- strRet.append(str);\r
- return strRet;\r
-}\r
-\r
-template<typename CT>\r
-inline\r
-CStdStr<CT> operator+(const CStdStr<CT>& str, PCWSTR pW)\r
-{ \r
- return CStdStr<CT>(SSREF(str)) + CStdStr<CT>(pW);\r
-}\r
-\r
-template<typename CT>\r
-inline\r
-CStdStr<CT> operator+(PCWSTR pW, const CStdStr<CT>& str)\r
-{\r
- CStdStr<CT> strRet(pW);\r
- strRet.append(str);\r
- return strRet;\r
-}\r
-\r
-#ifdef SS_INC_COMDEF\r
- template<typename CT>\r
- inline\r
- CStdStr<CT> operator+(const _bstr_t& bstr, const CStdStr<CT>& str)\r
- {\r
- return static_cast<const CT*>(bstr) + str;\r
- }\r
-\r
- template<typename CT>\r
- inline\r
- CStdStr<CT> operator+(const CStdStr<CT>& str, const _bstr_t& bstr)\r
- {\r
- return str + static_cast<const CT*>(bstr);\r
- }\r
-#endif\r
-\r
-// -----------------------------------------------------------------------------\r
-// HOW TO EXPORT CSTDSTRING FROM A DLL\r
-//\r
-// If you want to export CStdStringA and CStdStringW from a DLL, then all you\r
-// need to\r
-// 1. make sure that all components link to the same DLL version\r
-// of the CRT (not the static one).\r
-// 2. Uncomment the 3 lines of code below\r
-// 3. #define 2 macros per the instructions in MS KnowledgeBase\r
-// article Q168958. The macros are:\r
-//\r
-// MACRO DEFINTION WHEN EXPORTING DEFINITION WHEN IMPORTING\r
-// ----- ------------------------ -------------------------\r
-// SSDLLEXP (nothing, just #define it) extern\r
-// SSDLLSPEC __declspec(dllexport) __declspec(dllimport)\r
-//\r
-// Note that these macros must be available to ALL clients who want to \r
-// link to the DLL and use the class. If they \r
-// -----------------------------------------------------------------------------\r
-//#pragma warning(disable:4231) // non-standard extension ("extern template")\r
-// SSDLLEXP template class SSDLLSPEC CStdStr<char>;\r
-// SSDLLEXP template class SSDLLSPEC CStdStr<wchar_t>;\r
-\r
-// =============================================================================\r
-// END OF CStdStr INLINE FUNCTION DEFINITIONS\r
-// =============================================================================\r
-\r
-// Now typedef our class names based upon this humongous template\r
-\r
-typedef CStdStr<char> CStdStringA; // a better std::string\r
-typedef CStdStr<wchar_t> CStdStringW; // a better std::wstring\r
-typedef CStdStr<OLECHAR> CStdStringO; // almost always CStdStringW\r
-\r
-\r
-// New-style format function is a template\r
-\r
-#ifdef SS_SAFE_FORMAT\r
-\r
-template<>\r
-struct FmtArg<CStdStringA>\r
-{\r
- explicit FmtArg(const CStdStringA& arg) : a_(arg) {}\r
- PCSTR Val() const { return a_.c_str(); }\r
- const CStdStringA& a_;\r
-private:\r
- FmtArg<CStdStringA>& operator=(const FmtArg<CStdStringA>&) { return *this; }\r
-};\r
-template<>\r
-struct FmtArg<CStdStringW>\r
-{\r
- explicit FmtArg(const CStdStringW& arg) : a_(arg) {}\r
- PCWSTR Val() const { return a_.c_str(); }\r
- const CStdStringW& a_;\r
-private:\r
- FmtArg<CStdStringW>& operator=(const FmtArg<CStdStringW>&) { return *this; }\r
-};\r
-\r
-template<>\r
-struct FmtArg<std::string>\r
-{\r
- explicit FmtArg(const std::string& arg) : a_(arg) {}\r
- PCSTR Val() const { return a_.c_str(); }\r
- const std::string& a_;\r
-private:\r
- FmtArg<std::string>& operator=(const FmtArg<std::string>&) { return *this; }\r
-};\r
-template<>\r
-struct FmtArg<std::wstring>\r
-{\r
- explicit FmtArg(const std::wstring& arg) : a_(arg) {}\r
- PCWSTR Val() const { return a_.c_str(); }\r
- const std::wstring& a_;\r
-private:\r
- FmtArg<std::wstring>& operator=(const FmtArg<std::wstring>&) {return *this;}\r
-};\r
-#endif // #ifdef SS_SAFEFORMAT\r
-\r
-#ifndef SS_ANSI\r
- // SSResourceHandle: our MFC-like resource handle\r
- inline HMODULE& SSResourceHandle()\r
- {\r
- static HMODULE hModuleSS = GetModuleHandle(0);\r
- return hModuleSS;\r
- }\r
-#endif\r
-\r
-\r
-\r
-\r
-// In MFC builds, define some global serialization operators\r
-// Special operators that allow us to serialize CStdStrings to CArchives.\r
-// Note that we use an intermediate CString object in order to ensure that\r
-// we use the exact same format.\r
-\r
-#ifdef _MFC_VER\r
- inline CArchive& AFXAPI operator<<(CArchive& ar, const CStdStringA& strA)\r
- {\r
- CString strTemp = strA;\r
- return ar << strTemp;\r
- }\r
- inline CArchive& AFXAPI operator<<(CArchive& ar, const CStdStringW& strW)\r
- {\r
- CString strTemp = strW;\r
- return ar << strTemp;\r
- }\r
-\r
- inline CArchive& AFXAPI operator>>(CArchive& ar, CStdStringA& strA)\r
- {\r
- CString strTemp;\r
- ar >> strTemp;\r
- strA = strTemp;\r
- return ar;\r
- }\r
- inline CArchive& AFXAPI operator>>(CArchive& ar, CStdStringW& strW)\r
- {\r
- CString strTemp;\r
- ar >> strTemp;\r
- strW = strTemp;\r
- return ar;\r
- }\r
-#endif // #ifdef _MFC_VER -- (i.e. is this MFC?)\r
-\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// GLOBAL FUNCTION: WUFormat\r
-// CStdStringA WUFormat(UINT nId, ...);\r
-// CStdStringA WUFormat(PCSTR szFormat, ...);\r
-//\r
-// REMARKS:\r
-// This function allows the caller for format and return a CStdStringA\r
-// object with a single line of code.\r
-// -----------------------------------------------------------------------------\r
-#ifdef SS_ANSI\r
-#else\r
-\r
- inline CStdStringA WUFormatA(UINT nId, ...)\r
- {\r
- va_list argList;\r
- va_start(argList, nId);\r
-\r
- CStdStringA strFmt;\r
- CStdStringA strOut;\r
- if ( strFmt.Load(nId) )\r
- strOut.FormatV(strFmt, argList);\r
-\r
- va_end(argList);\r
- return strOut;\r
- }\r
- inline CStdStringA WUFormatA(PCSTR szFormat, ...)\r
- {\r
- va_list argList;\r
- va_start(argList, szFormat);\r
- CStdStringA strOut;\r
- strOut.FormatV(szFormat, argList);\r
- va_end(argList);\r
- return strOut;\r
- }\r
-\r
- inline CStdStringW WUFormatW(UINT nId, ...)\r
- {\r
- va_list argList;\r
- va_start(argList, nId);\r
-\r
- CStdStringW strFmt;\r
- CStdStringW strOut;\r
- if ( strFmt.Load(nId) )\r
- strOut.FormatV(strFmt, argList);\r
-\r
- va_end(argList);\r
- return strOut;\r
- }\r
- inline CStdStringW WUFormatW(PCWSTR szwFormat, ...)\r
- {\r
- va_list argList;\r
- va_start(argList, szwFormat);\r
- CStdStringW strOut;\r
- strOut.FormatV(szwFormat, argList);\r
- va_end(argList);\r
- return strOut;\r
- }\r
-#endif // #ifdef SS_ANSI\r
-\r
-#ifdef SS_WIN32\r
- // -------------------------------------------------------------------------\r
- // FUNCTION: WUSysMessage\r
- // CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID);\r
- // CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID);\r
- // \r
- // DESCRIPTION:\r
- // This function simplifies the process of obtaining a string equivalent\r
- // of a system error code returned from GetLastError(). You simply\r
- // supply the value returned by GetLastError() to this function and the\r
- // corresponding system string is returned in the form of a CStdStringA.\r
- //\r
- // PARAMETERS: \r
- // dwError - a DWORD value representing the error code to be translated\r
- // dwLangId - the language id to use. defaults to english.\r
- //\r
- // RETURN VALUE: \r
- // a CStdStringA equivalent of the error code. Currently, this function\r
- // only returns either English of the system default language strings. \r
- // -------------------------------------------------------------------------\r
- #define SS_DEFLANGID MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)\r
- inline CStdStringA WUSysMessageA(DWORD dwError, DWORD dwLangId=SS_DEFLANGID)\r
- {\r
- CHAR szBuf[512];\r
-\r
- if ( 0 != ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,\r
- dwLangId, szBuf, 511, NULL) )\r
- return WUFormatA("%s (0x%X)", szBuf, dwError);\r
- else\r
- return WUFormatA("Unknown error (0x%X)", dwError);\r
- }\r
- inline CStdStringW WUSysMessageW(DWORD dwError, DWORD dwLangId=SS_DEFLANGID)\r
- {\r
- WCHAR szBuf[512];\r
-\r
- if ( 0 != ::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,\r
- dwLangId, szBuf, 511, NULL) )\r
- return WUFormatW(L"%s (0x%X)", szBuf, dwError);\r
- else\r
- return WUFormatW(L"Unknown error (0x%X)", dwError);\r
- }\r
-#endif\r
-\r
-// Define TCHAR based friendly names for some of these functions\r
-\r
-#ifdef UNICODE\r
- #define CStdString CStdStringW\r
- #define WUSysMessage WUSysMessageW\r
- #define WUFormat WUFormatW\r
-#else\r
- #define CStdString CStdStringA\r
- #define WUSysMessage WUSysMessageA\r
- #define WUFormat WUFormatA\r
-#endif\r
-\r
-// ...and some shorter names for the space-efficient\r
-\r
-#define WUSysMsg WUSysMessage\r
-#define WUSysMsgA WUSysMessageA\r
-#define WUSysMsgW WUSysMessageW\r
-#define WUFmtA WUFormatA\r
-#define WUFmtW WUFormatW\r
-#define WUFmt WUFormat\r
-#define WULastErrMsg() WUSysMessage(::GetLastError())\r
-#define WULastErrMsgA() WUSysMessageA(::GetLastError())\r
-#define WULastErrMsgW() WUSysMessageW(::GetLastError())\r
-\r
-\r
-// -----------------------------------------------------------------------------\r
-// FUNCTIONAL COMPARATORS:\r
-// REMARKS:\r
-// These structs are derived from the std::binary_function template. They\r
-// give us functional classes (which may be used in Standard C++ Library\r
-// collections and algorithms) that perform case-insensitive comparisons of\r
-// CStdString objects. This is useful for maps in which the key may be the\r
-// proper string but in the wrong case.\r
-// -----------------------------------------------------------------------------\r
-#define StdStringLessNoCaseW SSLNCW // avoid VC compiler warning 4786\r
-#define StdStringEqualsNoCaseW SSENCW \r
-#define StdStringLessNoCaseA SSLNCA \r
-#define StdStringEqualsNoCaseA SSENCA \r
-\r
-#ifdef UNICODE\r
- #define StdStringLessNoCase SSLNCW \r
- #define StdStringEqualsNoCase SSENCW \r
-#else\r
- #define StdStringLessNoCase SSLNCA \r
- #define StdStringEqualsNoCase SSENCA \r
-#endif\r
-\r
-struct StdStringLessNoCaseW\r
- : std::binary_function<CStdStringW, CStdStringW, bool>\r
-{\r
- inline\r
- bool operator()(const CStdStringW& sLeft, const CStdStringW& sRight) const\r
- { return ssicmp(sLeft.c_str(), sRight.c_str()) < 0; }\r
-};\r
-struct StdStringEqualsNoCaseW\r
- : std::binary_function<CStdStringW, CStdStringW, bool>\r
-{\r
- inline\r
- bool operator()(const CStdStringW& sLeft, const CStdStringW& sRight) const\r
- { return ssicmp(sLeft.c_str(), sRight.c_str()) == 0; }\r
-};\r
-struct StdStringLessNoCaseA\r
- : std::binary_function<CStdStringA, CStdStringA, bool>\r
-{\r
- inline\r
- bool operator()(const CStdStringA& sLeft, const CStdStringA& sRight) const\r
- { return ssicmp(sLeft.c_str(), sRight.c_str()) < 0; }\r
-};\r
-struct StdStringEqualsNoCaseA\r
- : std::binary_function<CStdStringA, CStdStringA, bool>\r
-{\r
- inline\r
- bool operator()(const CStdStringA& sLeft, const CStdStringA& sRight) const\r
- { return ssicmp(sLeft.c_str(), sRight.c_str()) == 0; }\r
-};\r
-\r
-// If we had to define our own version of TRACE above, get rid of it now\r
-\r
-#ifdef TRACE_DEFINED_HERE\r
- #undef TRACE\r
- #undef TRACE_DEFINED_HERE\r
-#endif\r
-\r
-\r
-// These std::swap specializations come courtesy of Mike Crusader. \r
-\r
-//namespace std\r
-//{\r
-// inline void swap(CStdStringA& s1, CStdStringA& s2) throw()\r
-// {\r
-// s1.swap(s2);\r
-// }\r
-// template<>\r
-// inline void swap(CStdStringW& s1, CStdStringW& s2) throw()\r
-// {\r
-// s1.swap(s2);\r
-// }\r
-//}\r
-\r
-// Turn back on any Borland warnings we turned off.\r
-\r
-#ifdef __BORLANDC__\r
- #pragma option pop // Turn back on inline function warnings\r
-// #pragma warn +inl // Turn back on inline function warnings\r
-#endif\r
-\r
-#endif // #ifndef STDSTRING_H
\ No newline at end of file