1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0027838: Foundation Classes - support wchar_t* input within TCollection_AsciiString and TCollection_ExtendedString

TCollection_ExtendedString/TCollection_AsciiString description
has been updated to reflect usage of this classes for Unicode strings.

TCollection_ExtendedString now defines constructor taking wchar_t* (all platforms)
and method ::ToWideString() returning wchar_t* (Windows only).
TCollection_AsciiString now defines constructor taking wchar_t*.

TCollection_ExtendedString/TCollection_AsciiString now defines
auxiliary methods ::StartsWith() and ::EndsWith().

TCollection_ExtendedString internals has been updated to eliminate
duplicated code for converting between UTF-16 and UTF-8.

Code has been cleaned up from redundant explicit conversions to wchar_t*.
Global method OSD_OpenStream()/OSD_OpenFileBuf() have been replaced
by C++ template to eliminate copy-paste for different STL collections.

OSD_SharedLibrary now uses wide-char system API call LoadLibraryExW()
on Windows for consistency.

New macro Standard_UNUSED has been added for marking possibly unused functions and variables
(to suppress gcc/clang compiler warnings).
This commit is contained in:
kgv
2016-09-04 14:31:47 +03:00
parent 935069d23d
commit fb0b05319f
33 changed files with 654 additions and 741 deletions

View File

