|
1 /* |
|
2 * Copyright (c) 2002-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: This file implements class CESMRICalContentLineWriter. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Class include. |
|
20 #include "emailtrace.h" |
|
21 #include "cesmricalcontentlinewriter.h" // CESMRICalContentLineWriter |
|
22 |
|
23 //debug |
|
24 |
|
25 // System includes. |
|
26 #include <s32strm.h> // RWriteStream |
|
27 #include <utf.h> // CnvUtfConverter |
|
28 |
|
29 namespace{ |
|
30 // Constants. |
|
31 const TInt KICalMaxLineLength = 75; // The length of a line allowed by RFC 2445. |
|
32 const TInt KICalMaxFoldedLineLength = KICalMaxLineLength - 1; // Allows for the extra space at the start of the line. |
|
33 |
|
34 // Line folding literals. |
|
35 _LIT8(KICalCRLF,"\r\n"); |
|
36 _LIT8(KICalFoldLine,"\r\n "); |
|
37 }//namespace |
|
38 |
|
39 // ======== MEMBER FUNCTIONS ======== |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CESMRICalContentLineWriter::NewL |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CESMRICalContentLineWriter* CESMRICalContentLineWriter::NewL(RWriteStream& aStream) |
|
46 { |
|
47 FUNC_LOG; |
|
48 |
|
49 CESMRICalContentLineWriter* self = CESMRICalContentLineWriter::NewLC(aStream); |
|
50 CleanupStack::Pop(self); |
|
51 |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CESMRICalContentLineWriter::NewLC |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CESMRICalContentLineWriter* CESMRICalContentLineWriter::NewLC(RWriteStream& aStream) |
|
60 { |
|
61 FUNC_LOG; |
|
62 |
|
63 CESMRICalContentLineWriter* self = new (ELeave) CESMRICalContentLineWriter(aStream); |
|
64 CleanupStack::PushL(self); |
|
65 self->ConstructL(); |
|
66 |
|
67 return self; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CESMRICalContentLineWriter::~CESMRICalContentLineWriter |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CESMRICalContentLineWriter::~CESMRICalContentLineWriter() |
|
75 { |
|
76 FUNC_LOG; |
|
77 |
|
78 delete iCurrentLine; |
|
79 |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CESMRICalContentLineWriter::WriteContentLineL |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CESMRICalContentLineWriter::WriteContentLineL() |
|
87 { |
|
88 FUNC_LOG; |
|
89 |
|
90 // Convert to UTF-8 for writing |
|
91 HBufC8* tmpLine = CnvUtfConverter::ConvertFromUnicodeToUtf8L(*iCurrentLine); |
|
92 CleanupStack::PushL(tmpLine); |
|
93 |
|
94 TInt pos(0); |
|
95 TInt remaining(tmpLine->Length()); |
|
96 |
|
97 // Fold the line if longer than 75 octets |
|
98 TInt lineLength(KICalMaxLineLength); |
|
99 |
|
100 while (remaining > lineLength) |
|
101 { |
|
102 iWriteStream.WriteL(tmpLine->Mid(pos), lineLength); |
|
103 iWriteStream.WriteL(KICalFoldLine); |
|
104 pos += lineLength; |
|
105 remaining -= lineLength; |
|
106 lineLength = KICalMaxFoldedLineLength; |
|
107 } |
|
108 |
|
109 // Complete the line |
|
110 iWriteStream.WriteL(tmpLine->Mid(pos)); |
|
111 iWriteStream.WriteL(KICalCRLF); |
|
112 |
|
113 CleanupStack::PopAndDestroy(tmpLine); |
|
114 |
|
115 iCurrentLine->Des().SetLength(0); |
|
116 |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // CESMRICalContentLineWriter::AppendL |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 void CESMRICalContentLineWriter::AppendL(const TDesC& aLine) |
|
124 { |
|
125 FUNC_LOG; |
|
126 |
|
127 if (!iCurrentLine) |
|
128 { |
|
129 iCurrentLine = HBufC::NewL(KICalMaxLineLength); |
|
130 } |
|
131 |
|
132 if ((iCurrentLine->Length() + aLine.Length()) > iCurrentLine->Des().MaxLength()) |
|
133 { |
|
134 // Reallocate the buffer |
|
135 iCurrentLine = iCurrentLine->ReAllocL(iCurrentLine->Des().MaxLength() + aLine.Length()); |
|
136 } |
|
137 |
|
138 iCurrentLine->Des().Append(aLine); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CESMRICalContentLineWriter::AppendL |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 void CESMRICalContentLineWriter::AppendL(const TChar& aCharacter) |
|
146 { |
|
147 FUNC_LOG; |
|
148 |
|
149 if (!iCurrentLine) |
|
150 { |
|
151 iCurrentLine = HBufC::NewL(KICalMaxLineLength); |
|
152 } |
|
153 |
|
154 if ((iCurrentLine->Length() + 1) > iCurrentLine->Des().MaxLength()) |
|
155 { |
|
156 // Reallocate the buffer - expand by KICalMaxLineLength rather than '1' |
|
157 // to allow space for further expansion without further reallocation. |
|
158 iCurrentLine = iCurrentLine->ReAllocL(iCurrentLine->Des().MaxLength() + KICalMaxLineLength); |
|
159 } |
|
160 |
|
161 iCurrentLine->Des().Append(aCharacter); |
|
162 |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CESMRICalContentLineWriter::CESMRICalContentLineWriter |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 CESMRICalContentLineWriter::CESMRICalContentLineWriter(RWriteStream& aStream) |
|
170 : iWriteStream(aStream) |
|
171 { |
|
172 FUNC_LOG; |
|
173 //do nothing |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // CESMRICalContentLineWriter::ConstructL |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CESMRICalContentLineWriter::ConstructL() |
|
181 { |
|
182 FUNC_LOG; |
|
183 iCurrentLine = HBufC::NewL(KICalMaxLineLength); |
|
184 } |
|
185 |
|
186 // End of File |
|
187 |