0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Resource / Resource_Unicode.hxx
1 // Created on: 1996-09-26
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _Resource_Unicode_HeaderFile
18 #define _Resource_Unicode_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_CString.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <Standard_PCharacter.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Resource_FormatType.hxx>
29 class TCollection_ExtendedString;
30
31
32 //! This class provides functions used to convert a non-ASCII C string
33 //! given in ANSI, EUC, GB or SJIS format, to a
34 //! Unicode string of extended characters, and vice versa.
35 class Resource_Unicode 
36 {
37 public:
38
39   DEFINE_STANDARD_ALLOC
40
41   
42   //! Converts non-ASCII CString <fromstr> in SJIS format
43   //! to Unicode ExtendedString <tostr>.
44   Standard_EXPORT static void ConvertSJISToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
45   
46   //! Converts non-ASCII CString <fromstr> in EUC format
47   //! to Unicode ExtendedString <tostr>.
48   Standard_EXPORT static void ConvertEUCToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
49   
50   //! Converts non-ASCII CString <fromstr> in GB format
51   //! to Unicode ExtendedString <tostr>.
52   Standard_EXPORT static void ConvertGBToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
53   
54   //! Converts non-ASCII CString <fromstr> in GBK format
55   //! to Unicode ExtendedString <tostr>.
56   Standard_EXPORT static Standard_Boolean ConvertGBKToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
57   
58   //! Converts non-ASCII CString <fromstr> in Big5 format
59   //! to Unicode ExtendedString <tostr>.
60   Standard_EXPORT static Standard_Boolean ConvertBig5ToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
61   
62   //! Converts Unicode ExtendedString <fromstr> to non-ASCII
63   //! CString <tostr> in SJIS format, limited to <maxsize>
64   //! characters. To translate the whole <fromstr>, use more
65   //! than twice the length of <fromstr>. Returns true if
66   //! <maxsize> has not been reached before end of conversion.
67   Standard_EXPORT static Standard_Boolean ConvertUnicodeToSJIS (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
68   
69   //! Converts Unicode ExtendedString <fromstr> to non-ASCII
70   //! CString <tostr> in EUC format, limited to <maxsize>
71   //! characters. To translate the whole <fromstr>, use more
72   //! than twice the length of <fromstr>. Returns true if
73   //! <maxsize> has not been reached before end of conversion.
74   Standard_EXPORT static Standard_Boolean ConvertUnicodeToEUC (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
75   
76   //! Converts Unicode ExtendedString <fromstr> to non-ASCII
77   //! CString <tostr> in GB format, limited to <maxsize>
78   //! characters. To translate the whole <fromstr>, use more
79   //! than twice the length of <fromstr>. Returns true if
80   //! <maxsize> has not been reached before end of conversion.
81   Standard_EXPORT static Standard_Boolean ConvertUnicodeToGB (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
82   
83   //! Converts Unicode ExtendedString <fromstr> to non-ASCII
84   //! CString <tostr> in ANSI format, limited to <maxsize>
85   //! characters. To translate the whole <fromstr>, use more
86   //! than twice the length of <fromstr>.  Returns true if
87   //! <maxsize> has not been reached before end of conversion.
88   Standard_EXPORT static Standard_Boolean ConvertUnicodeToANSI (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
89   
90   //! Defines the current conversion format as typecode.
91   //! This conversion format will then be used by the
92   //! functions ConvertFormatToUnicode and
93   //! ConvertUnicodeToFormat to convert the strings.
94   Standard_EXPORT static void SetFormat (const Resource_FormatType typecode);
95   
96   //! Returns the current conversion format (either
97   //! ANSI, EUC, GB or SJIS).
98   //! The current converting format must be defined in
99   //! advance with the SetFormat function.
100   Standard_EXPORT static Resource_FormatType GetFormat();
101   
102   //! Reads converting format from resource "FormatType"
103   //! in Resource Manager "CharSet"
104   Standard_EXPORT static void ReadFormat();
105   
106   //! Converts the non-ASCII C string (as specified by GetFormat()) to the Unicode string of extended characters.
107   static void ConvertFormatToUnicode (const Standard_CString theFromStr,
108                                       TCollection_ExtendedString& theToStr)
109   {
110     return ConvertFormatToUnicode (Resource_Unicode::GetFormat(), theFromStr, theToStr);
111   }
112
113   //! Converts the non-ASCII C string in specified format to the Unicode string of extended characters.
114   //! @param theFormat  [in] source encoding
115   //! @param theFromStr [in] text to convert
116   //! @param theToStr  [out] destination string
117   Standard_EXPORT static void ConvertFormatToUnicode (const Resource_FormatType theFormat,
118                                                       const Standard_CString theFromStr,
119                                                       TCollection_ExtendedString& theToStr);
120
121   //! Converts the Unicode string of extended characters to the non-ASCII string according to specified format.
122   //! You need more than twice the length of the source string to complete the conversion.
123   //! The function returns true if conversion is complete, i.e. the maximum number of characters is not reached before the end of conversion.
124   //! @param theFormat  [in] destination encoding
125   //! @param theFromStr [in] text to convert
126   //! @param theToStr  [out] destination buffer
127   //! @param theMaxSize [in] destination buffer length
128   Standard_EXPORT static Standard_Boolean ConvertUnicodeToFormat (const Resource_FormatType theFormat,
129                                                                   const TCollection_ExtendedString& theFromStr,
130                                                                   Standard_PCharacter& theToStr,
131                                                                   const Standard_Integer theMaxSize);
132
133   //! Converts the Unicode string of extended characters to the non-ASCII string according to the format returned by the function GetFormat.
134   //! @param theFromStr [in] text to convert
135   //! @param theToStr  [out] destination buffer
136   //! @param theMaxSize [in] destination buffer length
137   static Standard_Boolean ConvertUnicodeToFormat (const TCollection_ExtendedString& theFromStr,
138                                                   Standard_PCharacter& theToStr,
139                                                   const Standard_Integer theMaxSize)
140   {
141     return ConvertUnicodeToFormat (Resource_Unicode::GetFormat(), theFromStr, theToStr, theMaxSize);
142   }
143   
144 };
145
146 #endif // _Resource_Unicode_HeaderFile