Display locale currency symbol using ICU C API? - c

I need to know how to use the ICU4C version 52 C API to display the locale Currency Symbol and code. i.e. ($ - USD)

There is probably more than one way how to do this. Here is one, that I think should work (untested):
Get the number format and format the value using it:
UErrorCode success = U_ZERO_ERROR;
UNumberFormat *nf;
const char* myLocale = "fr_FR";
// get locale specific number format
nf = unum_open( UNUM_CURRENCY, myLocale, success );
// use it to format the value
UChar buf[100];
unum_formatDouble (nf, 10.0, buf, 100, NULL, &success);
// close the format handle
unum_close(nf);

Or, more directly, use ucurr_getName() with the UCURR_SYMBOL_NAME selector. You can also use ucurr_forLocale() or ucurr_forLocaleAndDate() to get the currency code without needing a formatter. Note that there can be multiple currencies for a locale.

Related

Could not find the entrypoint _pcre2_compile#40. (3260)

I have built a libpcre2-8.dll with the help of this Git Repo.
I'm now trying to access the function pcre2_compile from an ABL (Progress) program. (Progress is an old 4GL Language). I'm constantly hitting the error
Could not find the entrypoint _pcre2_compile#40. (3260)
I've already tried many things but it still doesn't work.
The Dynamic Library is 64 bit and Progress is also running in 64 bit.
In ABL (Progress) you can specify the LIBRARY-CALLING-CONVENTION but whether I set it to STDCALL or CDECL or just don't specify it, the error remains the same.
This is a snippet of the Progress ABL I'm trying to execute the function: (code comes from this Git Repo, which works, but only for 32 bit)
PROCEDURE pcre2_compile :
DEFINE INPUT PARAMETER pattern AS CHARACTER. /* const char * */
DEFINE INPUT PARAMETER options AS INTEGER. /* int */
DEFINE OUTPUT PARAMETER errcodeptr AS INTEGER. /* int * */
DEFINE OUTPUT PARAMETER errptr AS MEMPTR. /* const char ** */
DEFINE OUTPUT PARAMETER erroffset AS MEMPTR. /* int * */
DEFINE INPUT PARAMETER tableptr AS INTEGER. /* const unsigned char * */
DEFINE OUTPUT PARAMETER result AS MEMPTR. /* pcre * */
DEFINE VARIABLE libName AS CHARACTER NO-UNDO.
DEFINE VARIABLE hCall AS HANDLE NO-UNDO.
libName = get-library().
CREATE CALL hCall.
ASSIGN
hCall:CALL-NAME = "pcre2_compile"
hCall:LIBRARY = "lib/libpcre2-8.dll"
//hCall:LIBRARY-CALLING-CONVENTION = "STDCALL"
hCall:CALL-TYPE = DLL-CALL-TYPE
hCall:NUM-PARAMETERS = 6
hCall:RETURN-VALUE-DLL-TYPE = "MEMPTR".
hCall:SET-PARAMETER(1, "CHARACTER", "INPUT" , pattern ).
hCall:SET-PARAMETER(2, "LONG" , "INPUT" , options ).
hCall:SET-PARAMETER(3, "HANDLE TO LONG" , "OUTPUT", errcodeptr ).
hCall:SET-PARAMETER(4, "MEMPTR" , "OUTPUT", errptr ).
hCall:SET-PARAMETER(5, "MEMPTR" , "OUTPUT", erroffset ).
hCall:SET-PARAMETER(6, "LONG" , "INPUT" , tableptr ).
hCall:INVOKE().
ASSIGN result = hCall:RETURN-VALUE.
DELETE OBJECT hCall.
END PROCEDURE.
What am I missing?
Update: Checked with Dependency Walker and the functions seem to be visible. They do have a _8 suffix... But even when trying pcre2_compile_8 it still gives me the same error.
I think that you need to change your long integers to INT64.
Is the entrypoint externally visible/accesible?
I've used https://dependencywalker.com/ in the past to figure that out.
Does that change if you specify the ORDINAL option ?
So the problem was that the name of the entry point was "pcre2_compile_8" instead of "pcre2_compile"... Wanted to delete the question because now it looks quite dumb but leaving it anyway...

Parse JSON message manually in C

