|
1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __TXTWRITER_H__ |
|
20 #define __TXTWRITER_H__ |
|
21 |
|
22 #include <e32std.h> |
|
23 |
|
24 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
26 // MTextWriter interface |
|
27 |
|
28 /** |
|
29 MTextWriter class is an interface, implemented by TParagraphTextWriter and |
|
30 TLineTextWriter classes. It offers two functions: |
|
31 1) void WriteL(TText aChar) - to output a single character. |
|
32 2) void FlushL() - if the implementations have stored some of the incomming characters |
|
33 for further processing, they will be immediately flushed to the output. |
|
34 They are not supposed to be called directly. MTextWriter class, together with TSLBTransaltor, |
|
35 MOutputChar, TParagraphTextWriter and TLineTextWriter classes builds a framework, used for |
|
36 correct filtering of the 0x0D and 0x0A characters and translating them to line breaks or spaces, |
|
37 depending of the text file organisation. |
|
38 @internalComponent |
|
39 */ |
|
40 class MTextWriter |
|
41 { |
|
42 public: |
|
43 virtual void WriteL(TText aChar) = 0; |
|
44 virtual void FlushL() |
|
45 { |
|
46 } |
|
47 }; |
|
48 |
|
49 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
51 // MOutputChar interface |
|
52 |
|
53 /** |
|
54 MOutputChar interface offers "void OutputCharL(TText aChar)" method, which gets as an input |
|
55 character, which may be a line break or something else, but not 0x0D or 0x0A characters, which |
|
56 were filtered earlier. |
|
57 @internalComponent |
|
58 */ |
|
59 class MOutputChar |
|
60 { |
|
61 public: |
|
62 virtual void OutputCharL(TText aChar) = 0; |
|
63 }; |
|
64 |
|
65 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
67 // TSLBTransaltor class |
|
68 |
|
69 /** |
|
70 TSLBTransaltor class offers functionality for processing a stream of characters, filtering |
|
71 0x0D and 0x0A characters or (0x0D 0x0A) combination, and transating them to single line breaks. |
|
72 It sends translated characters for a further processing using MTextWriter::WriteL() call. |
|
73 The translation rules are: |
|
74 - 0x0D - line break; |
|
75 - 0x0A - line break; |
|
76 - 0x0D 0x0A - line break; |
|
77 @internalComponent |
|
78 */ |
|
79 class TSLBTransaltor |
|
80 { |
|
81 public: |
|
82 inline TSLBTransaltor(MTextWriter& aTextWriter); |
|
83 void ProcessL(TText aChar); |
|
84 void FlushL(); |
|
85 private: |
|
86 MTextWriter& iTextWriter; |
|
87 TText iPrevChar; |
|
88 }; |
|
89 |
|
90 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 // TParagraphTextWriter class |
|
93 |
|
94 /** |
|
95 TParagraphTextWriter class is a concrete implementation of MTextWriter interface. |
|
96 It is used to translate line breaks in the input sequence to paragraph delimiters. |
|
97 Every line break from the input is replaced with paragraph delimiter in the output. |
|
98 MOutputChar interface is used for the output. |
|
99 @internalComponent |
|
100 */ |
|
101 NONSHARABLE_CLASS(TParagraphTextWriter) : public MTextWriter |
|
102 { |
|
103 public: |
|
104 inline TParagraphTextWriter(MOutputChar& aOutputChar); |
|
105 virtual void WriteL(TText aChar); |
|
106 private: |
|
107 MOutputChar& iOutputChar; |
|
108 }; |
|
109 |
|
110 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
111 ////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 // TLineTextWriter class |
|
113 |
|
114 /** |
|
115 TLineTextWriter class is a concrete implementation of MTextWriter interface. |
|
116 It is used to translate line breaks in the input sequence to paragraph delimiters or spaces. |
|
117 The translation rules are: |
|
118 - single line break - space; |
|
119 - double line break - paragraph delimiter; |
|
120 MOutputChar interface is used for the output. |
|
121 @internalComponent |
|
122 */ |
|
123 NONSHARABLE_CLASS(TLineTextWriter) : public MTextWriter |
|
124 { |
|
125 public: |
|
126 inline TLineTextWriter(MOutputChar& aOutputChar); |
|
127 virtual void WriteL(TText aChar); |
|
128 virtual void FlushL(); |
|
129 private: |
|
130 MOutputChar& iOutputChar; |
|
131 TText iPrevChar; |
|
132 }; |
|
133 |
|
134 |
|
135 #include "TxtWriter.inl" |
|
136 |
|
137 #endif //__TXTWRITER_H__ |