|
To be blunt, I really have no plans to do this.
You have no idea how many countless hours (over the past 7 years) I have spent on this single class, updating it, rewriting it, bug-fixing it, attempting to make it work on every platform imaginable, scrutinizing the Standards docs, etc. This was complicated by the fact that I usually only have 1 platform available to test it on (Windows), so much of my testing was done by emailing other people and having THEM test changes for me.
Every time I make a single change or "improvement" and get it to work on Windows, I get a dozen emails from people who work on other platforms where my changes have broken the compilation. Grrrr...
I've had this question a few times. What I usually do is recommend that people use John Maddocks Regex library that is a part of the Boost library (http://www.boost.org). This is designed to work with basic_string<> and since a CStdString is a basic_string it should work fine.
Sorry. You know the code is free so you are welcome to graft on any regex package you like. I just don't want to break what I finally seem to have working...
-Joe
|
|
|
|
|
Joe O`Leary wrote:
Sorry. You know the code is free so you are welcome to graft on any regex package you like. I just don't want to break what I finally seem to have working...
No need to apologize. I may add it myself (using the Boost Regex as has been suggested) and send you the updates. You might want to #ifdef them and let others try them at their own risk.
Good class, thanks for providing it!
|
|
|
|
|
I just wanted to comment on this:
std::string* pstr = new CStdStringA("Hi");
delete pstr;
It is not undefined - the destructor of std::string will be called, and CStdStringA destructor will not. That may or may not be a problem depending on imlementation of CStdStringA (I haven't really looked at your code )
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Actually yes, it really is undefined. Go check the ISO C++ Standard if you don't believe me.
And since it is undefined, if the vendor of your C++ implementation wanted, they could validly terminate the application as a result of doing what I have shown in the example.
The good news is that
a)Visual C++ (and most implementations, I'm guessing) will not crash your even if you do something like this.
and
b)CStdString is designed specifically to have no member data and to require not special cleanup of any kind.
What that means is that if you do this with Visual C++ (and again probably with most implementations of the runtime) you won't have any problems. But since it is poor programming practice, nobody should do it.
-Joe
|
|
|
|
|
Joe O`Leary wrote:
Actually yes, it really is undefined. Go check the ISO C++ Standard if you don't believe me.
Hmmm, you are right:
5.3.5.1:
If the static type of the operand is different from its dynamic type, the static type shall be a base class of the operand's dynamic type and the static type shall have a virtual destructor or the behavior is undefined
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
How can I see the CStdString strings in VC6 watches and hover bubbles?
Thanks, Pete
|
|
|
|
|
I found that if I edit C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin\autoexp.dat and change
std::basic_string<*>=<_Ptr>
to
std::basic_string<*>=<c_str(), su>
it works at least for Unicode. I am sure this needs more refinement, e.g. I need to adjust this to handle both MBCS and Unicode.
Pete
|
|
|
|
|
The c_str caused some unusual behavior. Using <_Ptr, su> works better.
|
|
|
|
|
Hi Pete,
So sorry to take so long to respond to you on this.
Yes, autoexp.dat is the key, as you have already figured out. You don't want to be calling functions (like c_str()) in it -- in fact I wasn't even aware that you could call functions from autoexp.dat. Anyway, you just need to examine the member variables and have it evaluate the version of the member char* (or wchar_t* in the case of wstring).
However, if you ever get the Dinkumware update for VC6 (the much more modern implementation of the Standard C++ Library that they sell) it becomes much more complicated to do this. Because in that case, the member char*/wchar_t* is either a fixed length buffer OR a pointer to a dynamically allocated buffer, depending on the length of the string. I have no idea how to make autoexp.dat do any if/then/else processing when determining what to display.
Anyway, I'm sorry I didn't help you out on this fast enough.
-Joe
|
|
|
|
|
Hi Joe, Microsoft Knowledge Base Article - 326616, "BUG: Cannot Display std::string and std::wstring Variables Correctly In Visual C++ .NET Debugger", might have the answer you are looking for:
http://support.microsoft.com/default.aspx?scid=kb;en-us;326616
From that...
In the Autoexp.dat file, locate the following lines:
std::basic_string<char,std::char_traits<char>,std::allocator<char> >=<_Bx._Buf>
std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >=<_Bx._Ptr>
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Bx._Ptr>
Replace with the following lines:
std::basic_string<char,std::char_traits<char>,std::allocator<char> >=
_Buf=<_Bx._Buf> _Ptr= <_Bx._Ptr>
std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >=_Buf=<_Bx._Buf> _Ptr= <_Bx._Ptr>
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Bx._Buf> _Ptr= <_Bx._Ptr>
Pete
|
|
|
|
|
Will this work with VC6 too ?
|
|
|
|
|
I am using VC6 without the upgrade Joe mentioned. This is my latest version of those templates in autoexp.dat:
std::basic_string<char,std::char_traits<char>,std::allocator<char> >=<_Ptr>
std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >=<_Ptr,su>
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Ptr,su>
That seems to work.
Pete
|
|
|
|
|
I finally found the solution.
I use the STLPORT library instead of the STL shipped with VC6
Here is my solution:
_STL::basic_string<*>=<_M_start>
|
|
|
|
|
like these while compiling looks like any MFC
using project:
<br />
c:\...\stdstring.h(2702) : warning C4786: '?Format@?$CStdStr@D@@QAEXIABVtemplate-parameter-CAB@ABVtemplate-parameter-CAC@ABVtemplate-parameter-CAD@ABVtemplate-parameter-CAE@ABVtemplate-parameter-CAF@ABVtemplate-paramete<br />
r-CAG@ABVtemplate-parameter-CAH@ABVtemplate-parameter-CAI@ABVtemplate-parameter-CAJ@ABVtemplate-parameter-CAK@ABVtemplate-parameter-CAL@ABVtemplate-parameter-CAM@ABVtemplate-parameter-CAN@ABVtemplate-parameter-CAO@ABVtemplate-parameter-CAP@@Z' : identifier was truncated to '255' characters in the browser information<br />
<br />
<br />
c:\mvs\vc98\include\xlocale(287) : warning C4100: '_State' : unreferenced formal parameter<br />
c:\mvs\vc98\include\xlocale(289) : while compiling class-template member function 'int __thiscall std::codecvt<char,char,int>::do_length(int &,const char *,const char *,unsigned int) const'<br />
<br />
<br />
c:\mvs\vc98\include\xlocale(289) : warning C4018: '<' : signed/unsigned mismatch<br />
c:\mvs\vc98\include\xlocale(289) : while compiling class-template member function 'int __thiscall std::codecvt<char,char,int>::do_length(int &,const char *,const char *,unsigned int) const'<br />
<br />
<br />
c:\mvs\vc98\include\xlocnum(179) : warning C4146: unary minus operator applied to unsigned type, result still unsigned<br />
c:\mvs\vc98\include\xlocnum(168) : while compiling class-template member function 'class std::istreambuf_iterator<unsigned short,struct std::char_traits<unsigned short> > __thiscall std::num_get<unsigned short,class std::istreambuf_iterator<<br />
<br />
Compiling a project that is not using MFC looks fine.
Please help!
|
|
|
|
|
Hi,
Well let's be sure you have the very latest version of the code before we panic. The version that is (or was) on CodeProject was years out of date. I've sent and updated version (yesterday) to CodeProject but I don't know if it's up yet. You can always the latest version here:
http://home.earthlink.net/~jmoleary/code/StdString.zip
Try that and see what it tells you.
-Joe
|
|
|
|
|
That's exactly what I'm using.
I didn't mention before - this is with VC 6.
I figured that the fist warning I listed will go away if I disable "Generate Browse info" in project settings. Still would be nice to have that on.
The others are still there. I get like around 1200 warnings
|
|
|
|
|
Can you send me a zipped-up VC6 project (without the .obj files or any of that) that generates all the warnings? I'll take hit home tonight and try it out (I don't have VC6 at work) and get back to you here.
I'm able to build this code with VC6 with zero warnings so I'm a little surprised you're having so much trouble. But if you can send me something, I'll figure it out.
My email address is in the StdString.h header file.
-Joe
|
|
|
|
|
E-Mailed. Thanks a lot for all the attention!
|
|
|
|
|
I've already talked to "inner" via email but just to post officially here, the warnings he listed are actually ALL caused by the VC6 implementation of the Standard C++ Library. It was a poor implementation and Dinkumware got rid of all these warnings in their next release.
In the meantime, those of you who have VC6, you'll need to #pragma the warnings away. Sorry. I didn't put the #pragmas in the StdString.h header because a) the warnings are harmless and b)I prefer to leave the choice up to the person using the code since their caused by code that's completely out of my control (Dinkumware's VC6 C++ Library).
I generally place the #pragmas in my precompiled header file.
-Joe
|
|
|
|
|
In VS 7.0 only one level 4 warning is displayed when compiling this class, with 'Detect 64 bit Portability issues' turned off. I've modified the class below to remove it:
template<typename ct="">
struct NotSpace : public std::unary_function<ct, bool="">
{
// DINKUMWARE BUG:
// Note -- using std::isspace in a COM DLL gives us access violations
// because it causes the dynamic addition of a function to be called
// when the library shuts down. Unfortunately the list is maintained
// in DLL memory but the function is in static memory. So the COM DLL
// goes away along with the function that was supposed to be called,
// and then later when the DLL CRT shuts down it unloads the list and
// tries to call the long-gone function.
// This is DinkumWare's implementation problem. If you encounter this
// problem, you may replace the calls here with good old isspace() and
// iswspace() from the CRT unless they specify SS_ANSI
const std::locale loc;
NotSpace(const std::locale& locArg=std::locale()) : loc(locArg) {}
bool operator() (CT t) const { return !std::isspace(t, loc); }
private:
// Private copy assignment resolve the C4512 warning.
const NotSpace &operator=(const NotSpace&); // Added line
};
|
|
|
|
|
It surely should be interesting and useful a CString-clone not using Microsoft C++ ...
So I test to compile Borland Builder C++, and it gives :
==========================================================
Borland C++ 5.6 for Win32 Copyright (c) 1993, 2002 Borland
.\TestString.cpp:
Error E2451 .\StdString.h 442: Undefined symbol 'mbstate_t'
Error E2451 .\StdString.h 463: Undefined symbol 'result' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2379 .\StdString.h 463: Statement missing ; in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 465: Undefined symbol 'state_type' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2379 .\StdString.h 465: Statement missing ; in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 466: Undefined symbol 'res' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2316 .\StdString.h 466: 'in' is not a member of 'SSCodeCvt' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 466: Undefined symbol 'st' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 469: Undefined symbol 'ok' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 486: Undefined symbol 'result' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2379 .\StdString.h 486: Statement missing ; in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2451 .\StdString.h 488: Undefined symbol 'state_type' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2379 .\StdString.h 488: Statement missing ; in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2451 .\StdString.h 489: Undefined symbol 'res' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2316 .\StdString.h 489: 'out' is not a member of 'SSCodeCvt' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2451 .\StdString.h 489: Undefined symbol 'st' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2451 .\StdString.h 492: Undefined symbol 'ok' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2034 .\StdString.h 1111: Cannot convert 'unsigned int' to 'const wchar_t *' in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Error E2342 .\StdString.h 1111: Type mismatch in parameter '__format' (wanted 'const wchar_t *', got 'unsigned int') in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Error E2034 .\StdString.h 1111: Cannot convert 'const wchar_t *' to 'void *' in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Error E2342 .\StdString.h 1111: Type mismatch in parameter '__arglist' (wanted 'void *', got 'const wchar_t *') in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Error E2227 .\StdString.h 1111: Extra parameter in call to vswprintf(wchar_t *,const wchar_t *,void *) in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Warning W8058 C:\BORLAND\include\stlport/locale 150: Cannot create pre-compiled header: initialized data in header
Error E2268 .\TestString.cpp 15: Call to undefined function '_bstr_t' in function main(int,char * *)
Error E2268 .\TestString.cpp 26: Call to undefined function '_ASSERTE' in function main(int,char * *)
Error E2451 .\TestString.cpp 56: Undefined symbol 'SetResourceHandle' in function main(int,char * *)
Error E2228 .\TestString.cpp 56: Too many error or warning messages in function main(int,char * *)
*** 26 errors in Compile ***
==========================================================
I think there are more errors ...
How It can be handled ?
Maybe solving for GCC (g++) it could run on BBuilder.
Thanks in advance
Miguel PS
|
|
|
|
|
You may want to try Str Library at http://www.utilitycode.com/str - it does support your scenario
It does work with Borland C++ Builder. By the way, porting code written for Visual C++ to BCB is not trivial - the compilers are quite different
|
|
|
|
|
First lets make sure you have the very latest version. You may always grab that here
http://home.earthlink.net/~jmoleary/code/StdString.zip
Please grab that and try again. I know that my code has successfully built on Borland C++ Builder in the past.
-Joe
p.s. I apologize for taking so long to respond to this. I must have missed the email notification. I only became aware of it after the first response to your question.
|
|
|
|
|
still the same problem (with the latest version too). I think you missed some library however i dont know which. Please help.
When you do things right people wont be sure you have done anything
|
|
|
|
|
Not sure how to proceed with this. Taking a look at the very first error in the message that 'miguelps' provided, I'm confused. It complains about 'mbstate_t' not being a known type. Well 'mbstate_t" is a pretty basic type of the Standard C++ Library. I know I've included the required files. Perhaps there is a namespace issue. Something is fundamentally wrong here but, lacking Borland C++, I don't know how to determine it. My best guess is that the version of the Standard C++ Library that comes with your compiler is not up-to-date. Can you get an update from Borland?
Barring that, can you try the latest GCC?
-Joe
|
|
|
|
|