webengine/wmlengine/src/utils/include/StringUtils.h
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  String related utility methods.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef STRINGUTIL_H
       
    21 #define STRINGUTIL_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32std.h>
       
    25 
       
    26 #include "nwx_defs.h"
       
    27 #include <nw_string_string.h>
       
    28 
       
    29 
       
    30 // CLASS DECLARATION
       
    31 
       
    32 /**
       
    33 * A static class which provides string related utility methods.
       
    34 *
       
    35 * @lib Browser Engine
       
    36 * @since 2.6
       
    37 */
       
    38 class StringUtils
       
    39     {
       
    40     public:  // Constructors and destructor
       
    41 
       
    42         /**
       
    43         * Convert a UCS2 buffer to ascii.
       
    44         *
       
    45         * @since 2.6
       
    46         * @param aUsc2Buf The buffer to convert.
       
    47         * @return The converted buffer or NULL, if failed to allocate a buffer.
       
    48         */
       
    49         static TUint8* CopyUsc2ToAscii(const TUint16* aUsc2Buf);
       
    50 
       
    51         /**
       
    52         * Convert a ascii buffer to unicode.
       
    53         *
       
    54         * @since 2.6
       
    55         * @param aAsciiBuf The buffer to convert.
       
    56         * @return The converted buffer or NULL, if failed to allocate a buffer.
       
    57         */
       
    58         static TUint16* CopyAsciiToUsc2(const TUint8* aAsciiBuf);
       
    59 
       
    60         /**
       
    61         * Copy a UCS2 buffer.
       
    62         *
       
    63         * @since 2.6
       
    64         * @param aUsc2Buf The buffer to copy.
       
    65         * @return The opied buffer or NULL, if failed to allocate a buffer.
       
    66         */
       
    67         static TUint16* CopyUsc2ToUcs2(const TUint16* aUsc2Buf);
       
    68 
       
    69         /**
       
    70         * Copy a ascii buffer.
       
    71         *
       
    72         * @since 2.6
       
    73         * @param aAsciiBuf The buffer to copy.
       
    74         * @return The copied buffer or NULL, if failed to allocate a buffer.
       
    75         */
       
    76         static TUint8* CopyAsciiToAscii(const TUint8* aAsciiBuf);
       
    77 
       
    78         /**
       
    79         * Convert a NW_String_t (holding an usc2 null-terminated string) to a TDes16.
       
    80         *
       
    81         * @since 2.6
       
    82         * @param aUcs2String The string to copy
       
    83         * @return The copied descriptor or NULL, if failed to allocate a buffer.
       
    84         */
       
    85         static TDesC16* CopyStringToDes(const NW_String_t& aUcs2String);
       
    86         
       
    87         /**
       
    88         * Convert a TDesC8* to a TDes16*
       
    89         *
       
    90         * @since 2.6
       
    91         * @param aTDes8String The string to copy
       
    92         * @return The copied descriptor or NULL, if failed to allocate a buffer.
       
    93         */
       
    94         static TDesC16* CopyTDesC8ToTDesC16(const TDesC8& aTDesC8String);
       
    95 
       
    96         /**
       
    97         * Convert a TUint16* to a TDesC16
       
    98         *
       
    99         * @since 2.6
       
   100         * @param aTUint16String The string to copy
       
   101         * @return The copied descriptor or NULL, if failed to allocate a buffer.
       
   102         */
       
   103         static TDesC16* CopyTUint16ToTDesC16(const TUint16* aTUint16String);        
       
   104         
       
   105 
       
   106         /**
       
   107         * Convert a UCS2 buffer to ascii.
       
   108         *
       
   109         * @since 2.6
       
   110         * @param aUsc2Ptr A descriptor to the buffer to convert.
       
   111         * @param retPtr The returned bufer.
       
   112         * @return KErrNone or KErrNoMemory.
       
   113         */
       
   114         static TInt ConvertPtrUsc2ToAscii(const TPtrC& aUsc2Ptr, TUint8** retPtr);
       
   115 
       
   116         /**
       
   117         * Convert a ascii buffer to UCS2.
       
   118         *
       
   119         * @since 2.6
       
   120         * @param aAsciiPtr A descriptor to the buffer to convert.
       
   121         * @param retPtr The returned bufer.
       
   122         * @return KErrNone or KErrNoMemory.
       
   123         */
       
   124         static TInt ConvertPtrAsciiToUcs2(const TPtrC8& aAsciiPtr, TUint16** retPtr);
       
   125 
       
   126         /**
       
   127         * Convert a UCS2 Desc to UCS2.
       
   128         *
       
   129         * @since 2.6
       
   130         * @param aUcs2Ptr A descriptor to the buffer to convert.
       
   131         * @param retPtr The returned bufer.
       
   132         * @return KErrNone or KErrNoMemory.
       
   133         */
       
   134         static TInt ConvertPtrUcs2ToUcs2(const TPtrC& aUcs2Ptr, TUint16** retPtr);
       
   135 
       
   136         /**
       
   137         * Convert a TUint to UCS2.
       
   138         *
       
   139         * @since 2.6
       
   140         * @param aUint The number to convert.
       
   141         * @param retPtr The returned bufer.
       
   142         * @return KErrNone or KErrNoMemory.
       
   143         */
       
   144         static TInt ConvertUintToUcs2(TUint aUint, TUint16** retPtr);
       
   145 
       
   146         /**
       
   147         * Create HBufC.
       
   148         *
       
   149         * @since 2.6
       
   150         * @param aInBuf The buffer to copy.
       
   151         * @return The new HBufC.
       
   152         */
       
   153         static HBufC* CopyHBufCZeroTerminateL(const TDesC& aInBuf);
       
   154 
       
   155         /**
       
   156         * Create HBufC.
       
   157         *
       
   158         * @since 2.6
       
   159         * @param aBuffer The buffer to copy from.
       
   160         * @param aStart The starting point in the buffer to copy.
       
   161         * @param aEnd The ending point in the buffer to copy.
       
   162         * @return The new HBufC.
       
   163         */
       
   164         static HBufC* MakeHBufCLC(const TUint16* aBuffer, TUint aStart, TUint aEnd);
       
   165 
       
   166         /**
       
   167         * Convert To Unicode.
       
   168         *
       
   169         * @since 2.6
       
   170         * @param aBuffer The buffer to copy from.
       
   171         * @param aStart The starting point in the buffer to copy.
       
   172         * @param aEnd The ending point in the buffer to copy.
       
   173         * @return The new HBufC.
       
   174         */
       
   175         static HBufC* ConvertToUnicodeLC(const TUint8* aBuffer, TUint aStart, TUint aEnd);
       
   176 
       
   177         /**
       
   178         * Create HBufC. from the TDesC8
       
   179         *
       
   180         * @since 2.6
       
   181         * @param aInBuf The buffer to copy.
       
   182         * @return The new HBufC.
       
   183         */
       
   184         static HBufC* CopyConvertHBufCZeroTerminateL(const TDesC8& aInBuf);
       
   185         /**
       
   186         * General panic for StringUtils.
       
   187         *
       
   188         * @since 2.6
       
   189         * @param aError The error code from the panicked method.
       
   190         * @return void.
       
   191         */
       
   192         static void Panic(TInt aError);
       
   193         /**
       
   194         * Show the amount of free memory in the system
       
   195         *
       
   196         * @since 2.8
       
   197         * @return void.
       
   198         */
       
   199         static void DisplayAvailableMemory();
       
   200 
       
   201     };
       
   202 
       
   203 
       
   204 #endif      // CSTRINGUTIL_H
       
   205 
       
   206 // End of File