For string manipulation, use the util/mongoutils/str.h library.
util/mongoutils/str.h provides string helper functions for each manipulation. Add new functions here rather than lines and lines of code to your app that are not generic.
Typically these functions return a string and take two as parameters :
string f(string,string).
Thus we wrap them all in a namespace called str.
str::stream() is quite useful:
uassert(12345, str::stream() << "bad ns:" << ns, isok);
/** A StringData object wraps a 'const string&' or a 'const char*' without
* copying its contents. The most common usage is as a function argument that
* takes any of the two forms of strings above. Fundamentally, this class tries
* go around the fact that string literals in C++ are char[N]'s.
*
* Note that the object StringData wraps around must be alive while the StringData
* is.
*/
class StringData {
See also bson/stringdata.h.
MongoUtils has its own namespace. Its code has these basic properties: