summaryrefslogtreecommitdiff
path: root/libs/pbd/localeguard.cc
blob: 12093beeaa973997e0414234942b8829b8f2608c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <cstring>
#include <locale.h>
#include <stdlib.h>

#include "pbd/localeguard.h"

// JE - added temporarily, to reduce the delay effects when calling
// setlocale() recursively in a Windows GUI thread (we should think
// about moving the caller(s) into a dedicated worker thread).
std::string PBD::LocaleGuard::current;

PBD::LocaleGuard::LocaleGuard (const char* str)
 : old(0)
{
	if (current != str) {
		old = strdup (setlocale (LC_NUMERIC, NULL));
		if (strcmp (old, str)) {
			if (setlocale (LC_NUMERIC, str))
				current = str; 
		}
	}
}

PBD::LocaleGuard::~LocaleGuard ()
{
	if (old) {
		if (setlocale (LC_NUMERIC, old))
			current = old;

		free ((char*)old);
	}
}