|
Boost : |
Subject: Re: [boost] [string] Realistic API proposal
From: Joe Mucchiello (jmucchiello_at_[hidden])
Date: 2011-01-28 23:12:13
>> > // 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:
// 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);
...
Joe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk