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

0022484: UNICODE characters support

Initial UNICODE (UFT-8) characters support for OCCT file operations

Fix for compilation errors and fix for StepFile (avoid objects in pure c code)

Fixes for set unicode symbols to OCAF and visualization
This commit is contained in:
pdn
2014-10-02 15:39:25 +04:00
committed by bugmaster
parent d3dfddaebc
commit d9ff84e8ea
34 changed files with 617 additions and 510 deletions

View File

@@ -87,8 +87,7 @@ is
---Purpose: Creation by converting an extended string to an ascii string.
-- If replaceNonAscii is non-null charecter, it will be used
-- in place of any non-ascii character found in the source string.
-- Otherwise, raises OutOfRange exception if at least one character
-- in the source string is not in the "Ascii range".
-- Otherwise, creates UTF-8 unicode string.
returns AsciiString from TCollection
raises OutOfRange from Standard;

View File

@@ -231,10 +231,10 @@ TCollection_AsciiString::TCollection_AsciiString(const TCollection_ExtendedStrin
mystring[mylength] = '\0';
}
else {
Standard_SStream amsg;
amsg << "It's not an ascii string : " ;
astring.Print(amsg);
Standard_OutOfRange::Raise(amsg);
// create UTF-8 string
mylength = astring.LengthOfCString();
mystring = Allocate(mylength+1);
astring.ToUTF8CString(mystring);
}
}

View File

@@ -41,7 +41,12 @@ is
Create( astring : CString; isMultiByte : Boolean = Standard_False)
returns ExtendedString from TCollection
raises NullObject;
---Purpose: Creation by converting a CString to an extended string.
---Purpose: Creation by converting a CString to an extended
-- string. If <isMultiByte> is true then the string is
-- treated as having UTF-8 coding. If it is not a UTF-8
-- then <isMultiByte> is ignored and each character is
-- copied to ExtCharacter.
Create( astring : ExtString)
returns ExtendedString from TCollection
@@ -73,7 +78,9 @@ is
Create( astring : AsciiString from TCollection)
returns ExtendedString from TCollection;
---Purpose: Creation by converting a normal Ascii string to an extended string.
---Purpose: Creation by converting an Ascii string to an extended
-- string. The string is treated as having UTF-8 coding.
-- If it is not a UTF-8 then each character is copied to ExtCharacter.
AssignCat (me : out ; other : ExtendedString from TCollection)
is static;

View File

@@ -35,10 +35,11 @@ Standard_EXPORT short NULL_EXTSTRING[1] = {0};
inline Standard_ExtCharacter ConvertToUnicode2B (unsigned char *p)
{
// *p, *(p+1)
// little endian
union {
struct {
unsigned char h;
unsigned char l;
unsigned char h;
} hl;
Standard_ExtCharacter chr;
} EL;
@@ -61,10 +62,11 @@ inline Standard_ExtCharacter ConvertToUnicode2B (unsigned char *p)
inline Standard_ExtCharacter ConvertToUnicode3B (unsigned char *p)
{
// *p, *(p+1), *(p+2) =>0 , 1, 2
// little endian
union {
struct {
unsigned char h;
unsigned char l;
unsigned char h;
} hl;
Standard_ExtCharacter chr;
} EL;
@@ -143,9 +145,11 @@ TCollection_ExtendedString::TCollection_ExtendedString
mystring = Allocate( (mylength+1)*2 );
if(!ConvertToUnicode (astring))
{
#ifdef DEB
cout <<"UTF8 decoding failure..." <<endl;
#endif
mylength = (int)strlen( astring );
mystring = Reallocate(mystring, (mylength+1)*2);
for (int i = 0 ; i < mylength ; i++)
mystring[i] = ToExtCharacter(astring[i]);
mystring[mylength] = '\0';
}
}
}
@@ -268,11 +272,16 @@ TCollection_ExtendedString::TCollection_ExtendedString
TCollection_ExtendedString::TCollection_ExtendedString
(const TCollection_AsciiString& astring)
{
mylength = astring.Length();
mylength = nbSymbols(astring.ToCString());
mystring = Allocate((mylength+1)*2);
Standard_CString aCString = astring.ToCString() ;
for (Standard_Integer i = 0; i <= mylength ; i++)
mystring[i] = ToExtCharacter( aCString[i] );
if(!ConvertToUnicode (astring.ToCString()))
{
mylength = astring.Length();
mystring = Reallocate(mystring, (mylength+1)*2);
Standard_CString aCString = astring.ToCString();
for (Standard_Integer i = 0; i <= mylength ; i++)
mystring[i] = ToExtCharacter( aCString[i] );
}
}
// ----------------------------------------------------------------------------