mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-14 07:48:58 +00:00
Merge pull request #1093 from bgK/iconv
COMMON: Add a function for converting strings using iconv
This commit is contained in:
commit
966641ef35
68
common/iconv.cpp
Normal file
68
common/iconv.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iconv.h>
|
||||
|
||||
#include "common/str.h"
|
||||
#include "common/textconsole.h"
|
||||
#include "common/ustr.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
U32String convertToU32String(const char *fromCode, const String &string) {
|
||||
// Apparently UTF-32 isn't native endian. Also, UCS−4−INTERNAL fails
|
||||
// for me.
|
||||
iconv_t handle = iconv_open(
|
||||
#ifdef SCUMM_BIG_ENDIAN
|
||||
"UTF-32BE",
|
||||
#else
|
||||
"UTF-32LE",
|
||||
#endif
|
||||
fromCode);
|
||||
if (handle == ((iconv_t)-1))
|
||||
error("Failed to initialize UTF-32 conversion from %s", fromCode);
|
||||
|
||||
size_t inSize = string.size();
|
||||
size_t outSize = inSize * 4; // Approximation
|
||||
size_t originalOutSize = outSize;
|
||||
|
||||
char *buffer = new char[outSize];
|
||||
char *dst = buffer;
|
||||
|
||||
#ifdef ICONV_USES_CONST
|
||||
const char *src = string.c_str();
|
||||
#else
|
||||
char *src = const_cast<char *>(string.c_str());
|
||||
#endif
|
||||
|
||||
if (iconv(handle, &src, &inSize, &dst, &outSize) == ((size_t)-1))
|
||||
error("Failed to convert %s to UTF-32 string", fromCode);
|
||||
|
||||
U32String output((const U32String::value_type *)buffer, (originalOutSize - outSize) / 4);
|
||||
|
||||
delete[] buffer;
|
||||
iconv_close(handle);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
} // End of namespace Common
|
41
common/iconv.h
Normal file
41
common/iconv.h
Normal file
@ -0,0 +1,41 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef COMMON_ICONV_H
|
||||
#define COMMON_ICONV_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
|
||||
#ifdef USE_ICONV
|
||||
|
||||
namespace Common {
|
||||
|
||||
class String;
|
||||
class U32String;
|
||||
|
||||
U32String convertToU32String(const char *fromCode, const String &string);
|
||||
|
||||
} // End of namespace Common
|
||||
|
||||
#endif // USE_ICONV
|
||||
|
||||
#endif // COMMON_ICONV_H
|
@ -57,5 +57,10 @@ MODULE_OBJS += \
|
||||
recorderfile.o
|
||||
endif
|
||||
|
||||
ifdef USE_ICONV
|
||||
MODULE_OBJS += \
|
||||
iconv.o
|
||||
endif
|
||||
|
||||
# Include common rules
|
||||
include $(srcdir)/rules.mk
|
||||
|
91
configure
vendored
91
configure
vendored
@ -132,6 +132,7 @@ _opengles2=no
|
||||
_opengl_shaders=no
|
||||
_readline=auto
|
||||
_freetype2=auto
|
||||
_iconv=auto
|
||||
_taskbar=auto
|
||||
_updates=no
|
||||
_libunity=auto
|
||||
@ -951,6 +952,9 @@ Optional Libraries:
|
||||
installed (optional)
|
||||
--disable-freetype2 disable freetype2 TTF library usage [autodetect]
|
||||
|
||||
--with-iconv-prefix=DIR Prefix where iconv is installed (optional)
|
||||
--disable-iconv disable iconv support [autodetect]
|
||||
|
||||
--with-nasm-prefix=DIR Prefix where nasm executable is installed (optional)
|
||||
--disable-nasm disable assembly language optimizations [autodetect]
|
||||
|
||||
@ -1022,6 +1026,8 @@ for ac_option in $@; do
|
||||
--disable-readline) _readline=no ;;
|
||||
--enable-freetype2) _freetype2=yes ;;
|
||||
--disable-freetype2) _freetype2=no ;;
|
||||
--enable-iconv) _iconv=yes ;;
|
||||
--disable-iconv) _iconv=no ;;
|
||||
--enable-taskbar) _taskbar=yes ;;
|
||||
--disable-taskbar) _taskbar=no ;;
|
||||
--enable-updates) _updates=yes ;;
|
||||
@ -1142,6 +1148,11 @@ for ac_option in $@; do
|
||||
OPENGL_CFLAGS="-I$arg/include"
|
||||
OPENGL_LIBS="-L$arg/lib"
|
||||
;;
|
||||
--with-iconv-prefix=*)
|
||||
arg=`echo $ac_option | cut -d '=' -f 2`
|
||||
ICONV_CFLAGS="-I$arg/include"
|
||||
ICONV_LIBS="-L$arg/lib"
|
||||
;;
|
||||
--backend=*)
|
||||
_backend=`echo $ac_option | cut -d '=' -f 2`
|
||||
;;
|
||||
@ -3902,6 +3913,86 @@ echo "$_freetype2"
|
||||
|
||||
define_in_config_if_yes "$_freetype2" "USE_FREETYPE2"
|
||||
|
||||
#
|
||||
# Check for iconv
|
||||
#
|
||||
echo_n "Checking whether iconv.h is present... "
|
||||
if test "$_iconv" = auto ; then
|
||||
_iconv=no
|
||||
cat > $TMPC << EOF
|
||||
#include <iconv.h>
|
||||
int main(int, char **) {
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
cc_check $ICONV_CFLAGS $ICONV_LIBS && _iconv=yes
|
||||
fi
|
||||
|
||||
create_iconv_test() {
|
||||
cat > $TMPC << EOF
|
||||
#include <iconv.h>
|
||||
int main(int, char **) {
|
||||
iconv_t iconv = iconv_open("UTF-32", "SJIS");
|
||||
iconv_close(iconv);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
}
|
||||
echo "$_iconv"
|
||||
|
||||
if test "$_iconv" = yes ; then
|
||||
echo_n "Checking whether iconv needs linking against libiconv... "
|
||||
|
||||
needs_iconvlib='auto'
|
||||
create_iconv_test
|
||||
cc_check $ICONV_CFLAGS $ICONV_LIBS -liconv && needs_iconvlib='yes'
|
||||
# We do check linking without -liconv here too, just in case
|
||||
# it would fail otherwise too
|
||||
create_iconv_test
|
||||
cc_check $ICONV_CFLAGS $ICONV_LIBS && needs_iconvlib='no'
|
||||
|
||||
if test "$needs_iconvlib" = auto ; then
|
||||
_iconv=no
|
||||
echo "does not link at all"
|
||||
else
|
||||
if test "$needs_iconvlib" = yes ; then
|
||||
ICONV_LIBS="$ICONV_LIBS -liconv"
|
||||
fi
|
||||
echo "$needs_iconvlib"
|
||||
|
||||
echo_n "Checking signature of iconv... "
|
||||
uses_const=no
|
||||
|
||||
cat > $TMPC << EOF
|
||||
#include <iconv.h>
|
||||
int main(int argc, char **argv) {
|
||||
iconv_t iconvP;
|
||||
const char **inbuf = 0;
|
||||
iconv(iconvP, inbuf, 0, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
cc_check $ICONV_CFLAGS $ICONV_LIBS && uses_const=yes
|
||||
|
||||
if test "$uses_const" = yes ; then
|
||||
echo "iconv_t, const char **, size_t *, char **, size_t *"
|
||||
else
|
||||
echo "iconv_t, char **, size_t *, char **, size_t *"
|
||||
fi
|
||||
|
||||
define_in_config_if_yes "$uses_const" 'ICONV_USES_CONST'
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$_iconv" = yes ; then
|
||||
LIBS="$LIBS $ICONV_LIBS"
|
||||
INCLUDES="$INCLUDES $ICONV_CFLAGS"
|
||||
fi
|
||||
|
||||
echocheck "iconv"
|
||||
define_in_config_if_yes "$_iconv" 'USE_ICONV'
|
||||
echo "$_iconv"
|
||||
|
||||
#
|
||||
# Check for OpenGL (ES)
|
||||
#
|
||||
|
Loading…
x
Reference in New Issue
Block a user