[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: UniversalString in Enc and Dec
Kaliraj,
Below is working sample code for what I think you are trying to accomplish. I don't understand why you want to print it to a file to compare, but, nonetheless, I have provided you with a successful way to do just that, as well as an alternative way to compare the encoded vs decoded strings. Please read the inline comments for brief descriptions of the minor changes. I removed the och variable as I found it a bit extraneous.
int main()
{
UniversalString ustr;
UniversalString dustr;
wchar_t wch[132] = L"Lé Royalé Meridien";
FILE *fp;
AsnBuf buf;
unsigned long bytes = 0;
fp = fopen("ustr.txt", "w+");
if(fp == NULL) printf("Error opening File\n");
try
{
ustr = &wch[0];
ustr.BEnc(buf);
buf.ResetMode();
dustr.BDec(buf,bytes);
/* Instead of printing to a file to see if it worked, I
* suggest code like below to compare ustr and dustr directly
* since they work off of the std::wstring class
*/
if(ustr == dustr)
printf("Success: Strings match after encode/decode!\n");
else
printf("Failure: Strings do NOT match after encode/decode!\n");
/* All of our getAsUTF8() functions are meant to
* Convert wide character strings to UTF-8 character strings
* They cannot be used with fwprintf to properly display a
* multi byte character string since they do not return
* multi byte character strings.
*/
fwprintf(fp, L"%s\n", dustr.data());
}
catch(SnaccException &se)
{
se.getCallStack(std::cout);
cout << "Exception thrown Snacc " <<se.what()<< endl;
}
catch(exception &e)
{
cout << "Exception thrown : " <<e.what()<< endl;
}
fclose(fp);
return 0;
}
Let me know if I can be of any furthur assistance.
--Joe
-----Original Message-----
From: Kaliraj Kalaichelvan - CTD, Chennai [mailto:kalirajk@xxxxxxxxxxx]
Sent: Monday, September 19, 2005 2:57 AM
To: Grone, Joseph; Sivakumar S - CTD, Chennai.; imc-snacc@xxxxxxx
Cc: Kaliraj Kalaichelvan - CTD, Chennai
Subject: UniversalString in Enc and Dec
Joe
Ur sample code works fine. Still i face the problem while encoding and
decoding.
The code is the same but only included the enc and dec. It doesnt throw the
exception but i get a different string.
I have given the code for ur referrence. Ur suggested works fine without
encoding and decoding
Code:
int main()
{
UniversalString ustr;
UniversalString dustr;
wchar_t wch[132] = L"Lé Royalé Meridien";
unsigned char* och=NULL;
FILE *fp;
AsnBuf buf;
unsigned long bytes;
fp = fopen("ustr.txt", "w+");
if(fp == NULL) printf("Error opening File\n");
try
{
ustr = &wch[0];
ustr.BEnc(buf);
buf.ResetMode(std::ios_base::in);
dustr.BDec(buf,bytes);
och = (unsigned char *)dustr.getAsUTF8();
fprintf(fp,"%s\n",och);
}
catch(SnaccException &se)
{
se.getCallStack(std::cout);
cout << "Exception thrown Snacc " <<se.what()<< endl;
}
catch(exception &e)
{
cout << "Exception thrown : " <<e.what()<< endl;
}
fclose(fp);
free(och);
return 0;
}
I am attaching the ustr.txt i got. Pls open that in Notepad.
But without enconding and decoding it works fine with files
Kindly Help
Regds
Kaliraj K
-----Original Message-----
From: Grone, Joseph [mailto:joseph.grone@xxxxxxxxxxxxxx]
Sent: Wednesday, September 14, 2005 10:22 PM
To: Sivakumar S - CTD, Chennai.; imc-snacc@xxxxxxx
Cc: Kaliraj Kalaichelvan - CTD, Chennai
Subject: RE: UniversalString throws exception
Siva and Kaliraj,
Our code is actually working as intended. The reason you are failing is
because you are not giving the set function the string in correct utf8 form.
To solve this, I have provided you with the correct code below with a few
inline comments describing what has been changed and why.
int main()
{
UniversalString ustr;
/* This must be declared as a wide character array and, when assigning
a wide character string, the L must be added as a qualifier before the
first double quote
*/
wchar_t ich[32]= L"Lé Royal Meridian";
/* This should be a character pointer because the getAsUTF8 function
returns a strdup'd copy of the UTF8 string. Since memory is already
allocated, it is unnecessary to allocate extra space. This would
leave room for a potential memory leak.
*/
char* och = NULL;
try
{
ustr.set((const char *)&ich[0]);
och = ustr.getAsUTF8(); /* see comment above where och is declared */
}
catch(SnaccException &se)
{
se.getCallStack(std::cout);
cout << "Exception thrown Snacc " <<se.what()<< endl; }
catch(exception &e) {
cout << "Exception thrown : " <<e.what()<< endl;
}
free(och);
return 0;
}
Thank you for asking this question as I'm sure that you guys aren't the only
ones who have ever come across this issue. I hope this solves your problems
and assists you in further devolopment. Please let me know if I can do
anything else for you.
--Joe
-----Original Message-----
From: Sivakumar S - CTD, Chennai. [mailto:sivakumars@xxxxxxxxxxx]
Sent: Wednesday, September 14, 2005 6:55 AM
To: Grone, Joseph; imc-snacc@xxxxxxx
Cc: Kaliraj Kalaichelvan - CTD, Chennai
Subject: RE: UniversalString throws exception
Joe,
I have installed the patch and tried again.
I am getting the same error (Only the error code is changed from 665 to
688).
I have given below the piece of code I tried:
int main()
{
UniversalString ustr;
char ich[32]="Lé Royal Meridian";
unsigned char och[32];
try
{
ustr.set((const char *)&ich[0]);
strcpy((char *)&och[0],ustr.getAsUTF8());
}
catch(SnaccException &se)
{
se.getCallStack(std::cout);
cout << "Exception thrown Snacc " <<se.what()<< endl;
}
catch(exception &e)
{
cout << "Exception thrown : " <<e.what()<< endl;
}
return 0;
}
Output:
asn-stringtype.cpp 688 WideAsnString::set()
Exception Thrown Snacc Invalid UTF-8 string
Thanks,
Siva
-----Original Message-----
From: Grone, Joseph
To: Sivakumar S - CTD, Chennai.; imc-snacc@xxxxxxx
Cc: kalirajk@xxxxxxxxxxx
Sent: 13/09/2005 20:21
Subject: RE: UniversalString throws exception
Before I troubleshoot this problem, I want to make sure that you have
the July 7, 2005 patch installed for eSNACC found here:
http://www.digitalnet.com/knowledge/download.htm
--Joe
-----Original Message-----
From: owner-imc-snacc@xxxxxxxxxxxx [mailto:owner-imc-snacc@xxxxxxxxxxxx]
On Behalf Of Sivakumar S - CTD, Chennai.
Sent: Tuesday, September 13, 2005 10:28 AM
To: imc-snacc@xxxxxxx
Subject: UniversalString throws exception
Importance: High
Hello,
I face a problem with eSNACC (I am using version 1.7).
The ASN throws some exception when I use French characters.
For example, there is one ASN data type called UniversalString.
When I try to store a value "ü" inside the UniversalString it throws an
exception saying "UTF8string invalid".
The storing procedure is the same. It works fine for all English
characters
but when try to use it for French characters like ü or ä like this it
doesnt
work.
Is there a possibility at the code generation time itself (while
generating
VNP_message set.cpp and .h from ASN.1) to make it support these
characters.
Kindly help
Thanks,
Siva
DISCLAIMER
This message and any attachment(s) contained here are information that
is confidential, proprietary to HCL Technologies
and its customers. Contents may be privileged or otherwise protected by
law. The information is solely intended for the
individual or the entity it is addressed to. If you are not the intended
recipient of this message, you are not authorized to
read, forward, print, retain, copy or disseminate this message or any
part of it. If you have received this e-mail in error,
please notify the sender immediately by return e-mail and delete it from
your computer