You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Jasmine_Shaikh <ja...@infosys.com> on 2010/08/19 09:30:12 UTC
Re: Problem:Unicode string causing transcode(..) crashes in
External Function
Hi Dave,
We have a similar problem here while using transcode in our external
function. It throws the TranscodingError for strings in East Asian
Languages. Our function actually encodes the XalanDOMString, for which we
need to get std::string from XalanDOMString. Similar to what you said I have
read it at many places that its not good to transcode to the local code
page, but I could not find any other method of Xalan that gives me a C
string.
Could you please provide any suggestions regarding this.
Regards,
Jasmine
David Bertoni wrote:
>
> souri datta wrote:
>> Hi,
>> In the external function whenever I am getting an argument which has
>> some Unicode chars in it,when i try to convert it to std::string..it is
>> causing transcode(..) method carshes.
> All of the characters in a XalanDOMString are "Unicode characters." Do
> you mean non-ASCII characters?
>
>> For example
>>
>> suppose in the external function args[0]->str() contains some Unicode
>> chars.
>> so when I do (args[0]->str()).transcode(opVector); // opVector is of
>> type CharVectorType;
>> it is crashing.
> It's probably not crashing. It may be throwing an exception because
> you're trying to transcode to a local code page that cannot represent
> all of the characters in the string.
>
> You might want to try surrounding the transcoding block with a try/catch
> handler:
>
> try
> {
> args[0]->str().transcode(opVector);
> }
> catch(const XalanDOMString::TranscodingError&)
> {
> std::cerr << "Transcoding failed!\n";
> }
>
> In general, it's a bad idea to transcode to the local code page, since
> it may not be able to encode all of the characters in the XalanDOMString.
>
> Dave
>
>
--
View this message in context: http://old.nabble.com/Problem%3AUnicode-string-causing-transcode%28..%29-crashes-in-External-Function-tp19878741p29479242.html
Sent from the Xalan - C - Users mailing list archive at Nabble.com.
Re: Problem:Unicode string causing transcode(..) crashes in
External Function
Posted by Jasmine_Shaikh <ja...@infosys.com>.
Hi Dave,
Thanks for your quick reply and apologies for replying late.
We had tried using XalanTranscodingServices::makeNewTranscoder() before, but
maybe we were passing some wrong arguments into it, it didn't work. I think
it should work.
We have actually solved the issue using another method to create transcoder
XMLPlatformUtils::fgTransService->makeNewTranscoderFor
to make transcoder for the required encoding. I guess you had suggested both
the methods in one of your previous posts. Anyways thanks for your guidance.
Regards,
Jasmine Shaikh
David Bertoni wrote:
>
> On 8/19/2010 12:30 AM, Jasmine_Shaikh wrote:
>>
>> Hi Dave,
>>
>> We have a similar problem here while using transcode in our external
>> function. It throws the TranscodingError for strings in East Asian
>> Languages. Our function actually encodes the XalanDOMString, for which we
>> need to get std::string from XalanDOMString. Similar to what you said I
>> have
>> read it at many places that its not good to transcode to the local code
>> page, but I could not find any other method of Xalan that gives me a C
>> string.
>>
>> Could you please provide any suggestions regarding this.
> You should transcode to UTF-8. Create a transcoder using
> XalanTranscodingServices::makeNewTranscoder(). Transcode the data into a
> char buffer, then use that buffer to construct a std::string instance.
>
> Dave
>
>
--
View this message in context: http://old.nabble.com/Problem%3AUnicode-string-causing-transcode%28..%29-crashes-in-External-Function-tp19878741p29611556.html
Sent from the Xalan - C - Users mailing list archive at Nabble.com.
Re: Problem:Unicode string causing transcode(..) crashes in External
Function
Posted by David Bertoni <db...@apache.org>.
On 8/19/2010 12:30 AM, Jasmine_Shaikh wrote:
>
> Hi Dave,
>
> We have a similar problem here while using transcode in our external
> function. It throws the TranscodingError for strings in East Asian
> Languages. Our function actually encodes the XalanDOMString, for which we
> need to get std::string from XalanDOMString. Similar to what you said I have
> read it at many places that its not good to transcode to the local code
> page, but I could not find any other method of Xalan that gives me a C
> string.
>
> Could you please provide any suggestions regarding this.
You should transcode to UTF-8. Create a transcoder using
XalanTranscodingServices::makeNewTranscoder(). Transcode the data into a
char buffer, then use that buffer to construct a std::string instance.
Dave