OString string literals ctor

Lubos Lunak l.lunak at suse.cz
Wed Mar 7 07:03:39 PST 2012


 attached is a patch that removes the need to use the 
RTL_CONSTASCII_STRINGPARAM macro with OString, similar to the patch from 
the 'Obsoleting RTL_CONSTASCII_USTRINGPARAM' thread.

 The difference here is that OString has a const char* ctor, which causes some 

- having const char* and const char(&)[N] overloads always prefers the first 
one for string literals, which AFAICS should be of the latter type. Trying to 
go for const char*(&) does not work e.g. with something explicitly cast to 
const char*. The solution I've found is to use a template and use SFINAE 
(Substitution failure is not an error) idiom to in practice limit the 
template arguments to only char* and const char*. Using the template makes 
the compiler consider the const char(&)[N] ctor first. I'm not entirely sure 
why this is so, but the problem and solution are consistently the same with 
gcc, clang and msvc.

- embedded \0's strike again, RTL_CONSTASCII_* macros include them in the 
string, the OString const char* ctor does not. There's no perfect solution, 
I've decided to make the string literal ctor include \0's as well, given it's 
mostly meant as a replacement for RTL_CONSTASCII_*, moreover if the \0 is 
explicitly present in the literal, pressumably it's there for a reason. This 
is not backwards compatible for the OString( "\0" ) case, but such code has 
been up to now pointless anyway, so I do not see a problem with this. This 
required also fixing unittests which tried to use this for whatever reason.

 I've checked that I can make a rebuild without this introducing any 
compilation warnings or errors.

 I'd like to also point out to people doing changes like

- foo == OString( RTL_CONSTASCII_STRINGPARAM( "bar" ))
+ foo.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "bar" ))

 that this will be soon obsolete by these changes and easily replaced by plain

 foo == "bar"

 (Do we have an Easy Hack asking for the above, so that I change it? I 
couldn't find one.)

 Lubos Lunak
 l.lunak at suse.cz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-rtl_uString_newFromLiteral-for-string-literals.patch
Type: text/x-diff
Size: 6717 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20120307/0b46b55c/attachment-0003.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-OString-ctor-for-string-literals-without-RTL_CONSTAS.patch
Type: text/x-diff
Size: 24565 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20120307/0b46b55c/attachment-0004.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-remove-usage-of-RTL_CONSTASCII_STRINGPARAM.patch
Type: text/x-diff
Size: 7766 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20120307/0b46b55c/attachment-0005.patch>

More information about the LibreOffice mailing list