Subject: Re: UT_UCS2String problems
From: Joaquin Cuenca Abela (e98cuenc@yahoo.com)
Date: Fri Jun 01 2001 - 13:20:04 CDT
--- Andrew Dunbar <hippietrail@yahoo.com> wrote:
> Joaquin Cuenca Abela wrote:
> >
> > --- Andrew Dunbar <hippietrail@yahoo.com> wrote:
> > >
> > > Also the size() method is now ambiguous. Does
> it
> > > return the
> > > number of characters or the number of bytes?
> > > Shouldn't we
> > > have two non-ambiguous methods in both the
> UT_String
> > > and
> > > UT_UCS2String?
> >
> > I don't think so. To me size() should return the
> > number of "entries" in the string. And here, the
> type
> > of the "entries" are "char", or "wchar_t", or
> > whatever. So size should return the number of
> > characters.
>
> For a vector or an array I'd agree but a string is a
> bit different. I'll change my code to
> write(pString->ucs_str(), pString->size *
> sizeof(UT_UCSChar));
can you please write the api of "write"?
if you're speaking about write of the C api "size_t
write(int, const void*, size_t)", then yes, that what
you get for using a old, unextensible method (now, if
we only can start using iostreams...).
If the need for the "number of bytes" of a
UT_UCS2String is too high, then you can always add a
"size_t nb_bytes()" or something, but I think that the
interface of this class should stay minimal.
> Have you checked the corruptions problems by the
> way?
I don't have the time to test it, but after a very
quick look at the code:
===========================
UT_UCS2String& UT_UCS2String::operator+=(UT_UCSChar
rhs)
{
UT_UCSChar cs = rhs;
pimpl->append(&cs, 1);
return *this;
}
the copy of rhs in cs is unnecesary. Besides that,
everything seems ok. A look at
UT_UCS2Stringbuf::append reveals:
============================
void UT_UCS2Stringbuf::append(const char_type* sz,
size_t n)
{
if (!n) {
return;
}
if (!capacity()) {
assign(sz, n);
return;
}
const size_t nLen = size();
grow_copy(nLen + n);
memcpy(m_psz + nLen, sz, n);
m_psz[nLen + n] = 0;
m_pEnd += n;
}
"memcpy(m_psz + nLen, sz, n);" should be
"memcpy(m_psz + nLen, sz, n * sizeof(char_type));"
(the same bug is present several times in
UT_UCS2Stringbuf)
Check it, and see if it works.
Cheers,
P.S.: I've seen XAP_AbiObject right now, and I think
that we should (at least) discuss if we should use
this kind of aproach to solve the multiref'd objects
problem, of if we should try to solve it with some
kind of smart pointer (I'm too busy to discuss it this
week, but I'm sure that others may start the
discussion :)
-- Joaquin Cuenca Abela cuenca@celium.net__________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/
This archive was generated by hypermail 2b25 : Fri Jun 01 2001 - 13:20:21 CDT