mirror of https://github.com/PCSX2/pcsx2.git
SPU2-X: Remove obsolete utf8 files.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3441 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
64450c5711
commit
9d5a1b44ba
|
@ -409,48 +409,6 @@
|
|||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utf8.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Devel|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
CompileAs="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="DebugStrict|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
CompileAs="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utf8.h"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="debug"
|
||||
>
|
||||
|
|
|
@ -1,319 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001 Peter Harris <peter.harris@hummingbird.com>
|
||||
* Copyright (C) 2001 Edmund Grimley Evans <edmundo@rano.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* Convert a string between UTF-8 and the locale's charset.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utf8.h"
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Thanks to Peter Harris <peter.harris@hummingbird.com> for this win32
|
||||
* code.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
static unsigned char *make_utf8_string(const wchar_t *unicode)
|
||||
{
|
||||
int size = 0, index = 0, out_index = 0;
|
||||
unsigned char *out;
|
||||
unsigned short c;
|
||||
|
||||
/* first calculate the size of the target string */
|
||||
c = unicode[index++];
|
||||
while(c) {
|
||||
if(c < 0x0080) {
|
||||
size += 1;
|
||||
} else if(c < 0x0800) {
|
||||
size += 2;
|
||||
} else {
|
||||
size += 3;
|
||||
}
|
||||
c = unicode[index++];
|
||||
}
|
||||
|
||||
out = (unsigned char*)malloc(size + 1);
|
||||
if (out == NULL)
|
||||
return NULL;
|
||||
index = 0;
|
||||
|
||||
c = unicode[index++];
|
||||
while(c)
|
||||
{
|
||||
if(c < 0x080) {
|
||||
out[out_index++] = (unsigned char)c;
|
||||
} else if(c < 0x800) {
|
||||
out[out_index++] = 0xc0 | (c >> 6);
|
||||
out[out_index++] = 0x80 | (c & 0x3f);
|
||||
} else {
|
||||
out[out_index++] = 0xe0 | (c >> 12);
|
||||
out[out_index++] = 0x80 | ((c >> 6) & 0x3f);
|
||||
out[out_index++] = 0x80 | (c & 0x3f);
|
||||
}
|
||||
c = unicode[index++];
|
||||
}
|
||||
out[out_index] = 0x00;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static wchar_t *make_unicode_string(const unsigned char *utf8)
|
||||
{
|
||||
int size = 0, index = 0, out_index = 0;
|
||||
wchar_t *out;
|
||||
unsigned char c;
|
||||
|
||||
/* first calculate the size of the target string */
|
||||
c = utf8[index++];
|
||||
while(c) {
|
||||
if((c & 0x80) == 0) {
|
||||
index += 0;
|
||||
} else if((c & 0xe0) == 0xe0) {
|
||||
index += 2;
|
||||
} else {
|
||||
index += 1;
|
||||
}
|
||||
size += 1;
|
||||
c = utf8[index++];
|
||||
}
|
||||
|
||||
out = (wchar_t*)malloc((size + 1) * sizeof(wchar_t));
|
||||
if (out == NULL)
|
||||
return NULL;
|
||||
index = 0;
|
||||
|
||||
c = utf8[index++];
|
||||
while(c)
|
||||
{
|
||||
if((c & 0x80) == 0) {
|
||||
out[out_index++] = c;
|
||||
} else if((c & 0xe0) == 0xe0) {
|
||||
out[out_index] = (c & 0x1F) << 12;
|
||||
c = utf8[index++];
|
||||
out[out_index] |= (c & 0x3F) << 6;
|
||||
c = utf8[index++];
|
||||
out[out_index++] |= (c & 0x3F);
|
||||
} else {
|
||||
out[out_index] = (c & 0x3F) << 6;
|
||||
c = utf8[index++];
|
||||
out[out_index++] |= (c & 0x3F);
|
||||
}
|
||||
c = utf8[index++];
|
||||
}
|
||||
out[out_index] = 0;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
int utf8_encode(const char *from, char **to)
|
||||
{
|
||||
wchar_t *unicode;
|
||||
int wchars, err;
|
||||
|
||||
wchars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, from,
|
||||
strlen(from), NULL, 0);
|
||||
|
||||
if(wchars == 0)
|
||||
{
|
||||
fprintf(stderr, "Unicode translation error %d\n", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
unicode = (wchar_t*)calloc(wchars + 1, sizeof(unsigned short));
|
||||
if(unicode == NULL)
|
||||
{
|
||||
fprintf(stderr, "Out of memory processing string to UTF8\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, from,
|
||||
strlen(from), unicode, wchars);
|
||||
if(err != wchars)
|
||||
{
|
||||
free(unicode);
|
||||
fprintf(stderr, "Unicode translation error %d\n", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* On NT-based windows systems, we could use WideCharToMultiByte(), but
|
||||
* MS doesn't actually have a consistent API across win32.
|
||||
*/
|
||||
*to = (char*)make_utf8_string(unicode);
|
||||
|
||||
free(unicode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int utf8_decode(const char *from, char **to)
|
||||
{
|
||||
wchar_t *unicode;
|
||||
int chars, err;
|
||||
|
||||
/* On NT-based windows systems, we could use MultiByteToWideChar(CP_UTF8), but
|
||||
* MS doesn't actually have a consistent API across win32.
|
||||
*/
|
||||
unicode = make_unicode_string((unsigned char*)from);
|
||||
if(unicode == NULL)
|
||||
{
|
||||
fprintf(stderr, "Out of memory processing string from UTF8 to UNICODE16\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
chars = WideCharToMultiByte(GetConsoleCP(), WC_COMPOSITECHECK, unicode,
|
||||
-1, NULL, 0, NULL, NULL);
|
||||
|
||||
if(chars == 0)
|
||||
{
|
||||
fprintf(stderr, "Unicode translation error %d\n", GetLastError());
|
||||
free(unicode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*to = (char *)calloc(chars + 1, sizeof(unsigned char));
|
||||
if(*to == NULL)
|
||||
{
|
||||
fprintf(stderr, "Out of memory processing string to local charset\n");
|
||||
free(unicode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = WideCharToMultiByte(GetConsoleCP(), WC_COMPOSITECHECK, unicode,
|
||||
-1, *to, chars, NULL, NULL);
|
||||
if(err != chars)
|
||||
{
|
||||
fprintf(stderr, "Unicode translation error %d\n", GetLastError());
|
||||
free(unicode);
|
||||
free(*to);
|
||||
*to = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(unicode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* End win32. Rest is for real operating systems */
|
||||
|
||||
#ifdef HAVE_LANGINFO_CODESET
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
|
||||
extern int iconvert(const char *fromcode, const char *tocode,
|
||||
const char *from, size_t fromlen,
|
||||
char **to, size_t *tolen);
|
||||
|
||||
static char *current_charset = 0; /* means "US-ASCII" */
|
||||
|
||||
void convert_set_charset(const char *charset)
|
||||
{
|
||||
|
||||
if (!charset)
|
||||
charset = getenv("CHARSET");
|
||||
|
||||
#ifdef HAVE_LANGINFO_CODESET
|
||||
if (!charset)
|
||||
charset = nl_langinfo(CODESET);
|
||||
#endif
|
||||
|
||||
free(current_charset);
|
||||
current_charset = 0;
|
||||
if (charset && *charset)
|
||||
current_charset = strdup(charset);
|
||||
}
|
||||
|
||||
static int convert_buffer(const char *fromcode, const char *tocode,
|
||||
const char *from, size_t fromlen,
|
||||
char **to, size_t *tolen)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
//#ifdef HAVE_ICONV
|
||||
ret = iconvert(fromcode, tocode, from, fromlen, to, tolen);
|
||||
if (ret != -1)
|
||||
return ret;
|
||||
//#endif
|
||||
|
||||
//#ifndef HAVE_ICONV /* should be ifdef USE_CHARSET_CONVERT */
|
||||
// ret = charset_convert(fromcode, tocode, from, fromlen, to, tolen);
|
||||
// if (ret != -1)
|
||||
// return ret;
|
||||
//#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int convert_string(const char *fromcode, const char *tocode,
|
||||
const char *from, char **to, char replace)
|
||||
{
|
||||
int ret;
|
||||
size_t fromlen;
|
||||
char *s;
|
||||
|
||||
fromlen = strlen(from);
|
||||
ret = convert_buffer(fromcode, tocode, from, fromlen, to, 0);
|
||||
if (ret == -2)
|
||||
return -1;
|
||||
if (ret != -1)
|
||||
return ret;
|
||||
|
||||
s = (char*)malloc(fromlen + 1);
|
||||
if (!s)
|
||||
return -1;
|
||||
strcpy(s, from);
|
||||
*to = s;
|
||||
for (; *s; s++)
|
||||
if (*s & ~0x7f)
|
||||
*s = replace;
|
||||
return 3;
|
||||
}
|
||||
|
||||
int utf8_encode(const char *from, char **to)
|
||||
{
|
||||
char *charset;
|
||||
|
||||
if (!current_charset)
|
||||
convert_set_charset(0);
|
||||
charset = current_charset ? current_charset : (char *)"US-ASCII";
|
||||
return convert_string(charset, "UTF-8", from, to, '#');
|
||||
}
|
||||
|
||||
int utf8_decode(const char *from, char **to)
|
||||
{
|
||||
char *charset;
|
||||
|
||||
if(*from == 0) {
|
||||
*to = (char*)malloc(1);
|
||||
**to = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!current_charset)
|
||||
convert_set_charset(0);
|
||||
charset = current_charset ? current_charset : (char*)"US-ASCII";
|
||||
return convert_string("UTF-8", charset, from, to, '?');
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,36 +0,0 @@
|
|||
|
||||
/*
|
||||
* Convert a string between UTF-8 and the locale's charset.
|
||||
* Invalid bytes are replaced by '#', and characters that are
|
||||
* not available in the target encoding are replaced by '?'.
|
||||
*
|
||||
* If the locale's charset is not set explicitly then it is
|
||||
* obtained using nl_langinfo(CODESET), where available, the
|
||||
* environment variable CHARSET, or assumed to be US-ASCII.
|
||||
*
|
||||
* Return value of conversion functions:
|
||||
*
|
||||
* -1 : memory allocation failed
|
||||
* 0 : data was converted exactly
|
||||
* 1 : valid data was converted approximately (using '?')
|
||||
* 2 : input was invalid (but still converted, using '#')
|
||||
* 3 : unknown encoding (but still converted, using '?')
|
||||
*/
|
||||
|
||||
#ifndef __UTF8_H
|
||||
#define __UTF8_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void convert_set_charset(const char *charset);
|
||||
|
||||
int utf8_encode(const char *from, char **to);
|
||||
int utf8_decode(const char *from, char **to);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __UTF8_H */
|
Loading…
Reference in New Issue