@@ -121,7 +121,8 @@ void OSD_Directory :: Build (const OSD_Protection& Protect) {
Standard_ProgramError :: Raise ( "OSD_Directory :: Build (): incorrect call - no directory name");
TCollection_ExtendedString dirNameW(dirName);
if (Exists() || CreateDirectoryW((const wchar_t*)dirNameW.ToExtString(), NULL)) {
if (Exists() || CreateDirectoryW (dirNameW.ToWideString(), NULL))
{
#ifndef OCCT_UWP
SetProtection(Protect);
#else
@@ -139,8 +140,7 @@ OSD_Directory OSD_Directory :: BuildTemporary () {
OSD_Protection prt;
wchar_t* aName = _wtmpnam(NULL);
NCollection_String aFolder(aName != NULL ? aName : L"");
OSD_Path dirPath(aFolder.ToCString());
OSD_Path dirPath (TCollection_AsciiString (aName != NULL ? aName : L""));
retVal.SetPath ( dirPath );
retVal.Build ( prt );

View File

@@ -239,7 +239,7 @@ Standard_Boolean OSD_DirectoryIterator :: More () {
// make wchar_t string from UTF-8
TCollection_ExtendedString wcW(wc);
myHandle = FindFirstFileExW ((const wchar_t*)wcW.ToExtString(), FindExInfoStandard, (PWIN32_FIND_DATAW)myData, FindExSearchNameMatch, NULL, 0);
myHandle = FindFirstFileExW (wcW.ToWideString(), FindExInfoStandard, (PWIN32_FIND_DATAW)myData, FindExSearchNameMatch, NULL, 0);
if ( myHandle == INVALID_HANDLE_VALUE )

View File

@@ -180,8 +180,7 @@ OSD_Disk :: OSD_Disk () {
if (aBuffLen > 3 && aBuff[0] != L'\\')
{
aBuff[3] = L'\0';
NCollection_String aFolder(aBuff);
DiskName = aFolder.ToCString();
DiskName = TCollection_AsciiString (aBuff);
delete[] aBuff;
}
else
@@ -234,7 +233,7 @@ Standard_Integer OSD_Disk :: DiskSize () {
ULARGE_INTEGER lpTotalNumberOfFreeBytes;// receives the free bytes on disk
TCollection_ExtendedString DiskNameW(DiskName);
if (!GetDiskFreeSpaceExW ((const wchar_t*)DiskNameW.ToExtString(),
if (!GetDiskFreeSpaceExW (DiskNameW.ToWideString(),
&lpFreeBytesAvailableToCaller,
&lpTotalNumberOfBytes,
&lpTotalNumberOfFreeBytes))
@@ -272,7 +271,7 @@ Standard_Integer OSD_Disk :: DiskFree () {
// if ( !GetDiskFreeSpace ( DiskName.ToCString (), &dwSpC, &dwBpS, &dwFC, &dwC ) )
TCollection_ExtendedString DiskNameW(DiskName);
if (!GetDiskFreeSpaceExW((const wchar_t*)DiskNameW.ToExtString(),
if (!GetDiskFreeSpaceExW (DiskNameW.ToWideString(),
&lpFreeBytesAvailableToCaller,
&lpTotalNumberOfBytes,
&lpTotalNumberOfFreeBytes))

View File

@@ -823,7 +823,7 @@ void OSD_File::Rewind() {
void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
#ifndef OCCT_UWP
PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd ( const OSD_Protection&, BOOL, wchar_t* = NULL );
PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd ( const OSD_Protection&, BOOL, const wchar_t* );
BOOL __fastcall _osd_wnt_sd_to_protection (
PSECURITY_DESCRIPTOR, OSD_Protection&, BOOL
);
@@ -1653,7 +1653,7 @@ Standard_Boolean OSD_File :: IsOpen () const {
#ifndef OCCT_UWP
PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd (
const OSD_Protection& prot, BOOL fDir, wchar_t* fName
const OSD_Protection& prot, BOOL fDir, const wchar_t* fName
) {
int i, j;
@@ -2289,7 +2289,7 @@ static HANDLE __fastcall _open_file (
TCollection_ExtendedString fNameW(fName, Standard_True);
#ifndef OCCT_UWP
retVal = CreateFileW (
(const wchar_t*) fNameW.ToExtString(), dwDesiredAccess,
fNameW.ToWideString(), dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, dwCreationDistribution, FILE_ATTRIBUTE_NORMAL, NULL
);
@@ -2300,7 +2300,7 @@ static HANDLE __fastcall _open_file (
pCreateExParams.lpSecurityAttributes = NULL;
pCreateExParams.hTemplateFile = NULL;
retVal = CreateFile2 (
(const wchar_t*) fNameW.ToExtString(), dwDesiredAccess,
fNameW.ToWideString(), dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE,
dwCreationDistribution, &pCreateExParams
);
@@ -2314,7 +2314,7 @@ static HANDLE __fastcall _open_file (
dwCreationDistribution = CREATE_ALWAYS;
#ifndef OCCT_UWP
retVal = CreateFileW (
(const wchar_t*) fNameW.ToExtString(), dwDesiredAccess,
fNameW.ToWideString(), dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, dwCreationDistribution, FILE_ATTRIBUTE_NORMAL, NULL
);
@@ -2325,7 +2325,7 @@ static HANDLE __fastcall _open_file (
pCreateExParams2.lpSecurityAttributes = NULL;
pCreateExParams2.hTemplateFile = NULL;
retVal = CreateFile2(
(const wchar_t*)fNameW.ToExtString(), dwDesiredAccess,
fNameW.ToWideString(), dwDesiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE,
dwCreationDistribution, &pCreateExParams2
);
@@ -2363,7 +2363,7 @@ Standard_Integer __fastcall _get_file_type (
TCollection_ExtendedString fNameW(fName, Standard_True);
WIN32_FILE_ATTRIBUTE_DATA aFileInfo;
if (GetFileAttributesExW((const wchar_t*)fNameW.ToExtString(), GetFileExInfoStandard, &aFileInfo))
if (GetFileAttributesExW (fNameW.ToWideString(), GetFileExInfoStandard, &aFileInfo))
retVal = aFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? FLAG_DIRECTORY : FLAG_FILE;

View File

@@ -317,7 +317,7 @@ Standard_Boolean OSD_FileIterator :: More () {
// make wchar_t string from UTF-8
TCollection_ExtendedString wcW(wc);
myHandle = FindFirstFileExW((const wchar_t*)wcW.ToExtString(), FindExInfoStandard, (PWIN32_FIND_DATAW)myData, FindExSearchNameMatch, NULL, 0);
myHandle = FindFirstFileExW (wcW.ToWideString(), FindExInfoStandard, (PWIN32_FIND_DATAW)myData, FindExSearchNameMatch, NULL, 0);
if ( myHandle == INVALID_HANDLE_VALUE )

View File

@@ -387,7 +387,7 @@ Standard_Integer OSD_FileNode::Error()const{
#ifndef OCCT_UWP
// None of the existing security APIs are supported in a UWP applications
PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd ( const OSD_Protection&, BOOL, wchar_t* = NULL );
PSECURITY_DESCRIPTOR __fastcall _osd_wnt_protection_to_sd ( const OSD_Protection&, BOOL, const wchar_t* );
BOOL __fastcall _osd_wnt_sd_to_protection (
PSECURITY_DESCRIPTOR pSD, OSD_Protection& prot, BOOL
);
@@ -396,7 +396,7 @@ Standard_Integer __fastcall _get_file_type ( Standard_CString, HANDLE );
void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
static BOOL __fastcall _get_file_time ( Standard_ExtString, LPSYSTEMTIME, BOOL );
static BOOL __fastcall _get_file_time (const wchar_t*, LPSYSTEMTIME, BOOL );
static void __fastcall _test_raise ( TCollection_AsciiString, Standard_CString );
//=======================================================================
@@ -460,14 +460,17 @@ Standard_Boolean OSD_FileNode::Exists () {
WIN32_FILE_ATTRIBUTE_DATA aFileInfo;
if ( !GetFileAttributesExW((const wchar_t*)fNameW.ToExtString(), GetFileExInfoStandard, &aFileInfo)) {
if ( GetLastError () != ERROR_FILE_NOT_FOUND )
_osd_wnt_set_error(myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString());
} else
if (!GetFileAttributesExW (fNameW.ToWideString(), GetFileExInfoStandard, &aFileInfo))
{
if (GetLastError() != ERROR_FILE_NOT_FOUND)
{
_osd_wnt_set_error (myError, OSD_WFileNode, fNameW.ToWideString());
}
}
else
{
retVal = Standard_True;
}
return retVal;
@@ -491,8 +494,8 @@ void OSD_FileNode::Remove () {
case FLAG_FILE:
if ( !DeleteFileW ( (const wchar_t*) fNameW.ToExtString () ) )
_osd_wnt_set_error ( myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString());
if (!DeleteFileW (fNameW.ToWideString()))
_osd_wnt_set_error ( myError, OSD_WFileNode, fNameW.ToWideString());
break;
case FLAG_DIRECTORY:
@@ -501,8 +504,8 @@ void OSD_FileNode::Remove () {
// LD : Suppression de l'appel a DeleteDirectory pour
// ne pas detruire un repertoire no vide.
if ( !RemoveDirectoryW ( (const wchar_t*) fNameW.ToExtString () ) )
_osd_wnt_set_error ( myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString());
if (!RemoveDirectoryW (fNameW.ToWideString()))
_osd_wnt_set_error (myError, OSD_WFileNode, fNameW.ToWideString());
break;
default:
@@ -533,21 +536,16 @@ void OSD_FileNode::Move ( const OSD_Path& NewPath ) {
case FLAG_FILE:
if (!MoveFileExW ((const wchar_t*)fNameW.ToExtString (),
(const wchar_t*)fNameDstW.ToExtString (),
MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED
)
)
_osd_wnt_set_error(myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString(), (const wchar_t*)fNameDstW.ToExtString());
if (!MoveFileExW (fNameW.ToWideString (),
fNameDstW.ToWideString (),
MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED))
_osd_wnt_set_error(myError, OSD_WFileNode, fNameW.ToWideString(), fNameDstW.ToWideString());
break;
case FLAG_DIRECTORY:
if ( !MoveDirectory (
(const wchar_t*) fNameW.ToExtString (), (const wchar_t*) fNameDstW.ToExtString ()
)
)
_osd_wnt_set_error(myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString(), (const wchar_t*)fNameDstW.ToExtString());
if (!MoveDirectory (fNameW.ToWideString(), fNameDstW.ToWideString()))
_osd_wnt_set_error(myError, OSD_WFileNode, fNameW.ToWideString(), fNameDstW.ToWideString());
break;
default:
@@ -578,23 +576,17 @@ void OSD_FileNode::Copy ( const OSD_Path& ToPath ) {
case FLAG_FILE:
#ifndef OCCT_UWP
if (!CopyFileW((const wchar_t*)fNameW.ToExtString(),
(const wchar_t*)fNameDstW.ToExtString(), FALSE))
if (!CopyFileW (fNameW.ToWideString(), fNameDstW.ToWideString(), FALSE))
#else
if (CopyFile2((const wchar_t*)fNameW.ToExtString (),
(const wchar_t*)fNameDstW.ToExtString (), FALSE ) != S_OK)
if (CopyFile2 (fNameW.ToWideString(), fNameDstW.ToWideString(), FALSE) != S_OK)
#endif
_osd_wnt_set_error(myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString(), (const wchar_t*)fNameDstW.ToExtString());
_osd_wnt_set_error (myError, OSD_WFileNode, fNameW.ToWideString(), fNameDstW.ToWideString());
break;
case FLAG_DIRECTORY:
if ( !CopyDirectory (
(const wchar_t*)fNameW.ToExtString (), (const wchar_t*)fNameDstW.ToExtString ()
)
)
_osd_wnt_set_error(myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString(), (const wchar_t*)fNameDstW.ToExtString());
if (!CopyDirectory (fNameW.ToWideString(), fNameDstW.ToWideString()))
_osd_wnt_set_error (myError, OSD_WFileNode, fNameW.ToWideString(), fNameDstW.ToWideString());
break;
@@ -624,12 +616,8 @@ OSD_Protection OSD_FileNode::Protection () {
TEST_RAISE( "Protection" );
if ( ( pSD = GetFileSecurityEx (
(const wchar_t*) fNameW.ToExtString (), DACL_SECURITY_INFORMATION |
OWNER_SECURITY_INFORMATION
)
) == NULL ||
!_osd_wnt_sd_to_protection (
if ((pSD = GetFileSecurityEx (fNameW.ToWideString(), DACL_SECURITY_INFORMATION |OWNER_SECURITY_INFORMATION)) == NULL
|| !_osd_wnt_sd_to_protection (
pSD, retVal,
_get_file_type (fName.ToCString(), INVALID_HANDLE_VALUE) == FLAG_DIRECTORY)
)
@@ -659,18 +647,12 @@ void OSD_FileNode::SetProtection ( const OSD_Protection& Prot ) {
TEST_RAISE( "SetProtection" );
pSD = _osd_wnt_protection_to_sd (
Prot,
_get_file_type (fName.ToCString(), INVALID_HANDLE_VALUE) ==
FLAG_DIRECTORY,
(wchar_t *)fNameW.ToExtString ()
);
pSD = _osd_wnt_protection_to_sd (Prot,
_get_file_type (fName.ToCString(), INVALID_HANDLE_VALUE) == FLAG_DIRECTORY,
fNameW.ToWideString());
if ( pSD == NULL || !SetFileSecurityW (
(const wchar_t*) fNameW.ToExtString (), DACL_SECURITY_INFORMATION, pSD
)
)
_osd_wnt_set_error ( myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString());
if (pSD == NULL || !SetFileSecurityW (fNameW.ToWideString(), DACL_SECURITY_INFORMATION, pSD))
_osd_wnt_set_error (myError, OSD_WFileNode, fNameW.ToWideString());
if ( pSD != NULL )
@@ -695,11 +677,11 @@ OSD_Protection OSD_FileNode::Protection ()
TCollection_ExtendedString fNameW(fName);
OSD_SingleProtection aProt = OSD_None;
if (_waccess_s ((const wchar_t*)fNameW.ToExtString(), 6))
if (_waccess_s (fNameW.ToWideString(), 6))
aProt = OSD_RW;
else if (_waccess_s ((const wchar_t*)fNameW.ToExtString(), 2))
else if (_waccess_s (fNameW.ToWideString(), 2))
aProt = OSD_W;
else if (_waccess_s ((const wchar_t*)fNameW.ToExtString(), 4))
else if (_waccess_s (fNameW.ToWideString(), 4))
aProt = OSD_R;
// assume full access for system and none for everybody
@@ -735,9 +717,7 @@ Quantity_Date OSD_FileNode::AccessMoment () {
TEST_RAISE( "AccessMoment" );
// if ( _get_file_time ( fName.ToCString (), &stAccessMoment, TRUE ) )
if ( _get_file_time ( fNameW.ToExtString (), &stAccessSystemMoment, TRUE ) )
//POP
if (_get_file_time (fNameW.ToWideString(), &stAccessSystemMoment, TRUE))
{
SYSTEMTIME * aSysTime = &stAccessMoment;
BOOL aFlag = SystemTimeToTzSpecificLocalTime (NULL ,
@@ -752,7 +732,9 @@ Quantity_Date OSD_FileNode::AccessMoment () {
);
}
else
_osd_wnt_set_error ( myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString());
{
_osd_wnt_set_error (myError, OSD_WFileNode, fNameW.ToWideString());
}
return retVal;
@@ -775,9 +757,7 @@ Quantity_Date OSD_FileNode::CreationMoment () {
TEST_RAISE( "CreationMoment" );
// if ( _get_file_time ( fName.ToCString (), &stCreationMoment, FALSE ) )
if ( _get_file_time ( fNameW.ToExtString (), &stCreationSystemMoment, TRUE ) )
//POP
if (_get_file_time (fNameW.ToWideString(), &stCreationSystemMoment, TRUE))
{
SYSTEMTIME * aSysTime = &stCreationMoment;
BOOL aFlag = SystemTimeToTzSpecificLocalTime (NULL,
@@ -792,7 +772,9 @@ Quantity_Date OSD_FileNode::CreationMoment () {
);
}
else
_osd_wnt_set_error ( myError, OSD_WFileNode, (const wchar_t*)fNameW.ToExtString());
{
_osd_wnt_set_error (myError, OSD_WFileNode, fNameW.ToWideString());
}
return retVal;
@@ -880,10 +862,8 @@ void _osd_wnt_set_error ( OSD_Error& err, OSD_WhoAmI who, ... ) {
#define __leave return retVal
#endif
static BOOL __fastcall _get_file_time (
Standard_ExtString fName, LPSYSTEMTIME lpSysTime, BOOL fAccess
) {
static BOOL __fastcall _get_file_time (const wchar_t* fName, LPSYSTEMTIME lpSysTime, BOOL fAccess)
{
BOOL retVal = FALSE;
FILETIME ftCreationTime;
FILETIME ftLastWriteTime;
@@ -892,7 +872,7 @@ static BOOL __fastcall _get_file_time (
__try {
#ifndef OCCT_UWP
if ((hFile = CreateFileW((const wchar_t*)fName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
if ((hFile = CreateFileW (fName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
) == INVALID_HANDLE_VALUE
)
#else
@@ -901,11 +881,7 @@ static BOOL __fastcall _get_file_time (
pCreateExParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
pCreateExParams.lpSecurityAttributes = NULL;
pCreateExParams.hTemplateFile = NULL;
if ((hFile = CreateFile2(
(const wchar_t*)fName, NULL, NULL,
OPEN_EXISTING, &pCreateExParams)
) == INVALID_HANDLE_VALUE
)
if ((hFile = CreateFile2 (fName, NULL, NULL, OPEN_EXISTING, &pCreateExParams)) == INVALID_HANDLE_VALUE)
#endif
__leave;

View File

@@ -16,8 +16,6 @@
#endif
#include <OSD_OpenFile.hxx>
#include <TCollection_ExtendedString.hxx>
#include <NCollection_UtfString.hxx>
#include <sys/types.h>
#include <sys/stat.h>
@@ -34,8 +32,8 @@ FILE* OSD_OpenFile(const char* theName,
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
const TCollection_ExtendedString aFileModeW (theMode, Standard_True);
aFile = ::_wfopen ((const wchar_t* )aFileNameW.ToExtString(),
(const wchar_t* )aFileModeW.ToExtString());
aFile = ::_wfopen (aFileNameW.ToWideString(),
aFileModeW.ToWideString());
#else
aFile = ::fopen (theName, theMode);
#endif
@@ -52,118 +50,16 @@ FILE* OSD_OpenFile(const TCollection_ExtendedString& theName,
FILE* aFile = 0;
#if defined(_WIN32)
const TCollection_ExtendedString aFileModeW (theMode, Standard_True);
aFile = ::_wfopen ((const wchar_t* )theName.ToExtString(),
(const wchar_t* )aFileModeW.ToExtString());
aFile = ::_wfopen (theName.ToWideString(),
aFileModeW.ToWideString());
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
NCollection_Utf8String aString (theName.ToExtString());
aFile = ::fopen (aString.ToCString(),theMode);
#endif
return aFile;
}
// ==============================================
// function : OSD_OpenFileBuf
// purpose : Opens file buffer
// ==============================================
void OSD_OpenFileBuf(std::filebuf& theBuff,
const char* theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
theBuff.open ((const wchar_t* )aFileNameW.ToExtString(), theMode);
#else
theBuff.open (theName, theMode);
#endif
}
// ==============================================
// function : OSD_OpenFileBuf
// purpose : Opens file buffer
// ==============================================
void OSD_OpenFileBuf(std::filebuf& theBuff,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
theBuff.open ((const wchar_t* )theName.ToExtString(), theMode);
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
theBuff.open (aString.ToCString(),theMode);
#endif
}
// ==============================================
// function : OSD_OpenStream
// purpose : Opens file stream
// ==============================================
void OSD_OpenStream(std::ofstream& theStream,
const char* theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
theStream.open ((const wchar_t* )aFileNameW.ToExtString(), theMode);
#else
theStream.open (theName, theMode);
#endif
}
// ==============================================
// function : OSD_OpenStream
// purpose : Opens file stream
// ==============================================
void OSD_OpenStream(std::ofstream& theStream,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
theStream.open ((const wchar_t* )theName.ToExtString(), theMode);
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
theStream.open (aString.ToCString(),theMode);
#endif
}
// ==============================================
// function : OSD_OpenStream
// purpose : Opens file stream
// ==============================================
void OSD_OpenStream (std::ifstream& theStream,
const char* theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
theStream.open ((const wchar_t*)aFileNameW.ToExtString(), theMode);
#else
theStream.open (theName, theMode);
#endif
}
// ==============================================
// function : OSD_OpenStream
// purpose : Opens file stream
// ==============================================
void OSD_OpenStream (std::ifstream& theStream,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
theStream.open ((const wchar_t*)theName.ToExtString(), theMode);
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString ((const Standard_Utf16Char*)theName.ToExtString());
theStream.open (aString.ToCString(), theMode);
#endif
}
// ==============================================
// function : OSD_FileStatCTime
// purpose :
@@ -175,7 +71,7 @@ Standard_Time OSD_FileStatCTime (const char* theName)
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
struct __stat64 aStat;
if (_wstat64 ((const wchar_t* )aFileNameW.ToExtString(), &aStat) == 0)
if (_wstat64 (aFileNameW.ToWideString(), &aStat) == 0)
{
aTime = (Standard_Time )aStat.st_ctime;
}

View File

@@ -23,55 +23,7 @@
#include <fstream>
#include <TCollection_ExtendedString.hxx>
//! Function opens the file stream.
//! @param theStream stream to open
//! @param theName name of file encoded in UTF-8
//! @param theMode opening mode
__Standard_API void OSD_OpenStream (std::ofstream& theStream,
const char* theName,
const std::ios_base::openmode theMode);
//! Function opens the file stream.
//! @param theStream stream to open
//! @param theName name of file encoded in UTF-16
//! @param theMode opening mode
__Standard_API void OSD_OpenStream (std::ofstream& theStream,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode);
//! Function opens the file stream.
//! @param theStream stream to open
//! @param theName name of file encoded in UTF-8
//! @param theMode opening mode
__Standard_API void OSD_OpenStream (std::ifstream& theStream,
const char* theName,
const std::ios_base::openmode theMode);
//! Function opens the file stream.
//! @param theStream stream to open
//! @param theName name of file encoded in UTF-16
//! @param theMode opening mode
__Standard_API void OSD_OpenStream (std::ifstream& theStream,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode);
//! Function opens the file buffer.
//! @param theBuff file buffer to open
//! @param theName name of file encoded in UTF-8
//! @param theMode opening mode
__Standard_API void OSD_OpenFileBuf (std::filebuf& theBuff,
const char* theName,
const std::ios_base::openmode theMode);
//! Function opens the file buffer.
//! @param theBuff file buffer to open
//! @param theName name of file encoded in UTF-16
//! @param theMode opening mode
__Standard_API void OSD_OpenFileBuf (std::filebuf& theBuff,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode);
#include <NCollection_UtfString.hxx>
//! Function opens the file.
//! @param theName name of file encoded in UTF-16
@@ -85,6 +37,42 @@ __Standard_API FILE* OSD_OpenFile (const TCollection_ExtendedString& theName,
//! @return stat.st_ctime value
__Standard_API Standard_Time OSD_FileStatCTime (const char* theName);
//! Function opens the file stream.
//! @param theStream stream to open
//! @param theName name of file encoded in UTF-8
//! @param theMode opening mode
template <typename T>
inline void OSD_OpenStream (T& theStream,
const char* theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
theStream.open (aFileNameW.ToWideString(), theMode);
#else
theStream.open (theName, theMode);
#endif
}
//! Function opens the file stream.
//! @param theStream stream to open
//! @param theName name of file encoded in UTF-16
//! @param theMode opening mode
template <typename T>
inline void OSD_OpenStream (T& theStream,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
theStream.open (theName.ToWideString(), theMode);
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString (theName.ToExtString());
theStream.open (aString.ToCString(), theMode);
#endif
}
extern "C" {
#endif // __cplusplus

View File

@@ -353,10 +353,10 @@ OSD_Path OSD_Process :: CurrentDirectory () {
DWORD dwSize = PATHLEN + 1;
Standard_WideChar* pBuff = new wchar_t[dwSize];
if ( GetCurrentDirectoryW(dwSize, (wchar_t*)pBuff) > 0 )
if (GetCurrentDirectoryW (dwSize, pBuff) > 0)
{
// conversion to UTF-8 is performed inside
TCollection_AsciiString aPath(TCollection_ExtendedString((Standard_ExtString)pBuff));
TCollection_AsciiString aPath (pBuff);
anCurrentDirectory = OSD_Path ( aPath );
}
else
@@ -374,7 +374,7 @@ void OSD_Process :: SetCurrentDirectory ( const OSD_Path& where ) {
where.SystemName ( path );
TCollection_ExtendedString pathW(path);
if ( !::SetCurrentDirectoryW ( (const wchar_t*) pathW.ToExtString () ) )
if (!::SetCurrentDirectoryW (pathW.ToWideString()))
_osd_wnt_set_error ( myError, OSD_WProcess );

View File

@@ -226,11 +226,11 @@ void OSD_SharedLibrary :: SetName ( const Standard_CString aName ) {
name = path.Name ();
name.AssignCat ( path.Extension () );
TCollection_ExtendedString nameW (name);
#ifndef OCCT_UWP
myHandle = GetModuleHandle(name.ToCString());
myHandle = GetModuleHandleW (nameW.ToWideString());
#else
TCollection_ExtendedString nameW(name);
myHandle = LoadPackagedLibrary ((const wchar_t*)nameW.ToExtString(), NULL );
myHandle = LoadPackagedLibrary (nameW.ToWideString(), NULL);
FreeLibrary ((HMODULE) myHandle);
#endif
@@ -246,12 +246,13 @@ Standard_Boolean OSD_SharedLibrary :: DlOpen ( const OSD_LoadMode /*Mode*/ ) {
Standard_Boolean retVal = Standard_True;
if ( myHandle == NULL ) {
if (myHandle == NULL)
{
TCollection_ExtendedString myNameW (myName);
#ifndef OCCT_UWP
myHandle = (HINSTANCE)LoadLibraryEx(myName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
myHandle = (HINSTANCE)LoadLibraryExW (myNameW.ToWideString(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
#else
TCollection_ExtendedString myNameW(myName);
myHandle = (HINSTANCE)LoadPackagedLibrary((const wchar_t*)myNameW.ToExtString(), NULL);
myHandle = (HINSTANCE)LoadPackagedLibrary (myNameW.ToWideString(), NULL);
#endif
if ( myHandle == NULL ) {
lastDLLError = GetLastError ();