More portable toLower() implementation
typedef std::wstring::npos tnpos;



std::string::npos and std::wstring::npos are static constant integer members of std::string and std::wstring, respectively. They are not types and they cannot be typedef'd.


unsigned int len = str.length();



This is incorrect. std::string::length() has a return type of size_t std::string::size_type which may be larger than an unsigned int depending on your platform and compiler. Other class methods will use the same type for length/position/indexing, so you should make this change for all the other uses of unsigned int.


// or use lower.reserve(len);



No, please don't. That reserves space for the string, but it does not resize it. There is a resize() method.

Since you said you're able to use C++11 features, as long as they're enabled, the first version of the function (the one that returns a string) will work without copying. It will use the move constructor. So you don't have to use the cumbersome version with an input and output parameter. For more information see http://blog.smartbear.com/c-plus-plus/c11-tutorial-introducing-the-move-constructor-and-the-move-assignment-operator/