OUString is mutable?

Noel Grandin noel at peralex.com
Fri Sep 28 05:07:16 PDT 2012


On 2012-09-28 14:03, Caolán McNamara wrote:
> Hi
>
> I don't really understand the point of not being able to mutate OUString
> in-place, but being able to overwrite it via the assignment operator?
>
> It seems to me it should be one or the other.
> Either OUString is immutable, and it cannot be assigned to, except via a
> constructor, or it is mutable, and we can pretty much throw away
> OUStringBuffer.
> Consider OUString as a smart const pointer to an immutable rtl_uString.
>
> i.e.
> const char *pFoo;
> pFoo = "hello";
> pFoo = "world"; //ok
> pFoo[0] = 'A'; //won't compile
> const_cast<char*>(pFoo)[0] = 'A'; //compiles but evil
>
>


Thanks. Weird, but makes sense.

Just looks very strange when we're passing an OUString as a parameter to 
a function in order that the function can write to it.


Disclaimer: http://www.peralex.com/disclaimer.html




More information about the LibreOffice mailing list