I need to parse manually, without external libraries, a JSON message coming from a server, in C language.
The message coming from server would be like:
{[CR+LF]
"Tmg": "R",[CR+LF]
"STP": 72[CR+LF]
}[CR+LF]
or
{[CR+LF]
"Tmg": "R",[CR+LF]
"STP": 150[CR+LF]
}[CR+LF]
I need the number after STP:. The number is different in each message structure, so I need to get that number from the JSON structure. I can't use external libraries because this code is in an embedded system and exernal code is not allowed.
I tried this following:
int main (){
const char response_message[35] = "{\r\n\"Tmg\":\"R\",\r\n\"STP\":72,\r\n}";
const char needle[8] = "P\":";
char *ret;
ret = strstr(response_message, needle);
printf("The number is: %s\n", ret);
return 0;
}
But obviously, I am getting this result:
The number is: P":72,
}
So I need to only get the number, how can I get this?
Thanks
You can use a hacked solution. Use strstr () to find "STP": then find the following , or } and extract the digits in between.
And that's a hack. Not guaranteed to work. For something that's guaranteed to work, you use a JSON parser.

Why can't I display emoji on Pebble using Symbola font?

I added the Symbola font to my watch app, and tried to display some emoji on the Pebble, but alas, no dice.
Here's the relevant vars and functions in my codeā€¦ be gentle, I'm kind of a C n00b.
Is this even the proper way to format unicode for a C string? I added the colons just as separators.
static char emoji_chars[]=":\xF0\x9F\x98\x81:\xF0\x9F\x98\x93:";
void handle_init(AppContextRef ctx) {
(void)ctx;
window_init(&window, "Window Name");
window_stack_push(&window, true /* Animated */);
text_layer_init(&emoji_layer, GRect(30, 30, 150, 50));
text_layer_set_background_color(&emoji_layer, GColorWhite);
text_layer_set_text_color(&emoji_layer, GColorBlack);
text_layer_set_font(&emoji_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SYMBOLA_24)));
text_layer_set_text(&emoji_layer, emoji_chars);
layer_add_child(&window.layer, &emoji_layer.layer);
}
void pbl_main(void *params) {
resource_init_current_app(&APP_RESOURCES);
PebbleAppHandlers handlers = {
.init_handler = &handle_init
};
app_event_loop(params, &handlers);
}
The documentation says on the argument of text_layer_set_text
The new text to set onto the TextLayer. This must be a null-terminated and valid UTF-8 string!
(note the exclamation point). "Unicode" is not a valid C string encoding, but "UTF-8" is. Inserting your icons' Unicode values as UTF-8 characters should work.
Edit
Hold on -- you already encoded the character U+1F601 as UTF-8. And it is a valid character in your font, according to http://users.teilar.gr/~g1951d/Symbola.pdf.
Have you in the font resource manifest specified those emoji characters in the characterRegex?
I also see that there is a patch for fontgen.py to include unicode here That may assist you.
https://github.com/fisakov/pebble-sdk-characterRegex

How to retrieve video format using cvGetCaptureProperty

I am trying to retrieve the video format
Ex. my input video file is video.mpeg then I want format as mpeg
I used this function
double Format = cvGetCapturePrperty(capture,CV_CAP_PROP_FORMAT);
but it returns 0.000
Please help.
Thanks.
CV_CAP_PROP_FORMAT is not what you think. Check the documentation.
You are probably looking for:
double val = cvGetCaptureProperty( capture, CV_CAP_PROP_FOURCC );
char* fourcc = (char*) (&val);

Implementation code for GetDateFormat Win32 function

I am porting some legacy code from windows to Linux (Ubuntu Karmic to be precise).
I have come across a Win32 function GetDateFormat().
The statements I need to port over are called like this:
GetDateFormat(LOCALE_USER_DEFAULT, 0, &datetime, "MMMM", 'January', 31);
OR
GetDateFormat(LOCALE_USER_DEFAULT, 0, &datetime, "MMMM", 'May', 30);
Where datetime is a SYSTEMTIME struct.
Does anyone know where I can get the code for the function - or failing that, tips on how to "roll my own" equivalent function?
The Linux equivalent (actually, plain ANSI C) to a call to GetDateFormat like this:
GetDateFormat(LOCALE_USER_DEFAULT, 0, &datetime, "MMMM", date_str, len);
is:
char *old_lc_time;
/* Set LC_TIME locale to user default */
old_lc_time = setlocale(LC_TIME, NULL);
setlocale(LC_TIME, "");
strftime(date_str, len, "%B", &datetime);
/* Set LC_TIME locale back */
setlocale(LC_TIME, old_lc_time);
(where datetime is now a struct tm rather than a SYSTEMTIME)
You may not need to worry about setting the locale each time and setting it back - if you are happy for all of your date/time formatting to be done in the user default locale (which is usual), then you can just call setlocale(LC_TIME, ""); once at program startup and be done with it.
Note however that the values your code is passing to GetDateFormat in the lpDateStr and cchDate parameters (second-last and last respectively) do not make sense. 'January' is a character constant, when it should be a pointer to a buffer where GetDateFormat will place its result.
The Win32 GetDateFormat function should be equivalent to the strftime function in the time.h header.

Resources