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