Very nice. As for suggestions for improvement:
- You're mixing signed and unsigned types. Your sizes/lengths are unsigned, but you use signed indexes (making it impossible to index higher-bound things)
- Add reference counting and copy-on-write semantics so that copies are not expensive
- If you add ref counting, also add a way to make an instance unique so it can be used in multithreaded environments
- condense your code into private functions. You have a lot of duplicate/triplicate code there that really should be cleaned up. Your += operators, copy ctor, assignment operator, etc are all reallocating -- that should really be in one distinct function -- and just look at all those replace overloads! Yikes! Same problem with == and != overloads.
- where are the <, >, <=, >= overloads? Gotta have a way to sort strings.
- get rid of your magic numbers and make them static const member vars -- or maybe user modifyable static vars (you seem to like 33 for the minimum buffer size)
- ugh @ the cast operators. operator char* () is especially ugh and would have all sorts of problems if used. Consider the following:
1 2 3 4 5 6
|
// someone being dumb with your string class:
string foo = "test";
strcpy( foo, "a" ); // allowed because of your cast operator
if( foo == "a" ) {} // will be true.. however...
cout << foo.length(); // prints 4! wtf
| |
This is partially the fault of the char* operator, but also the fault of your == operator for using null terminators instead of the known length.
- if you want to make it more familiar, you should pick better names for some functions. In particular, "maxsize" is better known as "capacity" for people familiar with STL. Also, "end" does something entirely different in STL and your use of it is kind of confusing.
- maybe add iterators?
- no love for Unicode?