glib r6809 - in branches/glib-2-16: . glib
- From: tml svn gnome org
- To: svn-commits-list gnome org
- Subject: glib r6809 - in branches/glib-2-16: . glib
- Date: Wed, 2 Apr 2008 03:48:21 +0100 (BST)
Author: tml
Date: Wed Apr 2 03:48:21 2008
New Revision: 6809
URL: http://svn.gnome.org/viewvc/glib?rev=6809&view=rev
Log:
2008-04-02 Tor Lillqvist <tml novell com>
Bug 524314 - g_convert() on Win32 implicitly converts full width
alphanumerics into half width
* glib/win_iconv.c: Update from Yukihiro Nakadaira. Use
WC_NO_BEST_FIT_CHARS flag for WideCharToMultiByte() unless the
//translit flag was suffixed to the codeset name.
* glib/gconvert.c: Include win_iconv.c earlier so that its
definition of WINVER before it includes <windows.h> is used.
Modified:
branches/glib-2-16/ChangeLog
branches/glib-2-16/glib/gconvert.c
branches/glib-2-16/glib/win_iconv.c
Modified: branches/glib-2-16/glib/gconvert.c
==============================================================================
--- branches/glib-2-16/glib/gconvert.c (original)
+++ branches/glib-2-16/glib/gconvert.c Wed Apr 2 03:48:21 2008
@@ -36,6 +36,10 @@
#include "gthreadprivate.h"
#include "gunicode.h"
+#ifdef G_OS_WIN32
+#include "win_iconv.c"
+#endif
+
#ifdef G_PLATFORM_WIN32
#define STRICT
#include <windows.h>
@@ -53,10 +57,6 @@
#include "galias.h"
-#ifdef G_OS_WIN32
-#include "win_iconv.c"
-#endif
-
GQuark
g_convert_error_quark (void)
{
Modified: branches/glib-2-16/glib/win_iconv.c
==============================================================================
--- branches/glib-2-16/glib/win_iconv.c (original)
+++ branches/glib-2-16/glib/win_iconv.c Wed Apr 2 03:48:21 2008
@@ -19,6 +19,12 @@
* be used for encoding validation purpose.
*/
+/* for WC_NO_BEST_FIT_CHARS */
+#ifndef WINVER
+# define WINVER 0x0500
+#endif
+
+#define STRICT
#include <windows.h>
#include <errno.h>
#include <string.h>
@@ -36,10 +42,12 @@
#define MB_CHAR_MAX 16
-#define UNICODE_MODE_BOM_DONE 1
-#define UNICODE_MODE_SWAPPED 2
+#define UNICODE_MODE_BOM_DONE 1
+#define UNICODE_MODE_SWAPPED 2
-#define UNICODE_FLAG_USE_BOM_ENDIAN 1
+#define FLAG_USE_BOM_ENDIAN 1
+#define FLAG_TRANSLIT 2 /* //TRANSLIT */
+#define FLAG_IGNORE 4 /* //IGNORE (not implemented) */
#define return_error(code) \
do { \
@@ -873,6 +881,7 @@
CPINFOEX cpinfoex;
csconv_t cv;
int use_compat = TRUE;
+ int flag = 0;
char name[128];
char *p;
@@ -883,11 +892,15 @@
{
if (_stricmp(p + 2, "nocompat") == 0)
use_compat = FALSE;
+ else if (_stricmp(p + 2, "translit") == 0)
+ flag |= FLAG_TRANSLIT;
+ else if (_stricmp(p + 2, "ignore") == 0)
+ flag |= FLAG_IGNORE;
*p = 0;
}
cv.mode = 0;
- cv.flags = 0;
+ cv.flags = flag;
cv.mblen = NULL;
cv.flush = NULL;
cv.compat = NULL;
@@ -899,14 +912,14 @@
if (_stricmp(name, "UTF-16") == 0 ||
_stricmp(name, "UTF16") == 0 ||
_stricmp(name, "UCS-2") == 0)
- cv.flags |= UNICODE_FLAG_USE_BOM_ENDIAN;
+ cv.flags |= FLAG_USE_BOM_ENDIAN;
}
else if (cv.codepage == 12000 || cv.codepage == 12001)
{
cv.mbtowc = utf32_mbtowc;
cv.wctomb = utf32_wctomb;
if (_stricmp(name, "UTF-32") == 0 || _stricmp(name, "UTF32") == 0)
- cv.flags |= UNICODE_FLAG_USE_BOM_ENDIAN;
+ cv.flags |= FLAG_USE_BOM_ENDIAN;
}
else if (cv.codepage == 65001)
{
@@ -1061,7 +1074,7 @@
check_utf_bom(rec_iconv_t *cd, ushort *wbuf, int *wbufsize)
{
/* If we have a BOM, trust it, despite what the caller said */
- if (wbuf[0] == 0xFFFE && (cd->from.flags & UNICODE_FLAG_USE_BOM_ENDIAN))
+ if (wbuf[0] == 0xFFFE && (cd->from.flags & FLAG_USE_BOM_ENDIAN))
{
/* swap endian: 1200 <-> 1201 or 12000 <-> 12001 */
cd->from.codepage ^= 1;
@@ -1345,13 +1358,22 @@
kernel_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize)
{
BOOL usedDefaultChar = 0;
+ BOOL *p = NULL;
+ int flags = 0;
int len;
if (bufsize == 0)
return_error(E2BIG);
- len = WideCharToMultiByte(cv->codepage, 0,
- (const wchar_t *)wbuf, wbufsize, (char *)buf, bufsize, NULL,
- must_use_null_useddefaultchar(cv->codepage) ? NULL : &usedDefaultChar);
+ if (!must_use_null_useddefaultchar(cv->codepage))
+ {
+ p = &usedDefaultChar;
+#ifdef WC_NO_BEST_FIT_CHARS
+ if (!(cv->flags & FLAG_TRANSLIT))
+ flags |= WC_NO_BEST_FIT_CHARS;
+#endif
+ }
+ len = WideCharToMultiByte(cv->codepage, flags,
+ (const wchar_t *)wbuf, wbufsize, (char *)buf, bufsize, NULL, p);
if (len == 0)
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]