Bump libdcp.
[libsub.git] / src / locale_convert.cc
1 /*
2     Copyright (C) 2014-2019 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "locale_convert.h"
21 #include <cstdio>
22
23 using std::string;
24
25 template<>
26 string
27 sub::locale_convert (int x, int, bool)
28 {
29         char buffer[64];
30         snprintf (buffer, sizeof(buffer), "%d", x);
31         return buffer;
32 }
33
34 template<>
35 string
36 sub::locale_convert (long int x, int, bool)
37 {
38         char buffer[64];
39 #ifdef LIBSUB_WINDOWS
40         __mingw_snprintf (buffer, sizeof(buffer), "%ld", x);
41 #else
42         snprintf (buffer, sizeof(buffer), "%ld", x);
43 #endif
44         return buffer;
45 }
46
47 template<>
48 string
49 sub::locale_convert (unsigned long int x, int, bool)
50 {
51         char buffer[64];
52         snprintf (buffer, sizeof(buffer), "%lu", x);
53         return buffer;
54 }
55
56 template<>
57 string
58 sub::locale_convert (unsigned long long x, int, bool)
59 {
60         char buffer[64];
61 #ifdef LIBSUB_WINDOWS
62         __mingw_snprintf (buffer, sizeof(buffer), "%lld", x);
63 #else
64         snprintf (buffer, sizeof(buffer), "%lld", x);
65 #endif
66         return buffer;
67 }
68
69 template<>
70 string
71 sub::locale_convert (string x, int, bool)
72 {
73         return x;
74 }
75
76 template<>
77 int
78 sub::locale_convert (string x, int, bool)
79 {
80         int y = 0;
81         sscanf (x.c_str(), "%d", &y);
82         return y;
83 }
84
85 template<>
86 float
87 sub::locale_convert (string x, int, bool)
88 {
89         float y = 0;
90         sscanf (x.c_str(), "%f", &y);
91         return y;
92 }