Jump to content
  • Advertisement
Sign in to follow this  
directrix

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
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.


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 SiCrane
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.


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 Promit
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.


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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!