1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0030694: Data Exchange - support non-standard GB2312-encoded STEP files

STEPCAFControl_Reader::SourceCodePage() - added property defining text encoding
for converting names within STEPCAFControl_Reader::ReadNames() method.
Added associated "read.stepcaf.codepage" parameter,
which default value is Resource_UTF8, preserving current behavior.

Resource_FormatType enumeration has been extended by UTF8 and SystemLocale values.
Resource_Unicode - added conversion methods taking Resource_FormatType as argument.

GetName command has been corrected to NOT replace non-Latin symbols.
This commit is contained in:
kgv
2019-05-06 16:00:16 +03:00
committed by bugmaster
parent 48ba181118
commit e3249d8e5a
11 changed files with 265 additions and 127 deletions

View File

@@ -17,18 +17,23 @@
#ifndef _Resource_FormatType_HeaderFile
#define _Resource_FormatType_HeaderFile
//! List of non ASCII format types which may be
//! converted into the Unicode 16 bits format type.
//! Use the functions provided by the
//! Resource_Unicode class to convert a string
//! List of non ASCII format types which may be converted into the Unicode 16 bits format type.
//! Use the functions provided by the Resource_Unicode class to convert a string
//! from one of these non ASCII format to Unicode, and vice versa.
enum Resource_FormatType
{
Resource_SJIS,
Resource_EUC,
Resource_ANSI,
Resource_GB
Resource_FormatType_SJIS, //!< SJIS (Shift Japanese Industrial Standards) encoding
Resource_FormatType_EUC, //!< EUC (Extended Unix Code) multi-byte encoding primarily for Japanese, Korean, and simplified Chinese
Resource_FormatType_ANSI, //!< ANSI encoding (pass through without conversion)
Resource_FormatType_GB, //!< GB (Guobiao) encoding for Simplified Chinese
Resource_FormatType_UTF8, //!< multi-byte UTF-8 encoding
Resource_FormatType_SystemLocale, //!< active system-defined locale; this value is strongly NOT recommended to use
// old aliases
Resource_SJIS = Resource_FormatType_SJIS,
Resource_EUC = Resource_FormatType_EUC,
Resource_ANSI = Resource_FormatType_ANSI,
Resource_GB = Resource_FormatType_GB,
};
#endif // _Resource_FormatType_HeaderFile

View File

