mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-09-06 07:07:48 -04:00
GCC missing codecvt support
This commit is contained in:
parent
61d67e69d6
commit
8b3fba02cc
@ -28,7 +28,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <codecvt>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* DataElement class */
|
/* DataElement class */
|
||||||
|
|
||||||
@ -113,11 +113,13 @@ void DataElement::set(const string &str_in) {
|
|||||||
void DataElement::set(const wstring &wstr_in) {
|
void DataElement::set(const wstring &wstr_in) {
|
||||||
data_type = DATA_WSTRING;
|
data_type = DATA_WSTRING;
|
||||||
|
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t> > utf8conv;
|
int maxLen = wstr_in.length()*2+1;
|
||||||
std::string wstrVal = utf8conv.to_bytes(wstr_in);
|
char *tmp_str = (char *)malloc(maxLen);
|
||||||
|
wcstombs(tmp_str, wstr_in.c_str(), maxLen);
|
||||||
|
|
||||||
data_init(wstrVal.length() + 1);
|
data_init(strlen(tmp_str) + 1);
|
||||||
memcpy(data_val, wstrVal.c_str(), data_size);
|
memcpy(data_val, tmp_str, data_size);
|
||||||
|
free(tmp_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataElement::set(vector<string> &strvect_in) {
|
void DataElement::set(vector<string> &strvect_in) {
|
||||||
@ -294,16 +296,17 @@ void DataElement::get(wstring &wstr_in) {
|
|||||||
if (data_type != DATA_WSTRING)
|
if (data_type != DATA_WSTRING)
|
||||||
throw(new DataTypeMismatchException("Type mismatch, not a WSTRING"));
|
throw(new DataTypeMismatchException("Type mismatch, not a WSTRING"));
|
||||||
|
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t> > utf8conv;
|
|
||||||
std::wstring wstrVal = utf8conv.from_bytes((char *)data_val);
|
|
||||||
|
|
||||||
if (!wstr_in.empty()) // flush the string
|
if (!wstr_in.empty()) // flush the string
|
||||||
{
|
{
|
||||||
wstr_in.erase(wstr_in.begin(), wstr_in.end());
|
wstr_in.erase(wstr_in.begin(), wstr_in.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_val) {
|
if (data_val) {
|
||||||
wstr_in.append(wstrVal);
|
int maxLen = strlen(data_val)*2+1;
|
||||||
|
wchar_t *tmp_wstr = (wchar_t *)malloc(maxLen*sizeof(wchar_t));
|
||||||
|
mbstowcs(tmp_wstr, data_val, maxLen);
|
||||||
|
wstr_in.append(tmp_wstr);
|
||||||
|
free(tmp_wstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,9 +579,15 @@ std::string trim(std::string& s, const std::string& drop = " ") {
|
|||||||
string DataTree::wsEncode(const wstring wstr) {
|
string DataTree::wsEncode(const wstring wstr) {
|
||||||
stringstream encStream;
|
stringstream encStream;
|
||||||
|
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t> > utf8conv;
|
int bufSize = wstr.length()*2+1;
|
||||||
std::string byte_str = utf8conv.to_bytes(wstr);
|
char *data_str = (char *)malloc(bufSize);
|
||||||
|
|
||||||
|
wcstombs(data_str, wstr.c_str(), bufSize);
|
||||||
|
|
||||||
|
std::string byte_str(data_str);
|
||||||
|
|
||||||
|
free(data_str);
|
||||||
|
|
||||||
encStream << std::hex;
|
encStream << std::hex;
|
||||||
|
|
||||||
for(auto i = byte_str.begin(); i != byte_str.end(); i++) {
|
for(auto i = byte_str.begin(); i != byte_str.end(); i++) {
|
||||||
@ -591,7 +600,7 @@ string DataTree::wsEncode(const wstring wstr) {
|
|||||||
wstring DataTree::wsDecode(const string str) {
|
wstring DataTree::wsDecode(const string str) {
|
||||||
|
|
||||||
std::stringstream decStream;
|
std::stringstream decStream;
|
||||||
std::stringstream utf8str;
|
std::stringstream mbstr;
|
||||||
unsigned int x;
|
unsigned int x;
|
||||||
|
|
||||||
string decStr = str;
|
string decStr = str;
|
||||||
@ -599,16 +608,19 @@ wstring DataTree::wsDecode(const string str) {
|
|||||||
decStream << trim(decStr);
|
decStream << trim(decStr);
|
||||||
|
|
||||||
string sResult;
|
string sResult;
|
||||||
wstring wsResult;
|
int maxLen = decStr.length();
|
||||||
|
wchar_t *wc_str = (wchar_t *) malloc(maxLen * sizeof(wchar_t));
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8conv;
|
|
||||||
|
|
||||||
while (!decStream.eof()) {
|
while (!decStream.eof()) {
|
||||||
decStream >> std::hex >> x;
|
decStream >> std::hex >> x;
|
||||||
utf8str << (unsigned char) x;
|
mbstr << (unsigned char) x;
|
||||||
}
|
}
|
||||||
|
|
||||||
return utf8conv.from_bytes(utf8str.str().c_str());
|
mbstowcs(wc_str, mbstr.str().c_str(), maxLen);
|
||||||
|
|
||||||
|
free(wc_str);
|
||||||
|
|
||||||
|
return wstring(wc_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataTree::decodeXMLText(DataNode *elem, const char *src_text, DT_FloatingPointPolicy fpp) {
|
void DataTree::decodeXMLText(DataNode *elem, const char *src_text, DT_FloatingPointPolicy fpp) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user