Commit e234ba81 authored by Aleksandr Bakhshiev's avatar Aleksandr Bakhshiev
Browse files

Unicode convert now platform-dependent.

--HG--
branch : Xml_debug
parent ceae838a64d9
......@@ -17,6 +17,7 @@ See file license.txt for more information
#include <fstream>
#include "USerStorageXML.h"
#include "../Utilities/USupport.h"
#include "../System/rdk_system.h"
namespace RDK {
......
......@@ -245,6 +245,101 @@ bool ReadUsedMemoryInfo(unsigned long long &total_used_memory, unsigned long lon
return true;
}
///
std::string& narrow(const std::wstring& wstr, std::string &result, unsigned codepage)
{
unsigned real_codepage=(codepage==0)?CP_ACP:codepage;
int slength = (int)wstr.length() + 1;
int len = WideCharToMultiByte(real_codepage, 0, wstr.c_str(), slength, 0, 0, 0, 0);
result.resize(len, '\0');
WideCharToMultiByte(real_codepage, 0, wstr.c_str(), slength, &result[0], len, 0, 0);
// int r_size1=r.size();
// int r_length1=r.length();
if(!result.empty())
result.resize(len-1);
// int r_size2=r.size();
// int r_length2=r.length();
return result;
}
/// Deprecated
std::string& narrow(const std::wstring& wstr, const std::locale& loc, std::string &result)
{
return narrow(wstr, result);
}
///
std::wstring& widen(const std::string& str, std::wstring &result, unsigned codepage)
{
unsigned real_codepage=(codepage==0)?CP_ACP:codepage;
int slength = (int)str.length() + 1;
int len = MultiByteToWideChar(real_codepage, 0, str.c_str(), slength, 0, 0);
result.resize(len, L'\0');
MultiByteToWideChar(real_codepage, 0, str.c_str(), slength, &result[0], len);
// int r_size1=r.size();
// int r_length1=r.length();
if(!result.empty())
result.resize(len-1);
// int r_size2=r.size();
// int r_length2=r.length();
return result;
}
/// Deprecated
std::wstring& widen(const std::string& str, const std::locale& loc, std::wstring &result)
{
return widen(str, result);
}
/*
// https://codereview.stackexchange.com/questions/419/converting-between-stdwstring-and-stdstring
std::wstring s2ws(const std::string& s)
{
int slength = (int)s.length() + 1;
int len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
std::wstring r(len, L'\0');
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, &r[0], len);
int r_size1=r.size();
int r_length1=r.length();
if(!r.empty())
r.resize(len-1);
int r_size2=r.size();
int r_length2=r.length();
return r;
}
std::string ws2s(const std::wstring& s)
{
int slength = (int)s.length() + 1;
int len = WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0);
std::string r(len, '\0');
WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, &r[0], len, 0, 0);
int r_size1=r.size();
int r_length1=r.length();
if(!r.empty())
r.resize(len-1);
int r_size2=r.size();
int r_length2=r.length();
return r;
}
*/
}
#endif
......@@ -262,40 +262,5 @@ void UDestroyEvent(UGenericEvent* event)
delete event;
}
// https://codereview.stackexchange.com/questions/419/converting-between-stdwstring-and-stdstring
std::wstring s2ws(const std::string& s)
{
/*
int slength = (int)s.length() + 1;
int len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
std::wstring r(len, L'\0');
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, &r[0], len);
return r; */
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
std::string ws2s(const std::wstring& s)
{
/* int slength = (int)s.length() + 1;
int len = WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0);
std::string r(len, '\0');
WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, &r[0], len, 0, 0);
return r; */
int len;
int slength = (int)s.length() + 1;
len = WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0);
char* buf = new char[len];
WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, buf, len, 0, 0);
std::string r(buf);
delete[] buf;
return r;
}
#endif
......@@ -59,6 +59,20 @@ RDK_LIB_TYPE void UDestroyDllLoader(UDllLoader *handle);
/// false
RDK_LIB_TYPE bool ReadUsedMemoryInfo(unsigned long long &total_used_memory, unsigned long long &largest_free_block);
///
/// 0 -
RDK_LIB_TYPE std::string& narrow(const std::wstring& wstr, std::string &result, unsigned codepage=0);
/// Deprecated
RDK_LIB_TYPE std::string& narrow(const std::wstring& wstr, const std::locale& loc, std::string &result);
///
/// 0 -
RDK_LIB_TYPE std::wstring& widen(const std::string& str, std::wstring &result, unsigned codepage=0);
/// Deprecated
RDK_LIB_TYPE std::wstring& widen(const std::string& str, const std::locale& loc, std::wstring &result);
}
}
......
......@@ -22,11 +22,10 @@ See file license.txt for more information
#include <fstream>
#include "USupport.h"
#ifdef __BORLANDC__
extern std::wstring s2ws(const std::string& s);
extern std::string ws2s(const std::wstring& s);
#endif
//#ifdef __BORLANDC__
//extern std::wstring s2ws(const std::string& s);
//extern std::string ws2s(const std::wstring& s);
//#endif
//#include "UPtr.cpp"
......@@ -159,7 +158,7 @@ std::string get_text_current_time(char date_sep, char time_sep, char m_sec_sep,
return result;
}*/
/*
#ifndef __BORLANDC__
// string<->wstring
// http://habrahabr.ru/blogs/cpp/112997/
......@@ -238,7 +237,7 @@ std::wstring& widen(const std::string& str, const std::locale& loc, std::wstring
}
#endif
*/
///
RDK_LIB_TYPE std::string trim_spaces(const std::string &str)
......
......@@ -313,18 +313,21 @@ RDK_LIB_TYPE std::string get_text_time_from_seconds(double time_data, char date_
//std::string get_text_current_time(char date_sep='/', char time_sep=':', char m_sec_sep=',', std::string additional_line="GMT+04:00");
// string<->wstring
// !!! - !!!
// http://habrahabr.ru/blogs/cpp/112997/
//@brief , loc
// @return ,
// .
RDK_LIB_TYPE std::string& narrow(const std::wstring& wstr, const std::locale& loc, std::string &result);
//RDK_LIB_TYPE std::string& narrow(const std::wstring& wstr, const std::locale& loc, std::string &result);
//RDK_LIB_TYPE std::string& narrow(const std::wstring& wstr, std::string &result, unsigned codepage);
//std::string narrow2(const std::wstring& wstr);
//@brief , loc
// @return ,
// , .
RDK_LIB_TYPE std::wstring& widen(const std::string& str, const std::locale& loc, std::wstring &result);
//RDK_LIB_TYPE std::wstring& widen(const std::string& str, const std::locale& loc, std::wstring &result);
//RDK_LIB_TYPE std::wstring& widen(const std::string& str, std::wstring &result, unsigned codepage);
//std::wstring widen2(const std::string& str);
......
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