String Theory is a flexible modern C++ library for string manipulation and storage. It stores data internally as UTF-8, for ease of use with existing C/C++ APIs. It can also handle conversion to and from UTF-16, UTF-32, and Latin-1, and has a variety of methods to simplify text manipulation.
In addition, String Theory includes a powerful and fast type-safe string
ST::format), which can be extended with custom type formatters
by end-user code.
String Theory was originally developed to replace the half-dozen or so string types and string manipulation mini-libraries in the Plasma game engine. Because of the state of the code, it was designed primarily to reduce coding errors, provide an easy to use set of manipulation functionality with minimal surprises, handle Unicode text without a lot of overhead, and have reasonable performance. Many existing string libraries provide some subset of those features, but were hard to integrate well with Plasma, or didn't meet all of our needs. Therefore, plString (and later plFormat) were born. After it had matured a while, it seemed that other projects could benefit from the string library, and so it was ported out into its own stand-alone library, which is String Theory.
String Theory is designed to provide:
.replace()will create a copy or modify the original -- it will always return a copy even if the new string is identical.
ST::stringis constructed, its data is assumed to already be in the UTF-8 encoding. This also allows easy re-use by other character-based APIs, since you don't have to first down-convert the string data from UTF-16 or UTF-32 in order to use it.
sprintfand friends are notoriously unsafe, and are one of the most common sources of bugs in string code.
ST::formatuses C++11's variadic templates to provide a type-safe way to format strings. String Theory also provides a mechanism to create custom formatters for end-user code, in order to extend
ST::string, this ends up being slightly slower than C++'s
std::stringdue to the extra encoding work. However, in my tests
ST::string_streamtends to be faster or at least on par with
ST::formatis in the same order of magnitude as an equivalent
std::string. String Theory was never designed to be faster than STL, and because of its design goal to always use UTF-8 data internally, it may be slower for some use cases. However, practical tests have shown that
ST::stringperforms at least on par with STL in many use cases, and
ST::formatis usually significantly faster than many other type-safe alternatives such as
ST::string, and I don't have a compelling reason at this point to introduce another regular expression library to String Theory.
string_theory supports a variety of platforms and compilers. As of July 2020, string_theory is tested and working on:
As of string_theory 3.0, support for some older compilers has been dropped. You'll need a compiler that supports most of C++11.
String Theory is Open Source software, licensed under the MIT license. Contributions are welcome, and may be submitted as issues and/or pull requests on GitHub: https://awesomeopensource.com/project/zrax/string_theory.
Some ideas for areas to contribute: