 |
|
 |
i want to reload the operator >> in this string class, but how can i avoid buffer overrun?
|
|
|
|
 |
|
 |
Your class is very usefull. I used it in a number of projects, when I couldn't use MFC.
It was great!
But I didn't found some useful methods from MFC CString (trimming with a character set, FormatV, etc). I also found a bug in Format method. When the result buffer was equal to the allocated one, then no terminating null character is added.
There is also impossible to support mixed Unicode/Non-unicode code. It would be great if we could use CCOMString, CCOMStringA, CCOMStringW together!
Thanks a lot for your code!
An author of the article "Task Manager Extension 2.0"
|
|
|
|
 |
|
 |
Here you can get modified version of CCOMString class.
http://reinhard.at.tut.by/files/String_new.zip[^]
This is the code prom my project. It was modified from the very old
version of CCOMString, but it is very common to yours.
We did the same things! But mine has no bug with Format() and has some
more useful CString methods.
Merge these classes at your own!
I hope that Paul will update his CCOMString.
P.S. You've also got my five.
|
|
|
|
 |
|
 |
I tried add a loop in demo application and i see memory usage increased gradually. I added Sleep() for each loop but the memory usage still increased. Any suggestion to remove leaks?
Nghi~a nghiado@psv.com.vn
|
|
|
|
 |
|
 |
I think we need to call Empty() and free(m_pszString) in CCOMString::~CCOMString()
CCOMString::~CCOMString()
{
Empty();
free(m_pszString);
}
|
|
|
|
 |
|
 |
Hi there,
I tried to compile the demo-source with VS.net 2003, but the compiler says:
error C2558: class 'CCOMString' : no copy constructor available or copy constructor is declared 'explicit'
But in the source, I think, there is a copy-constructor and the possibility to make assignements with operator=...
Is there any up to date version of this files with the many updates/bugfixing discussed in this threads here? The page of the author doesn't exist anymore, i think.
best regards,
Bjoern M. Albrecht
|
|
|
|
 |
|
 |
Modify the copy constructor like this:
CCOMString::CCOMString(const CCOMString& str)
{
m_pszString = NULL;
int nLen = str.GetLength();
AllocString(nLen);
_tcsncpy(m_pszString, (LPCTSTR) str, nLen);
}
Just add the "const" declaration to the argument specification. I did not test it yet, but it helps resolving the compiler error. At least this one
|
|
|
|
 |
|
 |
AllocString(nRetVal);
_tcsncpy(m_pszString, pszTemp, nRetVal);
m_pszString[nRetVal]=0;
|
|
|
|
 |
|
 |
used _vsntprintf(...) ..
how to write to POSIX ??
thx
|
|
|
|
 |
|
 |
Could someone please help with a piece of code to convert CCOMString back into BSTR?
Sorry, I'm a beginner.
|
|
|
|
 |
|
 |
I've already figured out myself.
|
|
|
|
 |
|
 |
In order to avoid an error in memmove() for example 'The instruction at "0x7800ffe7" referenced memory at "0x0097c000". The memory could not be "read".' the last parameter of memmove 'Number of bytes of characters to copy' must be the remaining string length not the original. void CCOMString::TrimLeft() { LPTSTR lpsz = m_pszString; while (_istspace(*lpsz)) lpsz = _tcsinc(lpsz); if (lpsz != m_pszString) { // original // memmove(m_pszString, lpsz, (GetLength()+1) * sizeof(TCHAR)); // new - move the remaining string length, not the original length // length shown as separate variable for clarity int nLen = (GetLength() + 1) - (lpsz - m_pszString); memmove(m_pszString, lpsz, nLen * sizeof(TCHAR)); } }
|
|
|
|
 |
|
 |
int CCOMString::ReverseFind(LPCTSTR lpszSub)
{
return ReverseFind(lpszSub, _tcslen(lpszSub));
}
int CCOMString::ReverseFind(LPCTSTR lpszSub, int nStart)
{
int nLength = GetLength();
nStart = nLength - nStart;
if (_tcslen(lpszSub) <= 0 || nStart > nLength || nStart < 0)
{
return -1;
}
CComString newStr(m_pszString);
newStr.MakeReverse();
CComString newSub(lpszSub);
int nSubLength = newSub.GetLength();
newSub.MakeReverse();
LPTSTR lpsz = _tcsstr(newStr + nStart, newSub);
int nResult = (lpsz == NULL) ? -1 : (int)(lpsz - newStr);
if (nResult != -1)
{
nResult = nLength - (nSubLength + nResult) + 1;
}
return nResult;
}
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
 |
|
 |
I think I've come up with a version of this class that will compile under PocketPC 2K2.
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
 |
|
 |
I get garbage text when i concate long lines of text.
|
|
|
|
 |
|
 |
Hi folks!
I use the class in a Tokenizer class I've written, and (after some modifications proposed in a previous thread) it works fine. But why is it called CCOMString ( I mean the "COM" )? I don't know that much about COM, but normally you have a reference counter, which is increased, if a) the COM object is constructed or b) the object is copied or used by another object. I don't find that concept in CCOMString class, so I'm a bit curious what the name means.
Best regards
Andreas Haferburg
|
|
|
|
 |
