Skip to content
Snippets Groups Projects
Commit 2b0c683d authored by Clinton Stimpson's avatar Clinton Stimpson Committed by Brad King
Browse files

Encoding: Default to ANSI code page on Windows

Create a KWSYS_ENCODING_DEFAULT_CODEPAGE setting that can be used
by parent projects to configure the default code page.  Default
to CP_ACP (ANSI Code Page) so that our narrow->wide conversions
used to access wide Windows APIs are equivalent to direct use of
the narrow Windows APIs.

Change-Id: I02ce362dbdc6127f42b7af7e620e46b7829cbc64
parent 0a98de97
No related branches found
No related tags found
No related merge requests found
......@@ -166,6 +166,11 @@ ELSE(KWSYS_LFS_DISABLE)
SET(KWSYS_LFS_REQUESTED 1)
ENDIF(KWSYS_LFS_DISABLE)
# Specify default 8 bit encoding for Windows
IF(NOT KWSYS_ENCODING_DEFAULT_CODEPAGE)
SET(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_ACP)
ENDIF(NOT KWSYS_ENCODING_DEFAULT_CODEPAGE)
# Enable testing if building standalone.
IF(KWSYS_STANDALONE)
INCLUDE(Dart)
......@@ -1074,6 +1079,12 @@ IF(KWSYS_USE_String)
COMPILE_FLAGS "-DKWSYS_STRING_C")
ENDIF(KWSYS_USE_String)
IF(KWSYS_USE_Encoding)
# Set default 8 bit encoding in "EndcodingC.c".
SET_PROPERTY(SOURCE EncodingC.c APPEND PROPERTY COMPILE_DEFINITIONS
KWSYS_ENCODING_DEFAULT_CODEPAGE=${KWSYS_ENCODING_DEFAULT_CODEPAGE})
ENDIF(KWSYS_USE_Encoding)
#-----------------------------------------------------------------------------
# Setup testing if not being built as part of another project.
IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
......
......@@ -31,7 +31,7 @@ size_t kwsysEncoding_mbstowcs(wchar_t* dest, const char* str, size_t n)
return (size_t)-1;
}
#ifdef _WIN32
return MultiByteToWideChar(CP_UTF8, 0,
return MultiByteToWideChar(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0,
str, -1, dest, (int)n) - 1;
#else
return mbstowcs(dest, str, n);
......@@ -58,7 +58,7 @@ size_t kwsysEncoding_wcstombs(char* dest, const wchar_t* str, size_t n)
return (size_t)-1;
}
#ifdef _WIN32
return WideCharToMultiByte(CP_UTF8, 0, str, -1,
return WideCharToMultiByte(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, str, -1,
dest, (int)n, NULL, NULL) - 1;
#else
return wcstombs(dest, str, n);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment