# xstr, my C++ string class

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

xstr is a string class I wrote that support many basic operations/conversions that can't be done with c-strings or the standard library string classes. I've used it in quite a bit of my C++ stuff and I figured some of the programmers around here would benefit from it. Anyway, if your interested, check it out and see if it's useful to you.

##### Share on other sites
Whats does it do?

ace

##### Share on other sites
Quote:
 Original post by ace_lovegroveWhats does it do?

Did you look at his link?

##### Share on other sites
The tag line for your string class, "xstr a string class for C++" is misleading; your code is extremely non-portable, it looks like MSVC based. It makes the assumption that wchar_t is 16 bits on the target compiler as well as using what look like MSVC specific runtime functions. It doesn't even use the standard include guards, relying on #pragma once. Plus you've got more potential buffer overruns in there than I can conveniently count. In particular it seems that every single one of your uses of wcscat() can potentially overflow, and the one time I saw that you did check to see if your buffer overflowed, it was against a hardcoded 255 and not the actual max length non-type template parameter your class uses.

##### Share on other sites
Other than what SiCrane pointed out, it might look very promising with more updates..

##### Share on other sites
I would just like to point out that near the top of the header he has
#include <string>

If you don't understand why I'm mentioning this, then, well, the joke's not for you.

##### Share on other sites
So...your saying that it isn't really his class?

##### Share on other sites
Quote:
 Original post by SiCraneThe tag line for your string class, "xstr a string class for C++" is misleading; your code is extremely non-portable, it looks like MSVC based. It makes the assumption that wchar_t is 16 bits on the target compiler as well as using what look like MSVC specific runtime functions. It doesn't even use the standard include guards, relying on #pragma once.

Yes, the code is MSVC-specific. I should have mentioned that. It should work with the VC6, 2002, 2003 and 2005 compilers; however with 2005 you'll get warning about the standard c-string copy and concatanation functions being deprecated.

I have no clue how portable it is, I'll take your word that it's "extremely non-portable."

Quote:
 Original post by SiCranePlus you've got more potential buffer overruns in there than I can conveniently count. In particular it seems that every single one of your uses of wcscat() can potentially overflow, and the one time I saw that you did check to see if your buffer overflowed, it was against a hardcoded 255 and not the actual max length non-type template parameter your class uses.

Fair enough. I guess it was irresponsible of me to make the code public w/o taking a closer look at it.

Here's an updated version: xstr 2.6
This should fix most, if not all, of the potential buffer overruns. If anyone finds any other bugs or flaws, please tell me. I've also removed the older version of the class from the file.

Quote:
 Original post by PromitI would just like to point out that near the top of the header he has#include If you don't understand why I'm mentioning this, then, well, the joke's not for you.

The string header is included b/c there are functions that cast to/from std::string and std::wstring.

##### Share on other sites
hmm, no more comments?

If they're any programmers around with a bit of free time, I'd appreciate some code review.

##### Share on other sites
*takes a stiff drink*

Errm.. yeah, a few comments;

• implicit conversions make baby jesus cry.
• calculating the length everytime you ask for it? Waste of resources.
• I cant help but feel most of those operators you've defined are a tad pointless
• IsValidCharacterIndex() is probably redundant
• ToBool() just seems.. insane.
• Infact, most of the ToType functions seem redundant and insane.
• why the min/max macros? std::max/std::min anyone? (and if you say because its faster I will hunt you down...
• SetStr() should really set the lenght, not rely on other functions todo so
• operators not defined in terms of other operators
• Two GetSubStringBlock functions when one and a default parameter would have done the job
• GetSubStringBlock seems insane anyways...
• C-style casts ALL over the place
• Basically no compatibility with the Std C++ Lib.

To my untrained eye it looks like you've gone "hey, wouldnt it be neet if I made a fixed length string with all those little functions I need and not make it compatbility with the standard library and make it worse than the built in version".. if so, well done.

That maybe harsh but I just call it how I see it.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633303
• Total Posts
3011278
• ### Who's Online (See full list)

There are no registered users currently online

×