]> git.lyx.org Git - lyx.git/blob - src/support/convert.cpp
Add quote style information to languages
[lyx.git] / src / support / convert.cpp
1 /**
2  * \file convert.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "support/convert.h"
15 #include "support/docstring.h"
16
17 #include <boost/lexical_cast.hpp>
18
19 #include <string>
20 #include <cstdlib>
21
22 using namespace std;
23
24 namespace lyx {
25
26 using boost::lexical_cast;
27
28 template<>
29 string convert<string>(bool b)
30 {
31         return (b ? "true" : "false");
32 }
33
34
35 template<>
36 string convert<string>(char c)
37 {
38         return string(1, c);
39 }
40
41
42 template<>
43 string convert<string>(short unsigned int sui)
44 {
45         return lexical_cast<string>(sui);
46 }
47
48
49 template<>
50 string convert<string>(int i)
51 {
52         return lexical_cast<string>(i);
53 }
54
55
56 template<>
57 docstring convert<docstring>(int i)
58 {
59         return from_ascii(lexical_cast<string>(i));
60 }
61
62
63 template<>
64 string convert<string>(unsigned int ui)
65 {
66         return lexical_cast<string>(ui);
67 }
68
69
70 template<>
71 docstring convert<docstring>(unsigned int ui)
72 {
73         return from_ascii(lexical_cast<string>(ui));
74 }
75
76
77 template<>
78 string convert<string>(unsigned long ul)
79 {
80         return lexical_cast<string>(ul);
81 }
82
83
84 template<>
85 docstring convert<docstring>(unsigned long ul)
86 {
87         return from_ascii(lexical_cast<string>(ul));
88 }
89
90
91 template<>
92 string convert<string>(long l)
93 {
94         return lexical_cast<string>(l);
95 }
96
97
98 template<>
99 docstring convert<docstring>(long l)
100 {
101         return from_ascii(lexical_cast<string>(l));
102 }
103
104
105 template<>
106 string convert<string>(float f)
107 {
108         return lexical_cast<string>(f);
109 }
110
111
112 template<>
113 string convert<string>(double d)
114 {
115         return lexical_cast<string>(d);
116 }
117
118
119 template<>
120 int convert<int>(string const s)
121 {
122         return strtol(s.c_str(), 0, 10);
123 }
124
125
126 template<>
127 int convert<int>(docstring const s)
128 {
129         return strtol(to_ascii(s).c_str(), 0, 10);
130 }
131
132
133 template<>
134 unsigned int convert<unsigned int>(string const s)
135 {
136         return strtoul(s.c_str(), 0, 10);
137 }
138
139
140 template<>
141 unsigned long convert<unsigned long>(string const s)
142 {
143         return strtoul(s.c_str(), 0, 10);
144 }
145
146
147 template<>
148 double convert<double>(string const s)
149 {
150         return strtod(s.c_str(), 0);
151 }
152
153
154 template<>
155 int convert<int>(char const * cptr)
156 {
157         return strtol(cptr, 0, 10);
158 }
159
160
161 template<>
162 double convert<double>(char const * cptr)
163 {
164         return strtod(cptr, 0);
165 }
166
167
168 } // namespace lyx