Browse code

fix mingw build, clean up new warnings

Adam Higerd authored on 2021/02/11 17:42:05
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,183 +0,0 @@
1
-// This comes from llvm's libcxx project. I've copied the code from there (with very minor modifications) for use with GCC and Clang when libcxx isn't being used.
2
-
3
-#if (defined(__GNUC__) || defined(__clang__)) && !defined(_LIBCPP_VERSION)
4
-#pragma once
5
-
6
-#include <memory>
7
-#include <string>
8
-#include <locale>
9
-
10
-namespace std
11
-{
12
-
13
-template<class _Codecvt, class _Elem = wchar_t, class _Wide_alloc = allocator<_Elem>, class _Byte_alloc = allocator<char>> class wstring_convert
14
-{
15
-public:
16
-	typedef basic_string<char, char_traits<char>, _Byte_alloc> byte_string;
17
-	typedef basic_string<_Elem, char_traits<_Elem>, _Wide_alloc> wide_string;
18
-	typedef typename _Codecvt::state_type state_type;
19
-	typedef typename wide_string::traits_type::int_type int_type;
20
-
21
-private:
22
-	byte_string __byte_err_string_;
23
-	wide_string __wide_err_string_;
24
-	_Codecvt *__cvtptr_;
25
-	state_type __cvtstate_;
26
-	size_t __cvtcount_;
27
-
28
-	wstring_convert(const wstring_convert &__wc);
29
-	wstring_convert& operator=(const wstring_convert &__wc);
30
-public:
31
-	wstring_convert(_Codecvt *__pcvt = new _Codecvt) : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) { }
32
-	wstring_convert(_Codecvt *__pcvt, state_type __state) : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) { }
33
-	wstring_convert(const byte_string &__byte_err, const wide_string &__wide_err = wide_string()) : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), __cvtptr_(new _Codecvt), __cvtstate_(), __cvtcount_(0) { }
34
-	wstring_convert(wstring_convert &&__wc) : __byte_err_string_(move(__wc.__byte_err_string_)), __wide_err_string_(move(__wc.__wide_err_string_)), __cvtptr_(__wc.__cvtptr_), __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtstate_)
35
-	{
36
-		__wc.__cvtptr_ = nullptr;
37
-	}
38
-	~wstring_convert() { delete this->__cvtptr_; }
39
-
40
-	wide_string from_bytes(char __byte) { return from_bytes(&__byte, &__byte + 1); }
41
-	wide_string from_bytes(const char *__ptr) { return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr)); }
42
-	wide_string from_bytes(const byte_string &__str) { return from_bytes(__str.data(), __str.data() + __str.size()); }
43
-	wide_string from_bytes(const char *__frm, const char *__frm_end)
44
-	{
45
-		this->__cvtcount_ = 0;
46
-		if (this->__cvtptr_)
47
-		{
48
-			wide_string __ws(2 * (__frm_end - __frm), _Elem());
49
-			if (__frm != __frm_end)
50
-				__ws.resize(__ws.capacity());
51
-			auto __r = codecvt_base::ok;
52
-			auto __st = this->__cvtstate_;
53
-			if (__frm != __frm_end)
54
-			{
55
-				auto __to = &__ws[0];
56
-				auto __to_end = __to + __ws.size();
57
-				const char *__frm_nxt;
58
-				do
59
-				{
60
-					_Elem *__to_nxt;
61
-					__r = this->__cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
62
-					this->__cvtcount_ += __frm_nxt - __frm;
63
-					if (__frm_nxt == __frm)
64
-						__r = codecvt_base::error;
65
-					else if (__r == codecvt_base::noconv)
66
-					{
67
-						__ws.resize(__to - &__ws[0]);
68
-						// This only gets executed if _Elem is char
69
-						__ws.append(reinterpret_cast<const _Elem *>(__frm), reinterpret_cast<const _Elem *>(__frm_end));
70
-						__frm = __frm_nxt;
71
-						__r = codecvt_base::ok;
72
-					}
73
-					else if (__r == codecvt_base::ok)
74
-					{
75
-						__ws.resize(__to_nxt - &__ws[0]);
76
-						__frm = __frm_nxt;
77
-					}
78
-					else if (__r == codecvt_base::partial)
79
-					{
80
-						ptrdiff_t __s = __to_nxt - &__ws[0];
81
-						__ws.resize(2 * __s);
82
-						__to = &__ws[0] + __s;
83
-						__to_end = &__ws[0] + __ws.size();
84
-						__frm = __frm_nxt;
85
-					}
86
-				} while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
87
-			}
88
-			if (__r == codecvt_base::ok)
89
-				return __ws;
90
-		}
91
-		if (this->__wide_err_string_.empty())
92
-			throw range_error("wstring_convert: from_bytes error");
93
-		return this->__wide_err_string_;
94
-	}
95
-
96
-	byte_string to_bytes(_Elem __wchar) { return to_bytes(&__wchar, &__wchar + 1); }
97
-	byte_string to_bytes(const _Elem *__wptr) { return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr)); }
98
-	byte_string to_bytes(const wide_string &__wstr) { return to_bytes(__wstr.data(), __wstr.data() + __wstr.size()); }
99
-	byte_string to_bytes(const _Elem *__frm, const _Elem *__frm_end)
100
-	{
101
-		this->__cvtcount_ = 0;
102
-		if (this->__cvtptr_)
103
-		{
104
-			byte_string __bs(2 * (__frm_end - __frm), char());
105
-			if (__frm != __frm_end)
106
-				__bs.resize(__bs.capacity());
107
-			auto __r = codecvt_base::ok;
108
-			auto __st = this->__cvtstate_;
109
-			if (__frm != __frm_end)
110
-			{
111
-				auto __to = &__bs[0];
112
-				auto __to_end = __to + __bs.size();
113
-				const _Elem *__frm_nxt;
114
-				do
115
-				{
116
-					char *__to_nxt;
117
-					__r = this->__cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
118
-					this->__cvtcount_ += __frm_nxt - __frm;
119
-					if (__frm_nxt == __frm)
120
-						__r = codecvt_base::error;
121
-					else if (__r == codecvt_base::noconv)
122
-					{
123
-						__bs.resize(__to - &__bs[0]);
124
-						// This only gets executed if _Elem is char
125
-						__bs.append(reinterpret_cast<const char *>(__frm), reinterpret_cast<const char *>(__frm_end));
126
-						__frm = __frm_nxt;
127
-						__r = codecvt_base::ok;
128
-					}
129
-					else if (__r == codecvt_base::ok)
130
-					{
131
-						__bs.resize(__to_nxt - &__bs[0]);
132
-						__frm = __frm_nxt;
133
-					}
134
-					else if (__r == codecvt_base::partial)
135
-					{
136
-						ptrdiff_t __s = __to_nxt - &__bs[0];
137
-						__bs.resize(2 * __s);
138
-						__to = &__bs[0] + __s;
139
-						__to_end = &__bs[0] + __bs.size();
140
-						__frm = __frm_nxt;
141
-					}
142
-				} while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
143
-			}
144
-			if (__r == codecvt_base::ok)
145
-			{
146
-				auto __s = __bs.size();
147
-				__bs.resize(__bs.capacity());
148
-				auto __to = &__bs[0] + __s;
149
-				auto __to_end = __to + __bs.size();
150
-				do
151
-				{
152
-					char *__to_nxt;
153
-					__r = this->__cvtptr_->unshift(__st, __to, __to_end, __to_nxt);
154
-					if (__r == codecvt_base::noconv)
155
-					{
156
-						__bs.resize(__to - &__bs[0]);
157
-						__r = codecvt_base::ok;
158
-					}
159
-					else if (__r == codecvt_base::ok)
160
-						__bs.resize(__to_nxt - &__bs[0]);
161
-					else if (__r == codecvt_base::partial)
162
-					{
163
-						ptrdiff_t __sp = __to_nxt - &__bs[0];
164
-						__bs.resize(2 * __sp);
165
-						__to = &__bs[0] + __sp;
166
-						__to_end = &__bs[0] + __bs.size();
167
-					}
168
-				} while (__r == codecvt_base::partial);
169
-				if (__r == codecvt_base::ok)
170
-					return __bs;
171
-			}
172
-		}
173
-		if (this->__byte_err_string_.empty())
174
-			throw range_error("wstring_convert: to_bytes error");
175
-		return this->__byte_err_string_;
176
-	}
177
-
178
-	size_t converted() const noexcept { return this->__cvtcount_; }
179
-	state_type state() const { return this->__cvtstate_; }
180
-};
181
-
182
-}
183
-#endif
Browse code