@@ -596,57 +596,80 @@ void Resource_Unicode::ReadFormat()
Resource_Unicode::GetFormat();
}
void Resource_Unicode::ConvertFormatToUnicode(const Standard_CString fromstr,
TCollection_ExtendedString& tostr)
void Resource_Unicode::ConvertFormatToUnicode (const Resource_FormatType theFormat,
const Standard_CString theFromStr,
TCollection_ExtendedString& theToStr)
{
Resource_FormatType theform = Resource_Unicode::GetFormat();
switch (theform) {
case Resource_SJIS :
switch (theFormat)
{
case Resource_FormatType_SJIS:
{
ConvertSJISToUnicode(fromstr,tostr);
ConvertSJISToUnicode (theFromStr, theToStr);
break;
}
case Resource_EUC :
case Resource_FormatType_EUC:
{
ConvertEUCToUnicode(fromstr,tostr);
ConvertEUCToUnicode(theFromStr, theToStr);
break;
}
case Resource_GB :
case Resource_FormatType_GB:
{
ConvertGBToUnicode(fromstr,tostr);
ConvertGBToUnicode(theFromStr, theToStr);
break;
}
case Resource_ANSI :
case Resource_FormatType_ANSI:
case Resource_FormatType_UTF8:
{
ConvertANSIToUnicode(fromstr,tostr);
theToStr = TCollection_ExtendedString (theFromStr, theFormat == Resource_FormatType_UTF8);
break;
}
case Resource_FormatType_SystemLocale:
{
NCollection_Utf16String aString;
aString.FromLocale (theFromStr);
theToStr = TCollection_ExtendedString (aString.ToCString());
break;
}
}
}
Standard_Boolean Resource_Unicode::ConvertUnicodeToFormat(const TCollection_ExtendedString& fromstr,
Standard_PCharacter& tostr,
const Standard_Integer maxsize)
Standard_Boolean Resource_Unicode::ConvertUnicodeToFormat(const Resource_FormatType theFormat,
const TCollection_ExtendedString& theFromStr,
Standard_PCharacter& theToStr,
const Standard_Integer theMaxSize)
{
Resource_FormatType theform = Resource_Unicode::GetFormat();
switch (theform) {
case Resource_SJIS :
switch (theFormat)
{
case Resource_FormatType_SJIS:
{
return ConvertUnicodeToSJIS(fromstr,tostr,maxsize);
return ConvertUnicodeToSJIS (theFromStr, theToStr, theMaxSize);
}
case Resource_EUC :
case Resource_FormatType_EUC:
{
return ConvertUnicodeToEUC(fromstr,tostr,maxsize);
return ConvertUnicodeToEUC (theFromStr, theToStr, theMaxSize);
}
case Resource_GB :
case Resource_FormatType_GB:
{
return ConvertUnicodeToGB(fromstr,tostr,maxsize);
return ConvertUnicodeToGB (theFromStr, theToStr, theMaxSize);
}
case Resource_ANSI :
case Resource_FormatType_ANSI:
{
return ConvertUnicodeToANSI(fromstr,tostr,maxsize);
return ConvertUnicodeToANSI (theFromStr, theToStr, theMaxSize);
}
case Resource_FormatType_UTF8:
{
if (theMaxSize < theFromStr.LengthOfCString())
{
return Standard_False;
}
theFromStr.ToUTF8CString (theToStr);
return Standard_True;
}
case Resource_FormatType_SystemLocale:
{
const NCollection_Utf16String aString (theFromStr.ToExtString());
return aString.ToLocale (theToStr, theMaxSize);
}
}
return Standard_False;
}

View File

@@ -107,47 +107,44 @@ public:
//! in Resource Manager "CharSet"
Standard_EXPORT static void ReadFormat();
//! Converts the non-ASCII C string fromstr to the
//! Unicode string of extended characters tostr.
//! fromstr is translated according to the format
//! (either ANSI, EUC, GB or SJIS) returned by the function GetFormat.
Standard_EXPORT static void ConvertFormatToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
//! Converts the non-ASCII C string (as specified by GetFormat()) to the Unicode string of extended characters.
static void ConvertFormatToUnicode (const Standard_CString theFromStr,
TCollection_ExtendedString& theToStr)
{
return ConvertFormatToUnicode (Resource_Unicode::GetFormat(), theFromStr, theToStr);
}
//! Converts the non-ASCII C string in specified format to the Unicode string of extended characters.
//! @param theFormat [in] source encoding
//! @param theFromStr [in] text to convert
//! @param theToStr [out] destination string
Standard_EXPORT static void ConvertFormatToUnicode (const Resource_FormatType theFormat,
const Standard_CString theFromStr,
TCollection_ExtendedString& theToStr);
//! Converts the Unicode string of extended characters to the non-ASCII string according to specified format.
//! You need more than twice the length of the source string to complete the conversion.
//! The function returns true if conversion is complete, i.e. the maximum number of characters is not reached before the end of conversion.
//! @param theFormat [in] destination encoding
//! @param theFromStr [in] text to convert
//! @param theToStr [out] destination buffer
//! @param theMaxSize [in] destination buffer length
Standard_EXPORT static Standard_Boolean ConvertUnicodeToFormat (const Resource_FormatType theFormat,
const TCollection_ExtendedString& theFromStr,
Standard_PCharacter& theToStr,
const Standard_Integer theMaxSize);
//! Converts the Unicode string of extended characters to the non-ASCII string according to the format returned by the function GetFormat.
//! @param theFromStr [in] text to convert
//! @param theToStr [out] destination buffer
//! @param theMaxSize [in] destination buffer length
static Standard_Boolean ConvertUnicodeToFormat (const TCollection_ExtendedString& theFromStr,
Standard_PCharacter& theToStr,
const Standard_Integer theMaxSize)
{
return ConvertUnicodeToFormat (Resource_Unicode::GetFormat(), theFromStr, theToStr, theMaxSize);
}
//! Converts the Unicode string of extended
//! characters fromstr to the non-ASCII C string
//! tostr according to the format (either ANSI, EUC,
//! GB or SJIS) returned by the function GetFormat.
//! maxsize limits the size of the string tostr to a
//! maximum number of characters. You need more
//! than twice the length of the string fromstr to
//! complete the conversion.
//! The function returns true if conversion is
//! complete, i.e. the maximum number of characters
//! maxsize is not reached by tostr before the end
//! of conversion of fromstr.
Standard_EXPORT static Standard_Boolean ConvertUnicodeToFormat (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
protected:
private:
};
#endif // _Resource_Unicode_HeaderFile