|
1 /* |
|
2 * Copyright (c) 2004 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: Content writer for the XML Serializer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include "TPEngWriter.h" |
|
22 |
|
23 |
|
24 |
|
25 // ================= MEMBER FUNCTIONS ======================= |
|
26 // C++ default constructor can NOT contain any code, that |
|
27 // might leave. |
|
28 // |
|
29 TPEngWriter::TPEngWriter( TDes8& aBuffer ) |
|
30 : iBuffer( aBuffer ) |
|
31 { |
|
32 } |
|
33 |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // TPEngWriter::WriteL() |
|
37 // |
|
38 // Writes the text to buffer, leaves if the buffer overflows. |
|
39 // Returns pointer descriptor pointing to just written text |
|
40 // (pointer desriptor stays valid until the actual buffer stays valid). |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 const TPtrC8 TPEngWriter::WriteL( const TDesC8& aText ) |
|
44 { |
|
45 if ( iBuffer.MaxLength() < ( iBuffer.Length() + aText.Length() ) ) |
|
46 { |
|
47 User::Leave( KErrOverflow ); |
|
48 } |
|
49 |
|
50 else |
|
51 { |
|
52 TInt startOfNew( iBuffer.Length() ); |
|
53 iBuffer.Append( aText ); |
|
54 return iBuffer.Mid( startOfNew ); |
|
55 } |
|
56 |
|
57 return TPtrC8( NULL, 0 ); |
|
58 } |
|
59 |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // TPEngWriter::WriteL() |
|
63 // |
|
64 // Writes one character to buffer, leaves if the buffer overflows. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void TPEngWriter::WriteL( TUint8 aCharacter ) |
|
68 { |
|
69 if ( iBuffer.MaxLength() < ( iBuffer.Length() + 1 ) ) //here magic number 1 means that we are |
|
70 //writing just one character at time |
|
71 { |
|
72 User::Leave( KErrOverflow ); |
|
73 } |
|
74 |
|
75 else |
|
76 { |
|
77 iBuffer.Append( &aCharacter, 1 ); //here magic number 1 means that we are |
|
78 //writing just one character at time |
|
79 } |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // TPEngWriter::CurrentLength() |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 TInt TPEngWriter::CurrentLength() |
|
87 { |
|
88 return iBuffer.Length(); |
|
89 } |
|
90 |
|
91 |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // TPEngWriter::ReverseTo() |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 TInt TPEngWriter::ReverseTo( TInt aLength ) |
|
98 { |
|
99 if ( aLength > iBuffer.Length() ) |
|
100 { |
|
101 return KErrUnderflow; |
|
102 } |
|
103 |
|
104 iBuffer.SetLength( aLength ); |
|
105 return KErrNone; |
|
106 } |
|
107 |
|
108 |
|
109 // End of File |
|
110 |
|
111 |
|
112 |
|
113 |