* Small Makefile changes.

* Removed a couple files that were not being used.
* Cleanups found with clang's -Weverything (and shutting it up about a
lot of things that were ridiculous, as well as ignoring some of the
warnings still coming up).

Naram Qashat authored on 2014/09/25 12:28:21
Showing 1 changed files
... ...
@@ -175,9 +175,9 @@ public:
175 175
 		return this->__byte_err_string_;
176 176
 	}
177 177
 
178
-	size_t converted() const throw() { return this->__cvtcount_; }
178
+	size_t converted() const noexcept { return this->__cvtcount_; }
179 179
 	state_type state() const { return this->__cvtstate_; }
180 180
 };
181 181
 
182
-};
182
+}
183 183
 #endif
Browse code

Lots of changes in regards to strings, as follows:

* Removed my custom String class, as well as removed the really old
Unicode ConvertUTF, the UTF Converter, and the UTF Encode/Decode
functions.
* Replaced the above with using standard C++ std::wstring_convert and
std::codecvt_utf8.
* Added headers adapted from llvm's libc++ project for allowing the
above C++ classes to exist with GCC and Clang when libc++ isn't being
used.
* Used std::string over std::wstring whenever possible.
* Added header adapted from llvm's libc++ project to create special
versions of the ifstream and ofstream classes that would utilize _wfopen
on non-MSVC Windows compilers, so those compilers could access files on
Windows that use characters outside the current codepage.
* Removed the -static-libgcc and -static-libstdc++ flags from the
Makefile for non-MSVC builds. The generated DLLs will require extra DLLs
from either Cygwin or MinGW (whichever is used to compile), I've only
tested with MinGW and for some reason they crash Winamp on exit, I have
no idea why.

