Mesen-SX/Utilities/UTF8Util.h

56 lines
1.2 KiB
C
Raw Normal View History

2019-02-13 14:10:36 -05:00
#pragma once
#include <fstream>
2020-12-19 23:32:47 +03:00
namespace utf8
{
2019-02-13 14:10:36 -05:00
class utf8
{
public:
2020-12-19 23:32:47 +03:00
static std::wstring decode(const std::string& str);
static std::string encode(const std::wstring& wstr);
static std::string encode(const std::u16string& wstr);
2019-02-13 14:10:36 -05:00
};
2020-12-19 23:32:47 +03:00
2019-02-13 14:10:36 -05:00
#if defined(_WIN32) && !defined(LIBRETRO)
class ifstream : public std::ifstream
{
public:
2020-12-19 23:32:47 +03:00
ifstream(const std::string& _Str, ios_base::openmode _Mode = ios_base::in,
int _Prot = (int)ios_base::_Openprot) : std::ifstream(utf8::decode(_Str), _Mode, _Prot)
{
}
ifstream() : std::ifstream()
{
}
void open(const std::string& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = (int)ios_base::_Openprot)
{
std::ifstream::open(utf8::decode(_Str), _Mode, _Prot);
}
2019-02-13 14:10:36 -05:00
};
class ofstream : public std::ofstream
{
public:
2020-12-19 23:32:47 +03:00
ofstream(const std::string& _Str, ios_base::openmode _Mode = ios_base::in,
int _Prot = (int)ios_base::_Openprot) : std::ofstream(utf8::decode(_Str), _Mode, _Prot)
{
}
ofstream() : std::ofstream()
{
}
void open(const std::string& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = (int)ios_base::_Openprot)
{
std::ofstream::open(utf8::decode(_Str), _Mode, _Prot);
}
2019-02-13 14:10:36 -05:00
};
#else
using std::ifstream;
using std::ofstream;
#endif
2020-12-19 23:32:47 +03:00
}