1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

0025367: IGES and BRep persistence - support unicode file names on Windows

OSD_OpenFile.hxx header is created for using in file open operations with Unicode names.

Fix for STEP files reading.

Adding test cases for issue 25367
Update test case for issue 25364
Update test cases due to improvements
This commit is contained in:
pdn
2014-10-22 12:17:10 +04:00
committed by bugmaster
parent 2caff0b32f
commit 947085567f
27 changed files with 341 additions and 80 deletions

View File

@@ -17,3 +17,5 @@ OSD_MAllocHook.cxx
OSD_MAllocHook.hxx
OSD_MemInfo.hxx
OSD_MemInfo.cxx
OSD_OpenFile.hxx
OSD_OpenFile.cxx

125
src/OSD/OSD_OpenFile.cxx Normal file
View File

@@ -0,0 +1,125 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <OSD_OpenFile.hxx>
#include <TCollection_ExtendedString.hxx>
#include <NCollection_UtfString.hxx>
// ==============================================
// function : OSD_OpenFile
// purpose : Opens file
// ==============================================
FILE* OSD_OpenFile(const char* theName,
const char* theMode)
{
FILE* aFile = 0;
#ifdef _WIN32
// 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());
#else
aFile = ::fopen (theName, theMode);
#endif
return aFile;
}
// ==============================================
// function : OSD_OpenFile
// purpose : Opens file
// ==============================================
FILE* OSD_OpenFile(const TCollection_ExtendedString& theName,
const char* theMode)
{
FILE* aFile = 0;
#ifdef _WIN32
const TCollection_ExtendedString aFileModeW (theMode, Standard_True);
aFile = ::_wfopen ((const wchar_t* )theName.ToExtString(),
(const wchar_t* )aFileModeW.ToExtString());
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString((const Standard_Utf16Char*)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)
{
#ifdef _WIN32
// 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)
{
#ifdef _WIN32
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)
{
#ifdef _WIN32
// 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)
{
#ifdef _WIN32
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
}

80
src/OSD/OSD_OpenFile.hxx Normal file
View File

@@ -0,0 +1,80 @@
// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
//! Auxiulary file to provide Unicode compatibility for file open functionality
//! Names of files are encoded as UTF-16 strings
#ifndef _OSD_OpenFile_HeaderFile
#define _OSD_OpenFile_HeaderFile
#include <Standard_Macro.hxx>
#if defined(__cplusplus)
#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 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);
//! Function opens the file.
//! @param theName name of file encoded in UTF-16
//! @param theMode opening mode
//! @return file handle of opened file
__Standard_API FILE* OSD_OpenFile (const TCollection_ExtendedString& theName,
const char* theMode);
extern "C" {
#endif // __cplusplus
//! Function opens the file.
//! @param theName name of file encoded in UTF-8
//! @param theMode opening mode
//! @return file handle of opened file
__Standard_API FILE* OSD_OpenFile (const char* theName, const char* theMode);
#if defined(__cplusplus)
}
#endif // __cplusplus
#endif // _OSD_OpenFile_HeaderFile