Commit 7b8b5a12 authored by twanvl's avatar twanvl

compatibility with wxWdigets 2.9+: there is now a built in wxString::FromUTF8 function, use it

parent 733a64aa
...@@ -138,10 +138,10 @@ void Reader::moveNext() { ...@@ -138,10 +138,10 @@ void Reader::moveNext() {
*/ */
template <typename T> class LocalVector { template <typename T> class LocalVector {
public: public:
LocalVector() : size(0), alloced(SMALL_SIZE), buffer(small) {} LocalVector() : the_size(0), alloced(SMALL_SIZE), buffer(small) {}
~LocalVector() { if (buffer != small) free(buffer); } ~LocalVector() { if (buffer != small) free(buffer); }
void push_back(T t) { void push_back(T t) {
if (size >= alloced) { if (the_size >= alloced) {
// double buffer size // double buffer size
if (buffer != small) { if (buffer != small) {
buffer = (T*)realloc(buffer, sizeof(T) * alloced * 2); buffer = (T*)realloc(buffer, sizeof(T) * alloced * 2);
...@@ -151,12 +151,13 @@ template <typename T> class LocalVector { ...@@ -151,12 +151,13 @@ template <typename T> class LocalVector {
} }
alloced *= 2; alloced *= 2;
} }
buffer[size++] = t; buffer[the_size++] = t;
} }
const T* get() { return buffer; } inline const T* get() const { return buffer; }
inline size_t size() const { return the_size; }
private: private:
static const int SMALL_SIZE = 1024; static const int SMALL_SIZE = 1024;
size_t size, alloced; size_t the_size, alloced;
T* buffer; T* buffer;
T small[SMALL_SIZE]; T small[SMALL_SIZE];
}; };
...@@ -190,14 +191,20 @@ String read_utf8_line(wxInputStream& input, bool eat_bom, bool until_eof) { ...@@ -190,14 +191,20 @@ String read_utf8_line(wxInputStream& input, bool eat_bom, bool until_eof) {
} else if (size == 0) { } else if (size == 0) {
return _(""); return _("");
} }
String result;
#ifdef UNICODE #ifdef UNICODE
// NOTE: wx doc is wrong, parameter to GetWritableChar is numer of characters, not bytes #if wxVERSION_NUMBER >= 2900
Char* result_buf = result.GetWriteBuf(size + 1); String result = wxString::FromUTF8(buffer.get(), buffer.size());
wxConvUTF8.MB2WC(result_buf, buffer.get(), size + 1); return eat_bom ? decodeUTF8BOM(result) : result;
result.UngetWriteBuf(size); #else
return eat_bom ? decodeUTF8BOM(result) : result; // NOTE: wx doc is wrong, parameter to GetWritableChar is numer of characters, not bytes
String result;
Char* result_buf = result.GetWriteBuf(size + 1);
wxConvUTF8.MB2WC(result_buf, buffer.get(), size + 1);
result.UngetWriteBuf(size);
return eat_bom ? decodeUTF8BOM(result) : result;
#endif
#else #else
String result;
// first to wchar, then back to local // first to wchar, then back to local
vector<wchar_t> buf2; buf2.resize(size+1); vector<wchar_t> buf2; buf2.resize(size+1);
wxConvUTF8.MB2WC(&buf2[0], buffer.get(), size + 1); wxConvUTF8.MB2WC(&buf2[0], buffer.get(), size + 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment