notepad/notepad1/inc/NpdUtil.h
branchRCL_3
changeset 30 bd7edf625bdd
parent 0 f979ecb2b13e
equal deleted inserted replaced
29:12af337248b1 30:bd7edf625bdd
       
     1 /*
       
     2 * Copyright (c) 2002 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 "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:  Declaration of Notepad Libaray utilitiy functions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef NPDUTIL_H
       
    20 #define NPDUTIL_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 
       
    25 // FORWARD DECLARATIONS
       
    26 class CCoeEnv;
       
    27 class CPlainText;
       
    28 
       
    29 /**
       
    30 * Utitilties used in Notepad Library.
       
    31 * NotepadUtil has some static library functions of Notepad Library.
       
    32 *  
       
    33 */
       
    34 class NotepadUtil
       
    35     {
       
    36     public:
       
    37 
       
    38         /**
       
    39         * Leave with KErrDiskFull if writing aBytesToWrite makes the 
       
    40         * free disk space under the critical level.
       
    41         *
       
    42         * @param aCoeEnv environment (for resource reading and RFs).
       
    43         * @param aBtyesToWrite expected data size to write
       
    44         */
       
    45         static void LeaveIfCriticalLevelL(
       
    46             CCoeEnv& aCoeEnv,
       
    47             TInt aBytesToWrite = 0 );
       
    48 
       
    49         /**
       
    50         * Show the database corrupted information note defined in 
       
    51         * "Low Memory and Error Handling".
       
    52         */
       
    53         static void ShowCorruptedNoteL(CCoeEnv& aCoeEnv);
       
    54 
       
    55         /**
       
    56         * Check whether a text is empty.
       
    57         *
       
    58         * @param aText text to be tested.
       
    59         * @return ETrue if aText is judged as empty
       
    60         */
       
    61         static TBool IsEmpty(const TDesC& aText);
       
    62 
       
    63         /**
       
    64         * Append aText to aBuf.
       
    65         *
       
    66         * Perl like semantics:
       
    67         *     $x = aText;
       
    68         *     if ( aShortenConsecutiveSpaces ) { $x =~ s/\s+/ /g; }
       
    69         *     else { $x =~ s/\s/ /g; }
       
    70         *     aBuf .= $x;
       
    71         *
       
    72         * If aText is longer than rest length of aBuf, some characters in 
       
    73         * aText will be discarded.
       
    74         *
       
    75         * @param aBuf buffer.
       
    76         * @param text to be appended.
       
    77         * @param aRemoveHeadingSpaces Doesn't append heading spaces if ETrue.
       
    78         */
       
    79         static void AppendLabel(
       
    80             TDes& aBuf, 
       
    81             const TDesC& aText, 
       
    82             const TBool aRemoveHeadingSpaces );
       
    83 
       
    84         /**
       
    85         * Load contents of a text file.
       
    86         * Character encoding of the file is detected automatically.
       
    87         *
       
    88         * @param aCoeEnv environment (for resource reading and RFs).
       
    89         * @param aFileName file name to be loaded.
       
    90         * @param aGuessEncoding guess encoding if ETrue (ignore aEncoding).
       
    91         * @param aEncoding encoding of the File
       
    92         * @param aText CPlainText object.
       
    93         */
       
    94         static void LoadFileL(
       
    95             CCoeEnv& aCoeEnv,
       
    96             const TDesC& aFileName, 
       
    97             TBool aGuessEncoding,
       
    98             TUint aEncoding, 
       
    99             CPlainText& aText);
       
   100  
       
   101         /**
       
   102         * Load contents of a text file.
       
   103         * Character encoding of the file is detected automatically.
       
   104         *
       
   105         * @param aCoeEnv environment (for resource reading and RFs).
       
   106         * @param aFile file handle.
       
   107         * @param aGuessEncoding guess encoding if ETrue (ignore aEncoding).
       
   108         * @param aEncoding encoding of the File
       
   109         * @param aText CPlainText object.
       
   110         */
       
   111         static TBool LoadFileL(
       
   112             CCoeEnv& aCoeEnv,
       
   113             RFile& aFile, 
       
   114             TBool aGuessEncoding,
       
   115             TUint aEncoding, 
       
   116             CPlainText& aText);
       
   117 
       
   118         /**
       
   119         * Checks wether the descriptor contains SHIFT-JIS encoded text
       
   120         * 
       
   121         * @param aText Text to be analyzed
       
   122         * @return ETrue if the text is encoded with SHIFT-JIS
       
   123         */
       
   124         static bool IsShiftJisText(TDesC8& aText);
       
   125 
       
   126         /**
       
   127         * Checks wether the descriptor contains big endian unicode text
       
   128         * 
       
   129         * @param aText Text to be analyzed
       
   130         * @return ETrue if the text is big endian unicode text
       
   131         */
       
   132         static bool IsBigEndianUnicodeText(TDesC8& aText);
       
   133 
       
   134         /**
       
   135         * Checks wether the descriptor contains little endian unicode text
       
   136         * 
       
   137         * @param aText Text to be analyzed
       
   138         * @return ETrue if the text is little endian unicode text
       
   139         */
       
   140         static bool IsLittleEndianUnicodeText(TDesC8& aText);
       
   141 
       
   142         /**
       
   143         * Checks wether the descriptor contains UTF8 text
       
   144         * 
       
   145         * @param aText Text to be analyzed
       
   146         * @return ETrue if the text is UTF8 text
       
   147         */
       
   148         static bool IsUTF8Text(TDesC8& aText);
       
   149 
       
   150         /**
       
   151         */
       
   152         static TUint GuessEncodingFromLanguage();
       
   153 
       
   154         /**
       
   155         */
       
   156         static TUint GetISO8859Variant(TLanguage aLanguage);
       
   157 
       
   158     private:
       
   159         /**
       
   160         * Checks wether the given two TUints contain SHIFT-JIS encoded
       
   161         * character.
       
   162         * 
       
   163         * @param aFirst First byte of the encoded character
       
   164         * @param aSecond Second byte of the encoded character
       
   165         * @return ETrue if the character is encoded with SHIFT-JIS
       
   166         */
       
   167         static bool IsShiftJisChar(const TUint& aFirst, const TUint& aSecond);
       
   168     };
       
   169 
       
   170 #endif
       
   171 // End of File