From: Zoltan B. <zb...@du...> - 2005-05-14 19:37:30
|
Zoltan Boszormenyi =EDrta: > [val() (and other functions?)] doesn't conform to the locale settings, = it prints > decimal dots. I am investigating it. How about changing rlib's locale behaviour? I found that rlib_set_locale() changes the current locale but doesn't save the current setting. I would expect the following behaviour: - If rlib_set_locale() was called, convert the given setting to UTF-8 with make_utf8_locale() and save it. Also notice in struct rlib that we have set the locale. - On every RLIB API call entry, remember the current locale locally. - If rlib_set_locale() was called, make the saved/converted setting current. - If rlib_set_locale() wasn't called, convert the currently set locale to utf8, make it current. (*) - On exiting from the API call, restore the old locale we saved on entry. (*) I know it makes RLIB slower but I don't know how much. I would have to benchmark setlocale(). It may also be a NOP if the current locale is already UTF-8 but you cannot know that The advantage of the above is that RLIB doesn't suppose anything about the current locale, e.g. one can play games with setlocale() between RLIB API calls, so the locale setting may be different from the one before rlib_init(). Call chains like this: /************************************************/ rlib_function1() { /* save locale */ /* do something */ /* restore locale */ } rlib_function2() { /* save locale */ /* do something that involves calling rlib_function1() */ /* restore locale */ } /************************************************/ should be modified to this: /************************************************/ rlib_function1_internals() { /* do something */ } rlib_function1() { /* save locale */ rlib_function1_internals(); /* restore locale */ } rlib_function2() { /* save locale */ /* do something that involves calling rlib_function1_internals() */ /* restore locale */ } /************************************************/ so it doesn't make it even slower. It wouldn't cause bugs, follow my proof: Suppose the current locale is hu_HU in my application, rlib_set_locale() is not called. The scenario would be: 1. In function2(): save current locale (hu_HU), convert it to UTF-8 -> hu_HU.utf8, call function1(). 2. In function1(): save current locale (hu_HU.utf8), convert it to UTF-8, that's a NOP but extra work. On exit, restore the saved hu_HU.utf8. 3. On exit from function2(), restore hu_HU. The other scenario is when I call rlib_set_locale() with e.g. en_US. That seems to be converted to UTF-8 internally. 1. In function2(): save current locale (hu_HU), set the saved one (en_US.utf8), call function1(). 2. In function1(): save the current locale (en_US.utf8) and set the saved one (en_US.utf8), again a NOP with extra work done. On exit, restore en_US.utf-8. 3. On exit from function2(), restore hu_HU. Best regards, Zolt=E1n B=F6sz=F6rm=E9nyi |