mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Unicode prep
This commit is contained in:
1 parent
cd162639ed
commit
a038f612bd
15 files changed
+121
-51
No files matched your search
+1
-1
@@ -98,7 +98,7 @@ Clip *clip_load(const char *filename) {
|
||||
uint8_t *filedata;
|
||||
size_t size;
|
||||
filedata = VFSReadFile(filename, &size);
|
||||
num_samples = (int)stb_vorbis_decode_memory(filedata, size, &num_channels, &data);
|
||||
num_samples = (int)stb_vorbis_decode_memory(filedata, (int)size, &num_channels, &data);
|
||||
if (num_samples <= 0)
|
||||
return NULL;
|
||||
sample_rate = 44100;
|
||||
|
||||
+1
-1
@@ -99,6 +99,6 @@ inline uint64 swap64(const uint8* _pData) {return swap64(*(const uint64*)_pData)
|
||||
#endif
|
||||
|
||||
// For really basic windows code compat
|
||||
#ifndef TCHAR
|
||||
#ifndef _TCHAR_DEFINED
|
||||
typedef char TCHAR;
|
||||
#endif
|
||||
+5
-5
@@ -64,12 +64,12 @@ inline void Crash() {
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void __ods__(const char *p);
|
||||
void OutputDebugStringUTF8(const char *p);
|
||||
|
||||
#define ILOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "I: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "I: " __VA_ARGS__); p += sprintf(p, "\n"); __ods__(temp);}
|
||||
#define WLOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "W: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "W: " __VA_ARGS__); p += sprintf(p, "\n"); __ods__(temp);}
|
||||
#define ELOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "E: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "E: " __VA_ARGS__); p += sprintf(p, "\n"); __ods__(temp);}
|
||||
#define FLOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "F: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "F: " __VA_ARGS__); p += sprintf(p, "\n"); __ods__(temp); Crash();}
|
||||
#define ILOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "I: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "I: " __VA_ARGS__); p += sprintf(p, "\n"); OutputDebugStringUTF8(temp);}
|
||||
#define WLOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "W: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "W: " __VA_ARGS__); p += sprintf(p, "\n"); OutputDebugStringUTF8(temp);}
|
||||
#define ELOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "E: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "E: " __VA_ARGS__); p += sprintf(p, "\n"); OutputDebugStringUTF8(temp);}
|
||||
#define FLOG(...) {char temp[512]; char *p = temp; p += sprintf(p, "F: %s:%i: ", __FILE__, __LINE__); p += sprintf(p, "F: " __VA_ARGS__); p += sprintf(p, "\n"); OutputDebugStringUTF8(temp); Crash();}
|
||||
|
||||
// TODO: Win32 version using OutputDebugString
|
||||
#else
|
||||
|
||||
+10
-2
@@ -1,5 +1,7 @@
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
@@ -8,6 +10,7 @@
|
||||
#include <sstream>
|
||||
#include <limits.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
|
||||
#include "base/buffer.h"
|
||||
@@ -17,9 +20,14 @@
|
||||
// Function Cross-Compatibility
|
||||
#define strcasecmp _stricmp
|
||||
|
||||
void __ods__(const char *p) {
|
||||
OutputDebugString(p);
|
||||
void OutputDebugStringUTF8(const char *p) {
|
||||
wchar_t temp[2048];
|
||||
int len = std::min(2047, (int)strlen(p));
|
||||
int size = (int)MultiByteToWideChar(CP_UTF8, 0, p, len, NULL, 0);
|
||||
MultiByteToWideChar(CP_UTF8, 0, p, len, temp, size);
|
||||
OutputDebugString(temp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
unsigned int parseHex(const char *_szValue)
|
||||
|
||||
@@ -25,7 +25,7 @@ bool compress_string(const std::string& str, std::string *dest, int compressionl
|
||||
}
|
||||
|
||||
zs.next_in = (Bytef*)str.data();
|
||||
zs.avail_in = str.size(); // set the z_stream's input
|
||||
zs.avail_in = (uInt)str.size(); // set the z_stream's input
|
||||
|
||||
int ret;
|
||||
char outbuffer[32768];
|
||||
@@ -72,7 +72,7 @@ bool decompress_string(const std::string& str, std::string *dest) {
|
||||
}
|
||||
|
||||
zs.next_in = (Bytef*)str.data();
|
||||
zs.avail_in = str.size();
|
||||
zs.avail_in = (uInt)str.size();
|
||||
|
||||
int ret;
|
||||
char outbuffer[32768];
|
||||
|
||||
+1
-7
@@ -214,23 +214,17 @@ void ChunkFile::writeWString(String str) {
|
||||
}
|
||||
*/
|
||||
|
||||
// Takes utf-8
|
||||
void ChunkFile::writeWString(const std::string &str) {
|
||||
unsigned short *text;
|
||||
size_t len = str.length();
|
||||
#ifdef UNICODE
|
||||
#error
|
||||
text = str.c_str();
|
||||
#else
|
||||
text = new unsigned short[len+1];
|
||||
for (int i=0; i<len; i++)
|
||||
text[i]=str[i];
|
||||
text[len]=0;
|
||||
#endif
|
||||
writeInt(len);
|
||||
writeData((char *)text, len * sizeof(unsigned short));
|
||||
#ifndef UNICODE
|
||||
delete [] text;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void toUnicode(const std::string &str, uint16 *t) {
|
||||
|
||||
+2
-1
@@ -57,7 +57,8 @@ private:
|
||||
int numLevels;
|
||||
|
||||
uint8_t *data;
|
||||
int pos, eof;
|
||||
int pos;
|
||||
int eof;
|
||||
bool fastMode;
|
||||
bool read;
|
||||
bool didFail;
|
||||
|
||||
+14
-15
@@ -21,6 +21,7 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/basictypes.h"
|
||||
#include "file/file_util.h"
|
||||
#include "util/text/utf8.h"
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__SYMBIAN32__)
|
||||
#define stat64 stat
|
||||
@@ -110,8 +111,7 @@ bool readDataFromFile(bool text_file, unsigned char* &data, const unsigned int s
|
||||
if (!f)
|
||||
return false;
|
||||
size_t len = (size_t)GetSize(f);
|
||||
if(len < size)
|
||||
{
|
||||
if(len < size) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
@@ -140,10 +140,10 @@ static void stripTailDirSlashes(std::string &fname)
|
||||
}
|
||||
|
||||
// Returns true if file filename exists
|
||||
bool exists(const std::string &filename)
|
||||
{
|
||||
bool exists(const std::string &filename) {
|
||||
#ifdef _WIN32
|
||||
return GetFileAttributes(filename.c_str()) != 0xFFFFFFFF;
|
||||
std::wstring wstr = ConvertUTF8ToWString(filename);
|
||||
return GetFileAttributes(wstr.c_str()) != 0xFFFFFFFF;
|
||||
#else
|
||||
struct stat64 file_info;
|
||||
|
||||
@@ -157,15 +157,13 @@ bool exists(const std::string &filename)
|
||||
}
|
||||
|
||||
// Returns true if filename is a directory
|
||||
bool isDirectory(const std::string &filename)
|
||||
{
|
||||
bool isDirectory(const std::string &filename) {
|
||||
FileInfo info;
|
||||
getFileInfo(filename.c_str(), &info);
|
||||
return info.isDirectory;
|
||||
}
|
||||
|
||||
bool getFileInfo(const char *path, FileInfo *fileInfo)
|
||||
{
|
||||
bool getFileInfo(const char *path, FileInfo *fileInfo) {
|
||||
// TODO: Expand relative paths?
|
||||
fileInfo->fullName = path;
|
||||
|
||||
@@ -207,7 +205,7 @@ bool getFileInfo(const char *path, FileInfo *fileInfo)
|
||||
}
|
||||
|
||||
std::string getFileExtension(const std::string &fn) {
|
||||
int pos = fn.rfind(".");
|
||||
int pos = (int)fn.rfind(".");
|
||||
if (pos < 0) return "";
|
||||
std::string ext = fn.substr(pos+1);
|
||||
for (size_t i = 0; i < ext.size(); i++) {
|
||||
@@ -248,7 +246,8 @@ size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files, const
|
||||
// Find the first file in the directory.
|
||||
WIN32_FIND_DATA ffd;
|
||||
#ifdef UNICODE
|
||||
HANDLE hFind = FindFirstFile((std::wstring(directory) + "\\*").c_str(), &ffd);
|
||||
|
||||
HANDLE hFind = FindFirstFile((ConvertUTF8ToWString(directory) + L"\\*").c_str(), &ffd);
|
||||
#else
|
||||
HANDLE hFind = FindFirstFile((std::string(directory) + "\\*").c_str(), &ffd);
|
||||
#endif
|
||||
@@ -259,7 +258,7 @@ size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files, const
|
||||
// windows loop
|
||||
do
|
||||
{
|
||||
const std::string virtualName(ffd.cFileName);
|
||||
const std::string virtualName = ConvertWStringToUTF8(ffd.cFileName);
|
||||
#else
|
||||
struct dirent_large { struct dirent entry; char padding[FILENAME_MAX+1]; };
|
||||
struct dirent_large diren;
|
||||
@@ -316,7 +315,7 @@ size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files, const
|
||||
void deleteFile(const char *file)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!DeleteFile(file)) {
|
||||
if (!DeleteFile(ConvertUTF8ToWString(file).c_str())) {
|
||||
ELOG("Error deleting %s: %i", file, GetLastError());
|
||||
}
|
||||
#else
|
||||
@@ -330,7 +329,7 @@ void deleteFile(const char *file)
|
||||
void deleteDir(const char *dir)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!RemoveDirectory(dir)) {
|
||||
if (!RemoveDirectory(ConvertUTF8ToWString(dir).c_str())) {
|
||||
ELOG("Error deleting directory %s: %i", dir, GetLastError());
|
||||
}
|
||||
#else
|
||||
@@ -390,7 +389,7 @@ std::vector<std::string> getWindowsDrives()
|
||||
auto drive = buff.data();
|
||||
while (*drive)
|
||||
{
|
||||
std::string str(drive);
|
||||
std::string str(ConvertWStringToUTF8(drive));
|
||||
str.pop_back(); // we don't want the final backslash
|
||||
str += "/";
|
||||
drives.push_back(str);
|
||||
|
||||
@@ -147,7 +147,7 @@ bool parseNumber(char* str, int defaultrad, int len, uint32& result)
|
||||
return true;
|
||||
}
|
||||
|
||||
ExpressionOpcodeType getExpressionOpcode(char* str, int& ReturnLen, ExpressionOpcodeType LastOpcode)
|
||||
ExpressionOpcodeType getExpressionOpcode(const char* str, int& ReturnLen, ExpressionOpcodeType LastOpcode)
|
||||
{
|
||||
int longestlen = 0;
|
||||
ExpressionOpcodeType result = EXOP_NONE;
|
||||
@@ -185,12 +185,12 @@ bool isAlphaNum(char c)
|
||||
}
|
||||
}
|
||||
|
||||
bool initPostfixExpression(char* infix, IExpressionFunctions* funcs, PostfixExpression& dest)
|
||||
bool initPostfixExpression(const char* infix, IExpressionFunctions* funcs, PostfixExpression& dest)
|
||||
{
|
||||
expressionError[0] = 0;
|
||||
|
||||
int infixPos = 0;
|
||||
int infixLen = strlen(infix);
|
||||
int infixLen = (int)strlen(infix);
|
||||
ExpressionOpcodeType lastOpcode = EXOP_NONE;
|
||||
std::vector<ExpressionOpcodeType> opcodeStack;
|
||||
dest.clear();
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
virtual bool getMemoryValue(uint32 address, int size, uint32& dest, char* error) = 0;
|
||||
};
|
||||
|
||||
bool initPostfixExpression(char* infix, IExpressionFunctions* funcs, PostfixExpression& dest);
|
||||
bool initPostfixExpression(const char* infix, IExpressionFunctions* funcs, PostfixExpression& dest);
|
||||
bool parsePostfixExpression(PostfixExpression& exp, IExpressionFunctions* funcs, uint32& dest);
|
||||
bool parseExpression(char* exp, IExpressionFunctions* funcs, uint32& dest);
|
||||
bool parseExpression(const char* exp, IExpressionFunctions* funcs, uint32& dest);
|
||||
const char* getExpressionError();
|
||||
+3
-1
@@ -11,14 +11,16 @@
|
||||
#include "base/basictypes.h"
|
||||
#include "base/logging.h"
|
||||
#include "midi/midi_input.h"
|
||||
#include "util/text/utf8.h"
|
||||
|
||||
std::vector<std::string> MidiInGetDevices() {
|
||||
int numDevs = midiInGetNumDevs();
|
||||
|
||||
std::vector<std::string> devices;
|
||||
for (int i = 0; i < numDevs; i++) {
|
||||
MIDIINCAPS caps;
|
||||
midiInGetDevCaps(i, &caps, sizeof(caps));
|
||||
devices.push_back(caps.szPname);
|
||||
devices.push_back(ConvertWStringToUTF8(caps.szPname));
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
+4
-4
@@ -27,25 +27,25 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v100</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
||||
+3
-5
@@ -96,8 +96,7 @@ bool DNSResolve(const std::string &host, const std::string &service, addrinfo **
|
||||
|
||||
*res = NULL;
|
||||
int result = getaddrinfo(host.c_str(), servicep, &hints, res);
|
||||
if (result == EAI_AGAIN)
|
||||
{
|
||||
if (result == EAI_AGAIN) {
|
||||
// Temporary failure. Since this already blocks, let's just try once more.
|
||||
#ifdef _WIN32
|
||||
Sleep(1);
|
||||
@@ -107,9 +106,8 @@ bool DNSResolve(const std::string &host, const std::string &service, addrinfo **
|
||||
result = getaddrinfo(host.c_str(), servicep, &hints, res);
|
||||
}
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
error = gai_strerror(result);
|
||||
if (result != 0) {
|
||||
error = gai_strerrorA(result);
|
||||
if (*res != NULL)
|
||||
freeaddrinfo(*res);
|
||||
*res = NULL;
|
||||
|
||||
+54
-1
@@ -11,11 +11,21 @@
|
||||
with these routines reserved for higher performance on data known to be
|
||||
valid.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "utf8.h"
|
||||
|
||||
@@ -407,4 +417,47 @@ int UTF8StringNonASCIICount(const char *utf8string) {
|
||||
|
||||
bool UTF8StringHasNonASCII(const char *utf8string) {
|
||||
return UTF8StringNonASCIICount(utf8string) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
std::string ConvertWStringToUTF8(const wchar_t *wstr) {
|
||||
int len = (int)wcslen(wstr);
|
||||
int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr, len, 0, 0, NULL, NULL);
|
||||
std::string s;
|
||||
s.resize(size);
|
||||
if (size > 0) {
|
||||
WideCharToMultiByte(CP_UTF8, 0, wstr, len, &s[0], size, NULL, NULL);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string ConvertWStringToUTF8(const std::wstring &wstr) {
|
||||
int len = (int)wstr.size();
|
||||
int size = (int)WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, 0, 0, NULL, NULL);
|
||||
std::string s;
|
||||
s.resize(size);
|
||||
if (size > 0) {
|
||||
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), len, &s[0], size, NULL, NULL);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source) {
|
||||
int len = (int)source.size();
|
||||
int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, NULL, 0);
|
||||
MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, dest, std::min((int)destSize, size));
|
||||
}
|
||||
|
||||
std::wstring ConvertUTF8ToWString(const std::string &source) {
|
||||
int len = (int)source.size();
|
||||
int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, NULL, 0);
|
||||
std::wstring str;
|
||||
str.resize(size);
|
||||
if (size > 0) {
|
||||
MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, &str[0], size);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
#endif
|
||||
+16
-1
@@ -14,7 +14,10 @@
|
||||
|
||||
// Further modified, and C++ stuff added, by [email protected].
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include <string>
|
||||
|
||||
uint32_t u8_nextchar(const char *s, int *i);
|
||||
int u8_wc_toutf8(char *dest, uint32_t ch);
|
||||
@@ -45,4 +48,16 @@ private:
|
||||
|
||||
int UTF8StringNonASCIICount(const char *utf8string);
|
||||
|
||||
bool UTF8StringHasNonASCII(const char *utf8string);
|
||||
bool UTF8StringHasNonASCII(const char *utf8string);
|
||||
|
||||
|
||||
// UTF8 to Win32 UCS-16
|
||||
// Should be used when calling Win32 api calls
|
||||
#ifdef _WIN32
|
||||
|
||||
std::string ConvertWStringToUTF8(const std::wstring &wstr);
|
||||
std::string ConvertWStringToUTF8(const wchar_t *wstr);
|
||||
void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source);
|
||||
std::wstring ConvertUTF8ToWString(const std::string &source);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user