Boost logo

Boost :

Subject: Re: [boost] [string] Realistic API proposal
From: Artyom (artyomtnk_at_[hidden])
Date: 2011-01-29 02:04:58


>
> >> > // 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

      


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk