1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Revise and enhance the Win32 string conversion routines.

FossilOrigin-Name: 345860c92195544aad44ea9b0d14c9ebbd50adf2
This commit is contained in:
mistachkin
2016-04-03 22:44:16 +00:00
parent 899c5c9d34
commit 5daed673b8
3 changed files with 117 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
C Replace\sthe\snew\sfprintf()\scalls. C Revise\sand\senhance\sthe\sWin32\sstring\sconversion\sroutines.
D 2016-04-03T20:50:02.891 D 2016-04-03T22:44:16.657
F Makefile.in e812bb732d7af01baa09f1278bd4f4a2e3a09449 F Makefile.in e812bb732d7af01baa09f1278bd4f4a2e3a09449
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc fe57d7e3e74fa383fd01ced796c0ffd966fc094a F Makefile.msc fe57d7e3e74fa383fd01ced796c0ffd966fc094a
@@ -358,7 +358,7 @@ F src/os.h 91ff889115ecd01f436d3611f7f5ea4dc12d92f1
F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
F src/os_unix.c b1ccb273771f41dbdbe0ba7c1ad63c38ad5972ec F src/os_unix.c b1ccb273771f41dbdbe0ba7c1ad63c38ad5972ec
F src/os_win.c ff870d89f4cb088a04cbf5ea0cbd9ff1b089ff4a F src/os_win.c 01ae58949a28edaecd5645abbe29ac9d2ee983fd
F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca
F src/pager.c 38718a019ca762ba4f6795425d5a54db70d1790d F src/pager.c 38718a019ca762ba4f6795425d5a54db70d1790d
F src/pager.h e1d38a2f14849e219df0f91f8323504d134c8a56 F src/pager.h e1d38a2f14849e219df0f91f8323504d134c8a56
@@ -1480,7 +1480,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 566b551e5a81440a5c8ff865ceb4422c76d67cf7 P f76c3a0ca40989fe9401c3b6f662f8e6ef2a730c
R c328759cdfd1946a4f3790cce9b56b06 R 9a8e623b20453c0fbff989d22019add7
U mistachkin U mistachkin
Z fca762cd11972041ea0ef005e2621264 Z 149573e0b667520348654eca6c5f3228

View File

@@ -1 +1 @@
f76c3a0ca40989fe9401c3b6f662f8e6ef2a730c 345860c92195544aad44ea9b0d14c9ebbd50adf2

View File

@@ -1635,50 +1635,50 @@ void sqlite3MemSetDefault(void){
** **
** Space to hold the returned string is obtained from malloc. ** Space to hold the returned string is obtained from malloc.
*/ */
static LPWSTR winUtf8ToUnicode(const char *zFilename){ static LPWSTR winUtf8ToUnicode(const char *zText){
int nChar; int nChar;
LPWSTR zWideFilename; LPWSTR zWideText;
nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0); nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, NULL, 0);
if( nChar==0 ){ if( nChar==0 ){
return 0; return 0;
} }
zWideFilename = sqlite3MallocZero( nChar*sizeof(zWideFilename[0]) ); zWideText = sqlite3MallocZero( nChar*sizeof(WCHAR) );
if( zWideFilename==0 ){ if( zWideText==0 ){
return 0; return 0;
} }
nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nChar = osMultiByteToWideChar(CP_UTF8, 0, zText, -1, zWideText,
nChar); nChar);
if( nChar==0 ){ if( nChar==0 ){
sqlite3_free(zWideFilename); sqlite3_free(zWideText);
zWideFilename = 0; zWideText = 0;
} }
return zWideFilename; return zWideText;
} }
/* /*
** Convert Microsoft Unicode to UTF-8. Space to hold the returned string is ** Convert Microsoft Unicode to UTF-8. Space to hold the returned string is
** obtained from sqlite3_malloc(). ** obtained from sqlite3_malloc().
*/ */
static char *winUnicodeToUtf8(LPCWSTR zWideFilename){ static char *winUnicodeToUtf8(LPCWSTR zWideText){
int nByte; int nByte;
char *zFilename; char *zText;
nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0); nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, 0, 0, 0, 0);
if( nByte == 0 ){ if( nByte == 0 ){
return 0; return 0;
} }
zFilename = sqlite3MallocZero( nByte ); zText = sqlite3MallocZero( nByte );
if( zFilename==0 ){ if( zText==0 ){
return 0; return 0;
} }
nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte, nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideText, -1, zText, nByte,
0, 0); 0, 0);
if( nByte == 0 ){ if( nByte == 0 ){
sqlite3_free(zFilename); sqlite3_free(zText);
zFilename = 0; zText = 0;
} }
return zFilename; return zText;
} }
/* /*
@@ -1688,12 +1688,12 @@ static char *winUnicodeToUtf8(LPCWSTR zWideFilename){
** Space to hold the returned string is obtained ** Space to hold the returned string is obtained
** from sqlite3_malloc. ** from sqlite3_malloc.
*/ */
static LPWSTR winMbcsToUnicode(const char *zFilename){ static LPWSTR winMbcsToUnicode(const char *zText, int useAnsi){
int nByte; int nByte;
LPWSTR zMbcsFilename; LPWSTR zMbcsFilename;
int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP; int codepage = useAnsi ? CP_ACP : CP_OEMCP;
nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL, nByte = osMultiByteToWideChar(codepage, 0, zText, -1, NULL,
0)*sizeof(WCHAR); 0)*sizeof(WCHAR);
if( nByte==0 ){ if( nByte==0 ){
return 0; return 0;
@@ -1702,7 +1702,7 @@ static LPWSTR winMbcsToUnicode(const char *zFilename){
if( zMbcsFilename==0 ){ if( zMbcsFilename==0 ){
return 0; return 0;
} }
nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsFilename,
nByte); nByte);
if( nByte==0 ){ if( nByte==0 ){
sqlite3_free(zMbcsFilename); sqlite3_free(zMbcsFilename);
@@ -1718,60 +1718,128 @@ static LPWSTR winMbcsToUnicode(const char *zFilename){
** Space to hold the returned string is obtained from ** Space to hold the returned string is obtained from
** sqlite3_malloc(). ** sqlite3_malloc().
*/ */
static char *winUnicodeToMbcs(LPCWSTR zWideFilename){ static char *winUnicodeToMbcs(LPCWSTR zWideText, int useAnsi){
int nByte; int nByte;
char *zFilename; char *zText;
int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP; int codepage = useAnsi ? CP_ACP : CP_OEMCP;
nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0); nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, 0, 0, 0, 0);
if( nByte == 0 ){ if( nByte == 0 ){
return 0; return 0;
} }
zFilename = sqlite3MallocZero( nByte ); zText = sqlite3MallocZero( nByte );
if( zFilename==0 ){ if( zText==0 ){
return 0; return 0;
} }
nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename, nByte = osWideCharToMultiByte(codepage, 0, zWideText, -1, zText,
nByte, 0, 0); nByte, 0, 0);
if( nByte == 0 ){ if( nByte == 0 ){
sqlite3_free(zFilename); sqlite3_free(zText);
zFilename = 0; zText = 0;
} }
return zFilename; return zText;
} }
/* /*
** Convert multibyte character string to UTF-8. Space to hold the ** Convert multibyte character string to UTF-8. Space to hold the
** returned string is obtained from sqlite3_malloc(). ** returned string is obtained from sqlite3_malloc().
*/ */
char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){ char *sqlite3_win32_mbcs_to_utf8(const char *zText){
char *zFilenameUtf8; char *zTextUtf8;
LPWSTR zTmpWide; LPWSTR zTmpWide;
zTmpWide = winMbcsToUnicode(zFilename); zTmpWide = winMbcsToUnicode(zText, osAreFileApisANSI());
if( zTmpWide==0 ){ if( zTmpWide==0 ){
return 0; return 0;
} }
zFilenameUtf8 = winUnicodeToUtf8(zTmpWide); zTextUtf8 = winUnicodeToUtf8(zTmpWide);
sqlite3_free(zTmpWide); sqlite3_free(zTmpWide);
return zFilenameUtf8; return zTextUtf8;
}
/*
** Convert multibyte character string to UTF-8 using the ANSI codepage.
** Space to hold the returned string is obtained from sqlite3_malloc().
*/
char *sqlite3_win32_mbcs_to_utf8_via_ansi(const char *zText){
char *zTextUtf8;
LPWSTR zTmpWide;
zTmpWide = winMbcsToUnicode(zText, 1);
if( zTmpWide==0 ){
return 0;
}
zTextUtf8 = winUnicodeToUtf8(zTmpWide);
sqlite3_free(zTmpWide);
return zTextUtf8;
}
/*
** Convert multibyte character string to UTF-8 using the OEM codepage.
** Space to hold the returned string is obtained from sqlite3_malloc().
*/
char *sqlite3_win32_mbcs_to_utf8_via_oem(const char *zText){
char *zTextUtf8;
LPWSTR zTmpWide;
zTmpWide = winMbcsToUnicode(zText, 0);
if( zTmpWide==0 ){
return 0;
}
zTextUtf8 = winUnicodeToUtf8(zTmpWide);
sqlite3_free(zTmpWide);
return zTextUtf8;
} }
/* /*
** Convert UTF-8 to multibyte character string. Space to hold the ** Convert UTF-8 to multibyte character string. Space to hold the
** returned string is obtained from sqlite3_malloc(). ** returned string is obtained from sqlite3_malloc().
*/ */
char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){ char *sqlite3_win32_utf8_to_mbcs(const char *zText){
char *zFilenameMbcs; char *zTextMbcs;
LPWSTR zTmpWide; LPWSTR zTmpWide;
zTmpWide = winUtf8ToUnicode(zFilename); zTmpWide = winUtf8ToUnicode(zText);
if( zTmpWide==0 ){ if( zTmpWide==0 ){
return 0; return 0;
} }
zFilenameMbcs = winUnicodeToMbcs(zTmpWide); zTextMbcs = winUnicodeToMbcs(zTmpWide, osAreFileApisANSI());
sqlite3_free(zTmpWide); sqlite3_free(zTmpWide);
return zFilenameMbcs; return zTextMbcs;
}
/*
** Convert UTF-8 to multibyte character string using the ANSI codepage.
** Space to hold the returned string is obtained from sqlite3_malloc().
*/
char *sqlite3_win32_utf8_to_mbcs_via_ansi(const char *zText){
char *zTextMbcs;
LPWSTR zTmpWide;
zTmpWide = winUtf8ToUnicode(zText);
if( zTmpWide==0 ){
return 0;
}
zTextMbcs = winUnicodeToMbcs(zTmpWide, 1);
sqlite3_free(zTmpWide);
return zTextMbcs;
}
/*
** Convert UTF-8 to multibyte character string using the OEM codepage.
** Space to hold the returned string is obtained from sqlite3_malloc().
*/
char *sqlite3_win32_utf8_to_mbcs_via_oem(const char *zText){
char *zTextMbcs;
LPWSTR zTmpWide;
zTmpWide = winUtf8ToUnicode(zText);
if( zTmpWide==0 ){
return 0;
}
zTextMbcs = winUnicodeToMbcs(zTmpWide, 0);
sqlite3_free(zTmpWide);
return zTextMbcs;
} }
/* /*