sl@0: /* sl@0: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Header for the classes that import and export plain text into and out of ETEXT. sl@0: * sl@0: */ sl@0: sl@0: sl@0: #ifndef __TXTPLAIN__ sl@0: #define __TXTPLAIN__ 1 sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "TxtWriter.h" sl@0: sl@0: class CCnvCharacterSetConverter; sl@0: class TPlainTextIOState; sl@0: sl@0: NONSHARABLE_CLASS(CPlainTextConverter) : public CBase sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: static CPlainTextConverter* NewLC(); sl@0: ~CPlainTextConverter(); sl@0: void PrepareToConvertL(TPlainTextIOState& aState,const TDesC8* aSample); sl@0: sl@0: enum sl@0: { sl@0: EConversionBufferSize = 1024 sl@0: }; sl@0: sl@0: CCnvCharacterSetConverter* iConverter; // use this converter to translate input or output sl@0: TUint8* iConversionBuffer; // the buffer used by iConverter for non-Unicode text sl@0: TInt iConversionBufferLength; // current number of characters in the conversion buffer sl@0: }; sl@0: sl@0: class TPlainTextIOState sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: TPlainTextIOState(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult, sl@0: RWriteStream& aOutput,RReadStream& aInput); sl@0: TBool Finished() const sl@0: { return iResult.iOutputChars >= iParam.iMaxOutputChars || iResult.iInputChars >= iParam.iMaxInputChars; } sl@0: TText ReadRawCharL(); sl@0: void WriteRawCharL(TText aChar); sl@0: sl@0: const CPlainText::TImportExportParam& iParam; sl@0: CPlainText::TImportExportResult& iResult; sl@0: RWriteStream& iOutput; sl@0: RReadStream& iInput; sl@0: CPlainTextConverter* iConverter;// if non-null, use CHARCONV, via this object, to convert a sl@0: // foreign encoding to or from Unicode sl@0: TBool iSwapInput; // input needs to be byte-swapped sl@0: TBool iCheckByteOrder; // flip iSwapInput if the next input character is 0xFFFE (byte-swapped byte order mark) sl@0: }; sl@0: sl@0: class TPlainTextWriter: public TPlainTextIOState sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: static void TranslateL(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult, sl@0: RWriteStream& aOutput,RReadStream& aInput); sl@0: sl@0: private: sl@0: TPlainTextWriter(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult, sl@0: RWriteStream& aOutput,RReadStream& aInput); sl@0: void TranslateHelperL(); sl@0: sl@0: enum sl@0: { sl@0: EDefaultLineBufferSize = CPlainTextConverter::EConversionBufferSize * 2 sl@0: }; sl@0: sl@0: void TranslateToEofL(); sl@0: void FlushL(); sl@0: void WriteCharL(TText aChar); sl@0: void WriteNewLineL(); sl@0: void WriteAndConvertL(const TText* aText,TInt aLength); sl@0: sl@0: RBufReadStream iBufReadStream; // a stream over the input buffer sl@0: TInt iMaxLineLength; // wrap lines automatically if they exceed this length sl@0: TInt iLineLength; // length of the current line sl@0: TText* iLineBuffer; // if non-null, this buffer contains the current line, or Unicode text sl@0: // to be converted to a foreign encoding sl@0: TInt iMaxLineBufferLength; // maximum number of characters in iLineBuffer sl@0: }; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(TPlainTextReader) : public TPlainTextIOState, public MOutputChar sl@0: { sl@0: public: sl@0: static void TranslateL(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult, sl@0: RWriteStream& aOutput,RReadStream& aInput); sl@0: sl@0: private: sl@0: TPlainTextReader(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult, sl@0: RWriteStream& aOutput,RReadStream& aInput); sl@0: void TranslateHelperL(TSLBTransaltor& aSLBTranslator); sl@0: sl@0: enum sl@0: { sl@0: EInputBufferSize = CPlainTextConverter::EConversionBufferSize * 2 sl@0: }; sl@0: sl@0: void TranslateToEofL(TSLBTransaltor& aSLBTranslator); sl@0: TText ReadAndConvertL(); sl@0: virtual void OutputCharL(TText aChar); sl@0: sl@0: TText* iInputBuffer; // if non-null, this buffer contains Unicode text sl@0: // converted from a foreign encoding sl@0: TInt iInputLength; // number of characters currently stored in iInputBuffer sl@0: TInt iInputPos; // current position in iInputBuffer; sl@0: TInt iConversionState; // state used by iConverter when converting to Unicode sl@0: }; sl@0: sl@0: #endif // __TXTPLAIN__