Mathematics, philosophy, programming, in-line skating and everything in between. More about me…

My Blog

My Latest Tweets

Follow me on Twitter…
English | Czech
Choose your language. I write in English, but I translate most of my articles to Czech as well. Zvolte si jazyk. Píšu anglicky, ale většinu svých článků překládám i do češtiny.

Vita::string – a slightly better C++ string

In the past year and a half I worked on several bigger C++ projects. Each one required string handling, and every time I found the basic std::string class lacking a few bits and pieces. I consequently derived my own class and started adding the missing capabilities.

In the course of time I created a few more classes which together form a tiny library. In the following weeks I am planning to improve, document, and publish this work of mine. Vita::string is the first part.

The class is not meant to be a backwards-compatible replacement of std::string. Actually, Vita::string contains some methods designed specifically to override the behavior of its ancestor.

All new methods are declared const, that is, they operate on copies of the original object. This mimics the behavior of the JavaScript String class. The methods can be nicely chained, like this:

Vita::string str("Lorem-ipsum-dolor-sit-amet");
std::vector<Vita::string> v = str.lcfirst().replace("o", "0").explode("-");

The class also features conversion utilities:

Vita::string str1("3.1415");
double pi = str.convert<double>();
Vita::string str2 = Vita::string::toStr<int>(150);

I don’t consider my work on Vita::string complete; I have some plans for the future and I’ll be happy to hear any suggestions or feature requests.

Download & documentation

Library documentation is contained in the downloadable archives. It is also available for on-line browsing.

The archives also contain a simple program demonstrating some of the capabilities of the class. You can build it by executing make in the demo/ directory.

I’ll be publishing other parts of my library pretty soon.

July 10, MMVIII — C++ and Programming.

Speak your mind

Allowed HTML tags are a, blockquote, em, code, li, ol, p, pre, strong, ul. Links to other comments in the form “[IV]” or “[4]” are detected automatically.