Edit:
It's a shame I cannot edit the thread's title.
[b]What are UStrings?:[/b]
I have found null-termination (c-strings and std string) to be quite limiting. Generally it's fine, and efficient. In the days of C, it's pretty much your only realistic option, in the absence of classes. However, there are times you would like a 0 (not '0') in a string, without wrecking it. This project is designed to achieve just that.
[b]Why?:[/b]
Because I'm bored.
[b]Will this be useful?:[/b]
I don't know just yet. UString-to-UString interraction works just fine with the ignoring (and general absence) of a null terminator. It works great for networking (send and recv), and anything else that isn't dependent on a null terminator. Unfortunately, printf and other similar commands will stop reading prematurely if the string contains a NULL.
The most useful aspect will probably be the functions it comes with.
(all functions have overloads for various uses)
(most parameters skipped for sake of page size)
- UString::c_str() - Returns a char*. Incompatible with most things.
- UString::Len() - Think strlen(), but UString compatible.
- UString::New() - Free the old string, create a new one.
- UString::Rem() - Remove a string if found.
- UString::RemAll() - Remove all of a string found.
- UString::Add() - Append to the end of a string.
- UString::Insert() - Insert string fragment into the UString.
- UString::Replace() - Replace string fragment with another. (UNFINISHED)
- UString::ReplaceAll() - Replace all of string fragment with another. (UNFINISHED)
- UString::Chr() - Think strchr()
- UString::Chr(short skip) - Overload. Returns the [skip]th strchr();
- UString::SubStr() - Think strstr()
- UString::SubStr(short skip) - Overload. Returns the [skip]th strstr();
[b]Shortcomings:[/b]
This is an early prototype, so it's very messy, unstable, and impractical. The main, long-term shortcoming I foresee is incompatibility with functions relying on null-termination. I have some ideas on how to get around that, but they are all a bit iffy...
[b]Possible commingsoons:[/b]
UString equivalents to some of the main c-string functions (strstr, strchr, etc), for internal compatibility. Rem() currently uses strstr to find the string..you get the idea.
[b][Download][/b]
[url]http://solidfiles.com/d/39340/[/url]
std::string is [B][I]not[/I][/B] null-terminated. You just can't use a constructor taking a C-string without specifying the length (for obvious reasons):
[cpp]
std::string str("Hello\0world!", 12);
[/cpp]
Ahhh, I should do more research on std::strings ;)
I guess that defeats the purpose of UStrings. I may continue, if I begin to see the purpose before I become bored.
[QUOTE=jA_cOp;21998892]std::string is [B][I]not[/I][/B] null-terminated. You just can't use a constructor taking a C-string without specifying the length (for obvious reasons):
[cpp]
std::string str("Hello\0world!", 12);
[/cpp][/QUOTE]
nice snipe there :v:
Sorry, you need to Log In to post a reply to this thread.