
// UTF validation
bool is_valid_utf() const;
See, that's what makes the whole thing pointless.
Actually not, consider:
socket.read(my_string); if(!my_string.is_valid_utf()) ....
This, and many of these functions, work much better as standalone functions:
To be honest I agree, if we just can keep std::string. Adding these functions would allow giving more UTF orientation to string - the ultimate goal we want.
// with a string-aware function socket.read(my_string); if (!is_valid_utf8(my_string.begin(),my_string.end())) ....
// with a C interface std::vector<char> vec; vec.resize(MY_BUFSIZE); int len = recv(socket, vec.data(), MY_BUFSIZE, 0); if (len >= 0) { vec.resize(len); if (!is_valid_utf8(vec.begin(), vec.end())) .... }
// conversion for Windows API std::vector<wchar_t> vec; vec.resize(count_codepoints<utf8>(mystring.begin(), mystring.end())); convert<utf8,utf16>(mystring.begin(), mystring.end(), vec.begin()); HRESULT hr = WriteFile(handle, vec.data(), vec.size(), &dwBytesWritten, NULL); ...
Notice vector is not string and it requires additional copy Artyom