You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Christian Reiniger <cr...@mayn.de> on 2002/06/13 13:12:40 UTC
XMLCh * -> std::string conversion problems
Maybe I'm just blind, but I couldn't find out how to do the following
(using xerces-c-src1_7_0.tar.gz):
I implement ContentHandler (SAX2), and override the "character" method.
Now this method has the signature
void characters (const XMLCh *const chars, const unsigned int length)
i.e. it seems to get a not-null-terminated XMLCh string. I need to convert
this string to a std::string for further processing, but I haven't got
the slightest idea how to do that.
XMLString::transcode() & co only work on null-terminated XMLCh strings.
Bad. Going over XMLString::CopyNString () could be possible, but
according to the description it awaits a null-terminated string as well,
so using it for some random, unterminated snippet is IMHO unsafe.
Looking at samples/SAX2Print/ it seems that a possible way is to implement
XMLFormatTarget::writeChars () [undocumented], pass it to
XMLFormatter::formatBuf () [undocumented] and let it construct a
std::string by casting the XMLByte* parameter to char * . Which is ugly
and unsafe.
So - Is there a simple solution for this problem?
PS: I looked through the mail archives, back to 2002-05-01 and didn't find
anything.
--
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)
REALITY.SYS corrupted ... reboot Universe [Y,n]?
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: XMLCh * -> std::string conversion problems
Posted by Christian Reiniger <cr...@mayn.de>.
On Thursday 2002-06-13 16:51, Robert Buck wrote:
> There are three options:
>
> Option 1:
>
> allocate an unsigned short buffer nchars+1 long (number of unicode
> characters, not C/C++ char's)
> use XMLString::copyNString
> use XMLString::transcode ()
Ok, that should be easy enough - but it should be a buffer of XMLCh
(silently assuming type compatibilities is always bad) :+)
Also, if this is something that explicitly can be done, the description
for XMLString::copyNString () should be adapted to allow for
non-terminated source strings.
> It looks like there is an ommision for a convenience function that is
> present in the transcoders. Please file a bug report specifying the api
> that is missing from the XMLString class.
Done
--
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)
REALITY.SYS corrupted ... reboot Universe [Y,n]?
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: XMLCh * -> std::string conversion problems
Posted by Robert Buck <rb...@mathworks.com>.
There are three options:
Option 1:
allocate an unsigned short buffer nchars+1 long (number of unicode
characters, not C/C++ char's)
use XMLString::copyNString
use XMLString::transcode ()
You could call the transcoding service directly too. Which leads me to the
next option:
Option 2:
XMLLCPTranscoder* defXCode =
XMLPlatformUtils::fgTransService->makeNewLCPTranscoder();
virtual char* transcode(const XMLCh* const toTranscode) = 0;
delete defXCode; // or cache it away somewhere for future use
which returns a heap allocated string in the local code page.
Option 3:
Use ICU directly.
It looks like there is an ommision for a convenience function that is
present in the transcoders. Please file a bug report specifying the api
that is missing from the XMLString class.
-Bob
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: XMLCh * -> std::string conversion problems
Posted by Christian Reiniger <cr...@mayn.de>.
On Thursday 2002-06-13 14:23, Robert Buck wrote:
> Often times one uses ICU with Xerces. Take a look at ICU's conversion
> API's. And just check on the internal guts of your std::string class to
> understand the relationship between its handling of Unicode code-units
> vs code-points. Some implementations may differ.
I guess that's a misunderstanding - I don't really care about proper
unicode handling (in this case). If the thing can only handle latin-1 or
so that's fine with me. My problem is that I'd simply need an equivalent
to XMLString::transcode () that can convert not-null-delimited XMLChar*
"strings" (like the one passed to ContentHandler::character() ) to char*
strings that can be fed to std::string.
I mean, it has to be there somewhere, but I can't find it.
--
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)
REALITY.SYS corrupted ... reboot Universe [Y,n]?
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: XMLCh * -> std::string conversion problems
Posted by Robert Buck <rb...@mathworks.com>.
Often times one uses ICU with Xerces. Take a look at ICU's conversion
API's. And just check on the internal guts of your std::string class to
understand the relationship between its handling of Unicode code-units vs
code-points. Some implementations may differ.
- Bob
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org