Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

String.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 2003-2005 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 #ifndef _DWFCORE_STRING_H
00023 #define _DWFCORE_STRING_H
00024 
00029 
00042 
00043 
00044 #include "dwfcore/Core.h"
00045 #include "dwfcore/Exception.h"
00046 #include "dwfcore/Pointer.h"
00047 
00048 
00049 
00050 #ifndef DWFCORE_STRING_STACK_BUFFER_SIZE_IN_BYTES
00055 #define DWFCORE_STRING_STACK_BUFFER_SIZE_IN_BYTES       32
00056 #define _DWFCORE_STRING_STACK_BUFFER_SIZE_IN_WCHARS     (DWFCORE_STRING_STACK_BUFFER_SIZE_IN_BYTES>>(sizeof(wchar_t)>>1))
00057 #define _DWFCORE_STRING_STACK_BUFFER_SIZE_IN_INTS       (DWFCORE_STRING_STACK_BUFFER_SIZE_IN_BYTES>>(sizeof(int)>>1))
00058 #endif
00059 
00060 #ifndef DWFCORE_STRING_PREFER_HEAP_LIMIT_IN_BYTES
00070 #define DWFCORE_STRING_PREFER_HEAP_LIMIT_IN_BYTES       128
00071 #define _DWFCORE_STRING_PREFER_HEAP_LIMIT_IN_WCHARS     (DWFCORE_STRING_PREFER_HEAP_LIMIT_IN_BYTES>>(sizeof(wchar_t)>>1))
00072 #endif
00073 
00074 
00075 
00076 namespace DWFCore
00077 {
00078 
00096 class DWFString : public DWFCoreMemory
00097 {
00098 
00099 public:
00100 
00116     _DWFCORE_API
00117     static size_t EncodeUTF8( const UCS2_char_t*    zUCS2String,
00118                               size_t                nUCS2StringBytes,
00119                               ASCII_char_t*         pUTF8Buffer,
00120                               size_t                nUTF8BufferBytes )
00121         throw( DWFOverflowException );
00122 
00138     _DWFCORE_API
00139     static size_t EncodeUTF8( const UCS4_char_t*    zUCS4String,
00140                               size_t                nUCS4StringBytes,
00141                               ASCII_char_t*         pUTF8Buffer,
00142                               size_t                nUTF8BufferBytes )
00143         throw( DWFOverflowException );
00144 
00145 
00159     _DWFCORE_API
00160     static size_t DecodeUTF8( const ASCII_char_t*   zUTF8String,
00161                               size_t                nUTF8StringBytes,
00162                               UCS2_char_t*          pUCS2Buffer,
00163                               size_t                nUCS2BufferBytes )
00164         throw( DWFOverflowException );
00165 
00179     _DWFCORE_API
00180     static size_t DecodeUTF8( const ASCII_char_t*   zUTF8String,
00181                               size_t                nUTF8StringBytes,
00182                               UCS4_char_t*          pUCS4Buffer,
00183                               size_t                nUCS4BufferBytes )
00184         throw( DWFOverflowException );
00185 
00186 
00201     _DWFCORE_API
00202     static size_t EncodeXML( const ASCII_char_t*    zASCIIString,
00203                              size_t                 nASCIIStringBytes,
00204                              ASCII_char_t*          pXMLBuffer,
00205                              size_t                 nXMLBufferBytes )
00206         throw( DWFException );
00207 
00235     _DWFCORE_API
00236     static size_t EncodeXML( const wchar_t*         zWideString,
00237                              size_t                 nWideStringBytes,
00238                              wchar_t*               pXMLBuffer,
00239                              size_t                 nXMLBufferBytes )
00240         throw( DWFException );
00241 
00256     _DWFCORE_API
00257     static size_t DecodeXML( const ASCII_char_t*   zXMLString,
00258                              size_t                nXMLStringBytes,
00259                              ASCII_char_t*         pASCIIBuffer,
00260                              size_t                nASCIIBufferBytes )
00261         throw( DWFException );
00262 
00287     _DWFCORE_API
00288     static size_t EncodeBase64( const void*         pRawBuffer,
00289                                 size_t              nRawBufferBytes,
00290                                 void*               pOutBuffer,
00291                                 size_t              nOutBufferBytes,
00292                                 bool                bRFC1521Compliant = true )
00293         throw( DWFOverflowException );
00294 
00306     _DWFCORE_API
00307     static double StringToDouble( const char* zString )
00308         throw( DWFException );
00309 
00321     _DWFCORE_API
00322     static double StringToDouble( const wchar_t* zString )
00323         throw( DWFException );
00324 
00336     _DWFCORE_API
00337     static wchar_t* RepairDecimalSeparators( wchar_t* zString )
00338         throw( DWFException );
00339 
00353     _DWFCORE_API
00354     static off_t Find( const wchar_t*   zString,
00355                        const wchar_t    cFind,
00356                        off_t            iOffset = 0,
00357                        bool             bReverse = false )
00358         throw( DWFInvalidArgumentException );
00359 
00373     _DWFCORE_API
00374     static off_t Find( const wchar_t*   zString,
00375                        const wchar_t*   zFind,
00376                        off_t            iOffset = 0,
00377                        bool             bReverse = false )
00378         throw( DWFInvalidArgumentException );
00379 
00388     _DWFCORE_API
00389     static off_t FindFirst( const wchar_t*  zString,
00390                             const wchar_t   cFind )
00391         throw();
00392 
00401     _DWFCORE_API
00402     static off_t FindLast( const wchar_t*   zString,
00403                            const wchar_t    cFind )
00404         throw();
00405 
00406 public:
00407 
00413     _DWFCORE_API 
00414     ~DWFString()
00415         throw();
00416 
00422     _DWFCORE_API 
00423     DWFString()
00424         throw();
00425 
00437     _DWFCORE_API
00438     DWFString( const char*      pBuffer,
00439                size_t           nBufferBytes )
00440         throw( DWFException );
00441 
00452     _DWFCORE_API
00453     DWFString( const char*      zASCIIString )
00454         throw( DWFException );
00455 
00465     _DWFCORE_API
00466     DWFString( const wchar_t*   pBuffer,
00467                size_t           nBufferBytes )
00468         throw( DWFException );
00469 
00478     _DWFCORE_API
00479     DWFString( const wchar_t*   zWideString )
00480         throw( DWFException );
00481 
00488     _DWFCORE_API 
00489     DWFString( const DWFString& rDWFString )
00490         throw( DWFException );
00491 
00498     _DWFCORE_API
00499     DWFString& operator=( const DWFString& rDWFString )
00500         throw( DWFException );
00501 
00508     _DWFCORE_API
00509     void assign( const DWFString& rDWFString )
00510         throw( DWFException );
00511 
00521     _DWFCORE_API
00522     void assign( const char*    pBuffer,
00523                  size_t         nBufferBytes )
00524         throw( DWFException );
00525 
00534     _DWFCORE_API
00535     void assign( const char*    zASCIIString )
00536         throw( DWFException );
00537 
00545     _DWFCORE_API
00546     void assign( const wchar_t* pBuffer,
00547                  size_t         nBufferBytes )
00548         throw( DWFException );
00549 
00556     _DWFCORE_API
00557     void assign( const wchar_t* zWideString )
00558         throw( DWFException );
00559 
00567     _DWFCORE_API
00568     bool operator==( const DWFString& rDWFString ) const
00569         throw();
00570 
00578     _DWFCORE_API
00579     bool operator==( const wchar_t* zWideString ) const
00580         throw();
00581 
00589     _DWFCORE_API
00590     bool operator!=( const DWFString& rDWFString ) const
00591         throw();
00592 
00600     _DWFCORE_API
00601     bool operator!=( const wchar_t* zWideString ) const
00602         throw();
00603 
00611     _DWFCORE_API
00612     bool operator<( const DWFString& rDWFString ) const
00613         throw();
00614 
00622     _DWFCORE_API
00623     bool operator<( const wchar_t* zWideString ) const
00624         throw();
00625 
00633     _DWFCORE_API
00634     bool operator>( const DWFString& rDWFString ) const
00635         throw();
00636 
00644     _DWFCORE_API
00645     bool operator>( const wchar_t* zWideString ) const
00646         throw();
00647 
00653     _DWFCORE_API
00654     void destroy()
00655         throw( DWFException );
00656 
00663     _DWFCORE_API
00664     void append( const DWFString& rDWFString )
00665         throw( DWFException );
00666 
00676     _DWFCORE_API
00677     void append( const char*    pBuffer,
00678                  size_t         nBufferBytes )
00679         throw( DWFException );
00680 
00689     _DWFCORE_API
00690     void append( const char*    zASCIIString )
00691         throw( DWFException );
00692 
00700     _DWFCORE_API
00701     void append( const wchar_t* pBuffer,
00702                  size_t         nBufferBytes )
00703         throw( DWFException );
00704 
00711     _DWFCORE_API
00712     void append( const wchar_t* zWideString )
00713         throw( DWFException );
00714 
00720     _DWFCORE_API
00721     size_t bytes() const
00722         throw();
00723 
00729     _DWFCORE_API
00730     size_t chars() const
00731         throw();
00732 
00743     _DWFCORE_API
00744     size_t getUTF8( char*   pBuffer,
00745                     size_t  nBufferBytes ) const
00746         throw( DWFException );
00747 
00758     _DWFCORE_API
00759     size_t getUTF8( char** ppBuffer ) const
00760         throw( DWFException );
00761 
00769     _DWFCORE_API
00770     operator const wchar_t*() const
00771         throw();
00772 
00785     _DWFCORE_API
00786     off_t find( const wchar_t cFind,
00787                 off_t         iOffset = 0,
00788                 bool          bReverse = false ) const
00789         throw( DWFInvalidArgumentException );
00790 
00803     _DWFCORE_API
00804     off_t find( const wchar_t* zFind,
00805                 off_t          iOffset = 0,
00806                 bool           bReverse = false ) const
00807         throw( DWFInvalidArgumentException );
00808 
00816     _DWFCORE_API
00817     off_t findFirst( const wchar_t cFind ) const
00818         throw();
00819 
00827     _DWFCORE_API
00828     off_t findLast( const wchar_t cFind ) const
00829         throw();
00830 
00840     _DWFCORE_API
00841     DWFString substring( size_t iPos,
00842                          size_t iLen = -1 )
00843          throw( DWFException );
00844 
00845 private:
00846 
00847     void _store( const void*    pBuffer,
00848                  size_t         nBufferBytes,
00849                  bool           bDecodeUTF8 = false )
00850         throw( DWFException );
00851 
00852     void _append( const void*   pBuffer,
00853                   size_t        nBufferBytes,
00854                   bool          bDecodeUTF8 = false )
00855         throw( DWFException );
00856 
00857 private:
00858 
00859 #ifndef DWFCORE_STRING_DISABLE_STACK_BUFFER
00860 
00861     wchar_t     _zStackBuffer[_DWFCORE_STRING_STACK_BUFFER_SIZE_IN_WCHARS];
00862 
00863 #endif
00864 
00865     wchar_t*    _pHeapBuffer;
00866     size_t      _nBufferChars;
00867     size_t      _nDataChars;
00868     bool        _bDataInHeap;
00869 };
00870 
00871 //
00872 //
00873 //
00874 
00875 _DWFCORE_API
00876 inline
00877 size_t
00878 DWFString::bytes()
00879 const
00880 throw()
00881 {
00882     return (_nDataChars * sizeof(wchar_t));
00883 }
00884 
00885 _DWFCORE_API
00886 inline
00887 size_t
00888 DWFString::chars()
00889 const
00890 throw()
00891 {
00892     return _nDataChars;
00893 }
00894 
00895 _DWFCORE_API
00896 inline
00897 DWFString::operator const wchar_t*()
00898 const
00899 throw()
00900 {
00901 #ifdef  DWFCORE_STRING_DISABLE_STACK_BUFFER
00902 
00903     return _pHeapBuffer;
00904 
00905 #endif
00906 
00907         //
00908         // return heap if it exists
00909         //
00910     if (_bDataInHeap)
00911     {
00912         return _pHeapBuffer;
00913     }
00914 
00915         //
00916         // with empty heap, return stack if any data exists
00917         //
00918     if (_nDataChars > 0)
00919     {
00920         return _zStackBuffer;
00921     }
00922 
00923         //
00924         // no data
00925         //
00926     return NULL;
00927 }
00928 
00929 
00930 }
00931 
00932 #endif

Generated on Tue May 17 12:05:10 2005 for Autodesk DWF Core Library by  doxygen 1.4.1