From: "David Bertoni" <[email protected]>

On 1/20/2010 5:45 AM, Ben Griffin wrote:
We use many literal XMLCh* string declarations in our codebase.

I am still not sure what is the safest, but most efficient way of declaring these WITHOUT RELYING UPON A TRANSCODE.
Take a look at src/xercesc/util/XMLUni.cpp:

const XMLCh XMLUni::fgAnyString[] =
{
    chLatin_A, chLatin_N, chLatin_Y, chNull
};

You could make this more readable by adding a literal string as a comment:

// "ANY"
const XMLCh XMLUni::fgAnyString[] =
{
    chLatin_A, chLatin_N, chLatin_Y, chNull
};

I must admit I looked at code like that, and wondered what it was for. The chLatin... definitions are in XmlUniDefs.hpp and cover 0-9, A-Z and a-z and very few others. An example is:

const XMLCh chLatin_A               = 0x41;

This is not going to come as a surprise on any machine with ASCII, UTF-16 or any Windows (and probably other) code page. It would be (for example) a bit radical on an IBM360 which (in my day <g>) used the EBCDIC character encoding, which is completely different from ASCII (and designed IIRC to reduce the frequency of getting too many holes punched too close together on the old punched card system - happy days). So it leaves me wondering what sort of extreme portability is aimed at here.

const XMLCh XMLUni::fgAnyString[] = { 'A', 'N', 'Y', '\0' }

(casting each character to a word) would surely do the same thing on any system of practical interest?

For those with the L operator, then

const XMLCh XMLUni::fgAnyString[] = { L'A', L'N', L'Y', L'\0' }
const XMLCh XMLUni::fgAnyString[] = L"ANY";

would surely be the same again. But I've never used the gcc compiler and maybe I'm missing something?

The C++ standard doesn't define a portable way to indicate UTF-16 string constants, so it's not surprising it's a problem. This should change in the next version of the standard, but it will be a long time before compilers that support it are widely available.

Are there compilers use something other than L"ANY"? Is the standard likely to be something else?

Dave
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm




Reply via email to