Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hullo List,

I hope this isn't a silly question, but I'm a little confused by a current behavior of the O*String classes, and wondering if it's A) known, and B) expected.

Please consider this code snippet:

-----
using ::rtl::OString;

OString a( "My Test String: " );
OString b( "Gobble Wobble" );
OSL_TRACE( "\n\n" );
OSL_TRACE( "a  : %s", a.getStr() );
OSL_TRACE( "b  : %s", b.getStr() );

a += b;
OSL_TRACE( "a+b: %s", a.getStr() );

// a += '\n';                         Does not work.  Should it?

a += b + '\n';                     // This is the suspect line
OSL_TRACE( "a+n: %s", a.getStr() );

/* OUTPUT:
Thread:     10 :a  : My Test String:
Thread:     10 :b  : Gobble Wobble
Thread:     10 :a+b: My Test String: Gobble Wobble
Thread:     10 :a+n: My Test String: Gobble Wobbleble
*/
-----

The a+b line is as expected, but adding a newline single character seems to break. I expected to receive this:

"a+n: My Test String: Gobble WobbleGobbleWobble
"

(Note the newline at the end, and repeated "Gobble Wobble" bit.)

Is that + operator expected to work with an O*String and a single character?

From analysis with Sébastien Le Ray, it looks like what's happening is that the b OString is converted to sal_Char *, and the compiler uses int( '\n' ) (=10) for the + operator. So, the pointer of "Gobble Wobble" is moved to "ble" before the += operator takes over.

Changing the suspect line to

a += b + "\n";

gives me the results I was originally expecting. (double quotes " for the single quotes ').

Is this expected behavior? It's admittedly a corner case, but I'm wondering if the is a bug in the API.

Cheers,

Kevin

P.S. I'm aware that I should be using O*StringBuffer for concatenation, but that doesn't detract from this issue.


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.