Naram Qashat authored on 2014/09/24 13:58:55
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,183 @@
1
+// This comes from llvm's libcxx project. I've copied the code from there (with very minor modifications) for use with GCC and Clang when libcxx isn't being used.
2
+
3
+#if (defined(__GNUC__) || defined(__clang__)) && !defined(_LIBCPP_VERSION)
4
+#pragma once
5
+
6
+#include <memory>
7
+#include <string>
8
+#include <locale>
9
+
10
+namespace std
11
+{
12
+
13
+template<class _Codecvt, class _Elem = wchar_t, class _Wide_alloc = allocator<_Elem>, class _Byte_alloc = allocator<char>> class wstring_convert
14
+{
15
+public:
16
+	typedef basic_string<char, char_traits<char>, _Byte_alloc> byte_string;
17
+	typedef basic_string<_Elem, char_traits<_Elem>, _Wide_alloc> wide_string;
18
+	typedef typename _Codecvt::state_type state_type;
19
+	typedef typename wide_string::traits_type::int_type int_type;
20
+
21
+private:
22
+	byte_string __byte_err_string_;
23
+	wide_string __wide_err_string_;
24
+	_Codecvt *__cvtptr_;
25
+	state_type __cvtstate_;
26
+	size_t __cvtcount_;
27
+
28
+	wstring_convert(const wstring_convert &__wc);
29
+	wstring_convert& operator=(const wstring_convert &__wc);
30
+public:
31
+	wstring_convert(_Codecvt *__pcvt = new _Codecvt) : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) { }
32
+	wstring_convert(_Codecvt *__pcvt, state_type __state) : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) { }
33
+	wstring_convert(const byte_string &__byte_err, const wide_string &__wide_err = wide_string()) : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), __cvtptr_(new _Codecvt), __cvtstate_(), __cvtcount_(0) { }
34
+	wstring_convert(wstring_convert &&__wc) : __byte_err_string_(move(__wc.__byte_err_string_)), __wide_err_string_(move(__wc.__wide_err_string_)), __cvtptr_(__wc.__cvtptr_), __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtstate_)
35
+	{
36
+		__wc.__cvtptr_ = nullptr;
37
+	}
38
+	~wstring_convert() { delete this->__cvtptr_; }
39
+
40
+	wide_string from_bytes(char __byte) { return from_bytes(&__byte, &__byte + 1); }
41
+	wide_string from_bytes(const char *__ptr) { return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr)); }
42
+	wide_string from_bytes(const byte_string &__str) { return from_bytes(__str.data(), __str.data() + __str.size()); }
43
+	wide_string from_bytes(const char *__frm, const char *__frm_end)
44
+	{
45
+		this->__cvtcount_ = 0;
46
+		if (this->__cvtptr_)
47
+		{
48
+			wide_string __ws(2 * (__frm_end - __frm), _Elem());
49
+			if (__frm != __frm_end)
50
+				__ws.resize(__ws.capacity());
51
+			auto __r = codecvt_base::ok;
52
+			auto __st = this->__cvtstate_;
53
+			if (__frm != __frm_end)
54
+			{
55
+				auto __to = &__ws[0];
56
+				auto __to_end = __to + __ws.size();
57
+				const char *__frm_nxt;
58
+				do
59
+				{
60
+					_Elem *__to_nxt;
61
+					__r = this->__cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
62
+					this->__cvtcount_ += __frm_nxt - __frm;
63
+					if (__frm_nxt == __frm)
64
+						__r = codecvt_base::error;
65
+					else if (__r == codecvt_base::noconv)
66
+					{
67
+						__ws.resize(__to - &__ws[0]);
68
+						// This only gets executed if _Elem is char
69
+						__ws.append(reinterpret_cast<const _Elem *>(__frm), reinterpret_cast<const _Elem *>(__frm_end));
70
+						__frm = __frm_nxt;
71
+						__r = codecvt_base::ok;
72
+					}
73
+					else if (__r == codecvt_base::ok)
74
+					{
75
+						__ws.resize(__to_nxt - &__ws[0]);
76
+						__frm = __frm_nxt;
77
+					}
78
+					else if (__r == codecvt_base::partial)
79
+					{
80
+						ptrdiff_t __s = __to_nxt - &__ws[0];
81
+						__ws.resize(2 * __s);
82
+						__to = &__ws[0] + __s;
83
+						__to_end = &__ws[0] + __ws.size();
84
+						__frm = __frm_nxt;
85
+					}
86
+				} while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
87
+			}
88
+			if (__r == codecvt_base::ok)
89
+				return __ws;
90
+		}
91
+		if (this->__wide_err_string_.empty())
92
+			throw range_error("wstring_convert: from_bytes error");
93
+		return this->__wide_err_string_;
94
+	}
95
+
96
+	byte_string to_bytes(_Elem __wchar) { return to_bytes(&__wchar, &__wchar + 1); }
97
+	byte_string to_bytes(const _Elem *__wptr) { return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr)); }
98
+	byte_string to_bytes(const wide_string &__wstr) { return to_bytes(__wstr.data(), __wstr.data() + __wstr.size()); }
99
+	byte_string to_bytes(const _Elem *__frm, const _Elem *__frm_end)
100
+	{
101
+		this->__cvtcount_ = 0;
102
+		if (this->__cvtptr_)
103
+		{
104
+			byte_string __bs(2 * (__frm_end - __frm), char());
105
+			if (__frm != __frm_end)
106
+				__bs.resize(__bs.capacity());
107
+			auto __r = codecvt_base::ok;
108
+			auto __st = this->__cvtstate_;
109
+			if (__frm != __frm_end)
110
+			{
111
+				auto __to = &__bs[0];
112
+				auto __to_end = __to + __bs.size();
113
+				const _Elem *__frm_nxt;
114
+				do
115
+				{
116
+					char *__to_nxt;
117
+					__r = this->__cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
118
+					this->__cvtcount_ += __frm_nxt - __frm;
119
+					if (__frm_nxt == __frm)
120
+						__r = codecvt_base::error;
121
+					else if (__r == codecvt_base::noconv)
122
+					{
123
+						__bs.resize(__to - &__bs[0]);
124
+						// This only gets executed if _Elem is char
125
+						__bs.append(reinterpret_cast<const char *>(__frm), reinterpret_cast<const char *>(__frm_end));
126
+						__frm = __frm_nxt;
127
+						__r = codecvt_base::ok;
128
+					}
129
+					else if (__r == codecvt_base::ok)
130
+					{
131
+						__bs.resize(__to_nxt - &__bs[0]);
132
+						__frm = __frm_nxt;
133
+					}
134
+					else if (__r == codecvt_base::partial)
135
+					{
136
+						ptrdiff_t __s = __to_nxt - &__bs[0];
137
+						__bs.resize(2 * __s);
138
+						__to = &__bs[0] + __s;
139
+						__to_end = &__bs[0] + __bs.size();
140
+						__frm = __frm_nxt;
141
+					}
142
+				} while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
143
+			}
144
+			if (__r == codecvt_base::ok)
145
+			{
146
+				auto __s = __bs.size();
147
+				__bs.resize(__bs.capacity());
148
+				auto __to = &__bs[0] + __s;
149
+				auto __to_end = __to + __bs.size();
150
+				do
151
+				{
152
+					char *__to_nxt;
153
+					__r = this->__cvtptr_->unshift(__st, __to, __to_end, __to_nxt);
154
+					if (__r == codecvt_base::noconv)
155
+					{
156
+						__bs.resize(__to - &__bs[0]);
157
+						__r = codecvt_base::ok;
158
+					}
159
+					else if (__r == codecvt_base::ok)
160
+						__bs.resize(__to_nxt - &__bs[0]);
161
+					else if (__r == codecvt_base::partial)
162
+					{
163
+						ptrdiff_t __sp = __to_nxt - &__bs[0];
164
+						__bs.resize(2 * __sp);
165
+						__to = &__bs[0] + __sp;
166
+						__to_end = &__bs[0] + __bs.size();
167
+					}
168
+				} while (__r == codecvt_base::partial);
169
+				if (__r == codecvt_base::ok)
170
+					return __bs;
171
+			}
172
+		}
173
+		if (this->__byte_err_string_.empty())
174
+			throw range_error("wstring_convert: to_bytes error");
175
+		return this->__byte_err_string_;
176
+	}
177
+
178
+	size_t converted() const throw() { return this->__cvtcount_; }
179
+	state_type state() const { return this->__cvtstate_; }
180
+};
181
+
182
+};
183
+#endif