Hello,
I've committed all changes related to the macros and all the different
tinderbox compilers have already compiled fine, so I consider the experiment
successful.
As of now, there should be no need to use either of these macros.
OString/OUString now have overloads that handle string literals, and string
literals convert automatically to OString/OUString, which means it should be
fine to just use string literals without any additional stuff.
In other words, either of these
if (foo.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("XXXXX")))
if (foo.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("XXXXX"))))
can be written as
if( foo == "XXXXX" )
, this
rtl::OUString foo(RTL_CONSTASCII_USTRINGPARAM("XXXXX"));
can be written simply as
rtl::OUString foo("XXXXX");
and
functionFoo( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("XXXXX")))
can be written as
functionFoo( "XXXXX" );
There are even more horrible multiline constructs in the code that can be
converted to a simple one-liner, but I don't want to scare anybody :).
I don't know if we want to encourage mass converts for this or create an Easy
Hack, we have thousands of instances of the macros in the source, so this
might lead to an unwanted flood.
There are few small catches when writting new code or converting existing
code:
- return "foo"; does not work for OUString return values
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41426)
- extern const char foo[]; (i.e. extern without a size given) does not work
with MSVC (and it's probably allowed to reject that), but this should be very
rare and can be fixed by converting to const char* const foo or specifying
the size
- embedded \0 in string literals is undefined, it cannot be detected at
compile time, but there will be runtime warnings. The reason for this is this
struct foo { const char s[ 3 ]; };
const foo foos[] = { "a", "bc" };
where foos[0] is actually "a\0" (i.e. 'a', '\0', '\0' ).
On a somewhat related note, I've also added macro SAL_DEBUG, which is like
SAL_INFO, except that it is meant in place of the usual debug-style printf()
calls that some people put temporarily in the code while debugging. Moreover
I've included rtl/oustringostreaminserter.hxx directly into rtl/ustring.hxx
(hopefully I'm right that it won't break anything in practice), so if you now
need to know what 'foo' is, just do
SAL_DEBUG( "foo is " << foo );
The git commit hook will reject commits with these debug outputs left in
code.
I have also updated
https://wiki.documentfoundation.org/Development/String_Classes accordingly.
--
Lubos Lunak
l.lunak@suse.cz
Context
- RTL_CONSTASCII_(U)STRINGPARAM officially obsolete · Lubos Lunak
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.