Boost logo

Boost :

From: Matt Gruenke (mgruenke_at_[hidden])
Date: 2008-03-04 05:03:45


Phil Endecott wrote:
> Matt Gruenke wrote:
>

>> Something that might be worth a look is Glib::ustring, in glibmm-2.
>>
>> http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1ustring.html
>>

> - It uses size_type to pass and return positions in the string, and
> doesn't specify whether these are byte or character positions; I get
> the impression that they're character positions but I could be wrong.
>

Given that they highlight the pitfalls of byte-based addressing in
std::string (when instantiated with multibyte characters)

    |std::string::operator[]
    <http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/classstd_1_1basic__string.html#std_1_1basic__stringa79>|
    might return a byte in the middle of a character, and
    |std::string::length()
    <http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/classstd_1_1basic__string.html#std_1_1basic__stringa71>|
    returns the number of bytes rather than characters

and that virtually everywhere size_type is used (where there's
documentation), they explicitly state that it describes a number of
characters, I think it's character-based. Also, they provide a bytes()
member function, in addition to size() and length().

> - It offers implicit conversion to and from std::string. Is this desirable?
>

I feel the danger and potential for confusion easily outweigh the
benefits. I agree that something like a str() member function is the
way to go.

Matt


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