As of late I've spent some time making improvements to my tiny C string library called SubStrings. There are other string solutions, but those either involve a language such as C++, or they try and create a new string type with a struct or something. In many of my programs, there is a huge amount of text processing. One might say more than you should generally attempt in C. It's not a big problem for me actually. It's becoming even less of a problem since I made my pet projects use SubStrings. As I said, I've recently updated it, but I've added a ton of new functions and features. I've updated aqu4bot to make use of these improvements where available.
Take this example of trying to iterate through lines of text stored in a string in memory
This was extracted from aqu4bot BEFORE I updated to use the new SubStrings functions.
It iterates through each line and forwards them to an IRC user.
Worker = InBuf;
do
{
while (*Worker == '\r' || *Worker == '\n') ++Worker;if (*Worker == '\0') break;
for (TInc = 0; Worker[TInc] != '\n' && Worker[TInc] != '\r' && Worker[TInc] != '\0' && TInc < sizeof LineBuf - 1; ++TInc)
{
LineBuf[TInc] = Worker[TInc];
}
LineBuf[TInc] = '\0';IRC_Message(SendTo, LineBuf);
} while ((Worker = strpbrk(Worker, "\r\n")));
Hideous, yes?
Thanks to SubStrings, I can shorten it to this:
Worker = InBuf;
while (SubStrings.Line.GetLine(LineBuf, sizeof LineBuf, (const char**)&Worker))
{
IRC_Message(SendTo, LineBuf);
}
I'll be sifting through aqu4bot's code and updating other components that rely on deranged gerbil magic to get strings to work properly. I'll also be working on SubStrings more.
So far, SubStrings is:
* C89/ANSI with no extensions/platform specific stuff
* Doesn't use ANY library functions, meaning you could build it into your bootloader to make text processing easier.
* Uses a pseudo-OOP function pointer based system for getting functions.
* Is small enough to painlessly be embedded in larger source trees.
* Is public domain (unlicense) software, making it pretty much license neutral.
This should encourage me to add new features to aqu4bot, including making good on my threat of using libcurl to build in email support. Why? Because fuck you.