Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:42

0001 // Created on: 1996-09-26
0002 // Created by: Arnaud BOUZY
0003 // Copyright (c) 1996-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Resource_Unicode_HeaderFile
0018 #define _Resource_Unicode_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Standard_CString.hxx>
0025 #include <Standard_Boolean.hxx>
0026 #include <Standard_PCharacter.hxx>
0027 #include <Standard_Integer.hxx>
0028 #include <Resource_FormatType.hxx>
0029 class TCollection_ExtendedString;
0030 
0031 
0032 //! This class provides functions used to convert a non-ASCII C string
0033 //! given in ANSI, EUC, GB or SJIS format, to a
0034 //! Unicode string of extended characters, and vice versa.
0035 class Resource_Unicode 
0036 {
0037 public:
0038 
0039   DEFINE_STANDARD_ALLOC
0040 
0041   
0042   //! Converts non-ASCII CString <fromstr> in SJIS format
0043   //! to Unicode ExtendedString <tostr>.
0044   Standard_EXPORT static void ConvertSJISToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
0045   
0046   //! Converts non-ASCII CString <fromstr> in EUC format
0047   //! to Unicode ExtendedString <tostr>.
0048   Standard_EXPORT static void ConvertEUCToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
0049   
0050   //! Converts non-ASCII CString <fromstr> in GB format
0051   //! to Unicode ExtendedString <tostr>.
0052   Standard_EXPORT static void ConvertGBToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
0053   
0054   //! Converts non-ASCII CString <fromstr> in GBK format
0055   //! to Unicode ExtendedString <tostr>.
0056   Standard_EXPORT static Standard_Boolean ConvertGBKToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
0057   
0058   //! Converts non-ASCII CString <fromstr> in Big5 format
0059   //! to Unicode ExtendedString <tostr>.
0060   Standard_EXPORT static Standard_Boolean ConvertBig5ToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
0061   
0062   //! Converts Unicode ExtendedString <fromstr> to non-ASCII
0063   //! CString <tostr> in SJIS format, limited to <maxsize>
0064   //! characters. To translate the whole <fromstr>, use more
0065   //! than twice the length of <fromstr>. Returns true if
0066   //! <maxsize> has not been reached before end of conversion.
0067   Standard_EXPORT static Standard_Boolean ConvertUnicodeToSJIS (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
0068   
0069   //! Converts Unicode ExtendedString <fromstr> to non-ASCII
0070   //! CString <tostr> in EUC format, limited to <maxsize>
0071   //! characters. To translate the whole <fromstr>, use more
0072   //! than twice the length of <fromstr>. Returns true if
0073   //! <maxsize> has not been reached before end of conversion.
0074   Standard_EXPORT static Standard_Boolean ConvertUnicodeToEUC (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
0075   
0076   //! Converts Unicode ExtendedString <fromstr> to non-ASCII
0077   //! CString <tostr> in GB format, limited to <maxsize>
0078   //! characters. To translate the whole <fromstr>, use more
0079   //! than twice the length of <fromstr>. Returns true if
0080   //! <maxsize> has not been reached before end of conversion.
0081   Standard_EXPORT static Standard_Boolean ConvertUnicodeToGB (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
0082   
0083   //! Converts Unicode ExtendedString <fromstr> to non-ASCII
0084   //! CString <tostr> in ANSI format, limited to <maxsize>
0085   //! characters. To translate the whole <fromstr>, use more
0086   //! than twice the length of <fromstr>.  Returns true if
0087   //! <maxsize> has not been reached before end of conversion.
0088   Standard_EXPORT static Standard_Boolean ConvertUnicodeToANSI (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
0089   
0090   //! Defines the current conversion format as typecode.
0091   //! This conversion format will then be used by the
0092   //! functions ConvertFormatToUnicode and
0093   //! ConvertUnicodeToFormat to convert the strings.
0094   Standard_EXPORT static void SetFormat (const Resource_FormatType typecode);
0095   
0096   //! Returns the current conversion format (either
0097   //! ANSI, EUC, GB or SJIS).
0098   //! The current converting format must be defined in
0099   //! advance with the SetFormat function.
0100   Standard_EXPORT static Resource_FormatType GetFormat();
0101   
0102   //! Reads converting format from resource "FormatType"
0103   //! in Resource Manager "CharSet"
0104   Standard_EXPORT static void ReadFormat();
0105   
0106   //! Converts the non-ASCII C string (as specified by GetFormat()) to the Unicode string of extended characters.
0107   static void ConvertFormatToUnicode (const Standard_CString theFromStr,
0108                                       TCollection_ExtendedString& theToStr)
0109   {
0110     return ConvertFormatToUnicode (Resource_Unicode::GetFormat(), theFromStr, theToStr);
0111   }
0112 
0113   //! Converts the non-ASCII C string in specified format to the Unicode string of extended characters.
0114   //! @param theFormat  [in] source encoding
0115   //! @param theFromStr [in] text to convert
0116   //! @param theToStr  [out] destination string
0117   Standard_EXPORT static void ConvertFormatToUnicode (const Resource_FormatType theFormat,
0118                                                       const Standard_CString theFromStr,
0119                                                       TCollection_ExtendedString& theToStr);
0120 
0121   //! Converts the Unicode string of extended characters to the non-ASCII string according to specified format.
0122   //! You need more than twice the length of the source string to complete the conversion.
0123   //! The function returns true if conversion is complete, i.e. the maximum number of characters is not reached before the end of conversion.
0124   //! @param theFormat  [in] destination encoding
0125   //! @param theFromStr [in] text to convert
0126   //! @param theToStr  [out] destination buffer
0127   //! @param theMaxSize [in] destination buffer length
0128   Standard_EXPORT static Standard_Boolean ConvertUnicodeToFormat (const Resource_FormatType theFormat,
0129                                                                   const TCollection_ExtendedString& theFromStr,
0130                                                                   Standard_PCharacter& theToStr,
0131                                                                   const Standard_Integer theMaxSize);
0132 
0133   //! Converts the Unicode string of extended characters to the non-ASCII string according to the format returned by the function GetFormat.
0134   //! @param theFromStr [in] text to convert
0135   //! @param theToStr  [out] destination buffer
0136   //! @param theMaxSize [in] destination buffer length
0137   static Standard_Boolean ConvertUnicodeToFormat (const TCollection_ExtendedString& theFromStr,
0138                                                   Standard_PCharacter& theToStr,
0139                                                   const Standard_Integer theMaxSize)
0140   {
0141     return ConvertUnicodeToFormat (Resource_Unicode::GetFormat(), theFromStr, theToStr, theMaxSize);
0142   }
0143   
0144 };
0145 
0146 #endif // _Resource_Unicode_HeaderFile