|
 |
I don't want to kill the idea (well, actually I do), but why not using WTL strings with VC 6.0? And in VS.Net MFC and ATL share common CString implementation.
VC framework is already full of string implementations (CString, CComBSTR, _bstr_t, STL strings), so I don't see the point of adding yet another one.
Vagif Abilov
MCP (Visual C++)
Oslo, Norway
|
|
|
|
 |
|
 |
Back when we started our latest project, there just didn't exist a solid string class that met our needs. We needed to be able to use UNICODE and MBCS strings in the same build. That killed CString, CComBSTR, and _bstr_t. Then the problems with STLPort and bugs in VC6 strings made STL string unusable. Not to mention that STL strings don't support mixed string styles well. The support them, but just don't mix as well as we needed.
Thus we created our own.
If we started the project today, we would use the ATL strings since they seem to be not only full featured, but can mix W and A strings in the same application easily.
So, there are valid reasons to re-invent implementations. We had to re-write STL's hash_map since it made implementation decisions that relegated it to a limited set of problems. We improved performance by 4 fold with our implementation that was specifically tailored for our needs.
Just because there exists a solution in a problem set doesn't mean that solution fully covers the problem set.
Tim Smith
"Programmers are always surrounded by complexity; we can not avoid it... If our basic tool, the language in which we design and code our programs, is also complicated, the language itself becomes part of the problem rather that part of the solution."
Hoare - 1980 ACM Turing Award Lecture
|
|
|
|
 |
|
 |
OK, that explains it. I thought the code was new. But since it's probably older than first WTL implementation, you had all reasons to come up with this solution. Great code. I was just curious about practical aspects.
Best regards and thanks for sharing your code.
Vagif Abilov
MCP (Visual C++)
Oslo, Norway
|
|
|
|
 |
|
 |
I spent a lot of time trying to debug it and in vain. Even destructor don't frees allocated memory!
|
|
|
|
 |
|
 |
Make these changes: 1) CCOMString::~CCOMString(){ if (m_bAllocated){ free (m_pszString); }; } 2) Remove the function and header for ReAllocString 3) Change all other occurences of ReAllocString to AllocString 4) Change AllocString: void CCOMString::AllocString(int nLen){ ATLASSERT(nLen >= 0); if (m_bAllocated){ m_pszString = (TCHAR*) realloc(m_pszString, (nLen+1) * sizeof(TCHAR)); }else{ m_pszString = (TCHAR*) malloc((nLen+1) * sizeof(TCHAR)); } m_bAllocated=true; m_pszString[nLen] = '\0'; } 5) Add m_bAllocated=false; to the top of every constructor 6) Add bool m_bAllocated; to the protected section of the header 7) Have yourself a great coding day with a great string class that includes perl style concatenation
|
|
|
|
 |
|
 |
I changed a bit in demo application to test leaks in CCOMString. After the loop i don't see the memory is released all. I think we still have leaks in CCOMString class.
void main()
long i = 0;
CCOMString zTotal;
while (TRUE)
{
CCOMString zTest;
zTest+=_T("1234567890");
zTest+=_T("QWERASDFZXCVTYUIFGHJVNBMO[P]K;'M.,/");
zTest+=_T("qwertyuiop[]\asdfghjkl;'zxcvbnm,./");
zTest+=_T("~!@#$%^&*()_+");
zTotal+=zTest;
i++;
zTest.Empty();
if (i == 10000)
{
zTotal.Empty();
break;
}
Sleep(1000);
}
Any suggestion?
|
|
|
|
 |
|
 |
is there a method or anyone has done similar, to compare a string with another string consists of wild card characters?
e.g.
"house" is equal to "hou*"
cheers,
cym
|
|
|
|
 |
|
 |
there is more general solution:
try search this server for "regular expresion"s
t!
|
|
|
|
 |
|
|
 |