avoid a set of calls to gettext() and/or cousins from global constructor scope
[ardour.git] / libs / pbd / localeguard.cc
1 #include <cstring>
2 #include <locale.h>
3 #include <stdlib.h>
4
5 #include "pbd/localeguard.h"
6
7 // JE - added temporarily, to reduce the delay effects when calling
8 // setlocale() recursively in a Windows GUI thread (we should think
9 // about moving the caller(s) into a dedicated worker thread).
10 std::string PBD::LocaleGuard::current;
11
12 PBD::LocaleGuard::LocaleGuard (const char* str)
13  : old(0)
14 {
15         if (current != str) {
16                 old = strdup (setlocale (LC_NUMERIC, NULL));
17                 if (strcmp (old, str)) {
18                         if (setlocale (LC_NUMERIC, str))
19                                 current = str; 
20                 }
21         }
22 }
23
24 PBD::LocaleGuard::~LocaleGuard ()
25 {
26         if (old) {
27                 if (setlocale (LC_NUMERIC, old))
28                         current = old;
29
30                 free ((char*)old);
31         }
32 }
33
34