B
braj
Hi Friends,
I was trying a test code to use the icu stuff with variable arguments
and I seem to be heading nowhere.
Can anyone please help.
Given below is the test code and the Output.
Thanks a ton in advance
-braj
#include <stdio.h>
#include <stdarg.h>
#include "unicode/utypes.h"
#include <stdlib.h>
#include <string.h>
#include "unicode/uloc.h"
#include "unicode/umsg.h"
#include "unicode/urename.h"
#include "unicode/ustring.h" /* required for UERROR CODE u_strlen
etc... */
void msgCall(const char *msgid, char *type, ...);
int main()
{
printf("here is goes \n");
msgCall("MSG_VFI_E0332", "HELLO" , "%s: something %s : follows : %s
nothing\n", "ONE", "TWO", "THREE");
return 0;
}
void msgCall(const char *msgid, char *type, ...)
{
char *fmt = NULL, *lfmt = NULL, *lmsg = NULL, *msg = NULL;
va_list ap;
char *finalstr;
UChar *result;
UChar pattern[2048];
int32_t resultlength, resultLengthOut;
UErrorCode status = U_ZERO_ERROR;
char *message = "CLI Tool {0} could not be {1} found with {2}
ending";
int len = 0;
u_uastrcpy(pattern, message);
va_start(ap, type);
fmt = va_arg(ap, char *);
resultlength=0;
resultLengthOut=u_vformatMessage("en_US", pattern, resultlength,
NULL, resultlength, ap, &status);
if(status == U_BUFFER_OVERFLOW_ERROR) {
status = U_ZERO_ERROR;
resultlength = resultLengthOut+1;
result = (UChar *)malloc(sizeof(UChar) * resultlength);
u_vformatMessage("en_US", pattern, resultlength, result,
resultlength, ap, &status);
}
len = u_strlen(result);
finalstr = (char*)malloc(sizeof(char) * (len + 1));
u_austrcpy(finalstr, result);
printf("finalstr = [%s]\n", finalstr);
va_end(ap);
}
/* OUTPUT of the above */
here is goes
finalstr = [CLI Tool ä¹E could not be åOä¹E found with ä¡äEåOä¹E
ending]
I was trying a test code to use the icu stuff with variable arguments
and I seem to be heading nowhere.
Can anyone please help.
Given below is the test code and the Output.
Thanks a ton in advance
-braj
#include <stdio.h>
#include <stdarg.h>
#include "unicode/utypes.h"
#include <stdlib.h>
#include <string.h>
#include "unicode/uloc.h"
#include "unicode/umsg.h"
#include "unicode/urename.h"
#include "unicode/ustring.h" /* required for UERROR CODE u_strlen
etc... */
void msgCall(const char *msgid, char *type, ...);
int main()
{
printf("here is goes \n");
msgCall("MSG_VFI_E0332", "HELLO" , "%s: something %s : follows : %s
nothing\n", "ONE", "TWO", "THREE");
return 0;
}
void msgCall(const char *msgid, char *type, ...)
{
char *fmt = NULL, *lfmt = NULL, *lmsg = NULL, *msg = NULL;
va_list ap;
char *finalstr;
UChar *result;
UChar pattern[2048];
int32_t resultlength, resultLengthOut;
UErrorCode status = U_ZERO_ERROR;
char *message = "CLI Tool {0} could not be {1} found with {2}
ending";
int len = 0;
u_uastrcpy(pattern, message);
va_start(ap, type);
fmt = va_arg(ap, char *);
resultlength=0;
resultLengthOut=u_vformatMessage("en_US", pattern, resultlength,
NULL, resultlength, ap, &status);
if(status == U_BUFFER_OVERFLOW_ERROR) {
status = U_ZERO_ERROR;
resultlength = resultLengthOut+1;
result = (UChar *)malloc(sizeof(UChar) * resultlength);
u_vformatMessage("en_US", pattern, resultlength, result,
resultlength, ap, &status);
}
len = u_strlen(result);
finalstr = (char*)malloc(sizeof(char) * (len + 1));
u_austrcpy(finalstr, result);
printf("finalstr = [%s]\n", finalstr);
va_end(ap);
}
/* OUTPUT of the above */
here is goes
finalstr = [CLI Tool ä¹E could not be åOä¹E found with ä¡äEåOä¹E
ending]