|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : TSIPLogLineParser.cpp |
|
15 // Part of : Logging |
|
16 // Version : SIP/2.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "TSIPLogLineParser.h" |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // TSIPLogLineParser::TSIPLogLineParser |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 TSIPLogLineParser::TSIPLogLineParser (const TDesC8& aMessage, |
|
29 TUint aMaxLineLength) |
|
30 : iMaxLineLength(aMaxLineLength), |
|
31 iMessage(aMessage), |
|
32 iCurrentPos(0) |
|
33 { |
|
34 } |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // TSIPLogLineParser::End |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 TBool TSIPLogLineParser::End () |
|
41 { |
|
42 return (iCurrentPos >= iMessage.Length()); |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // TSIPLogLineParser::GetLine |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 TPtrC8 TSIPLogLineParser::GetLine () |
|
50 { |
|
51 if (End()) return TPtrC8(); |
|
52 |
|
53 TPtrC8 ptr(iMessage.Mid(iCurrentPos)); |
|
54 TUint lineEndOffset = 0; |
|
55 TInt nextLineEndPos = FindNextLineEndPos(ptr,lineEndOffset); |
|
56 TUint length; |
|
57 if (nextLineEndPos == KErrNotFound) |
|
58 { |
|
59 if (ptr.Length() < iMaxLineLength) |
|
60 { |
|
61 length = ptr.Length(); |
|
62 } |
|
63 else |
|
64 { |
|
65 length = iMaxLineLength; |
|
66 } |
|
67 } |
|
68 else |
|
69 { |
|
70 if (nextLineEndPos <= iMaxLineLength) |
|
71 { |
|
72 length = nextLineEndPos; |
|
73 iCurrentPos += lineEndOffset; |
|
74 } |
|
75 else |
|
76 { |
|
77 length = iMaxLineLength; |
|
78 } |
|
79 } |
|
80 iCurrentPos += length; |
|
81 return ptr.Left(length); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // TSIPLogLineParser::FindNextLineEndPos |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 TInt TSIPLogLineParser::FindNextLineEndPos (const TDesC8& aDes, |
|
89 TUint& aLineEndOffset) |
|
90 { |
|
91 TInt crPos = aDes.Locate ('\r'); |
|
92 TInt lfPos = aDes.Locate ('\n'); |
|
93 |
|
94 TInt pos = KErrNotFound; |
|
95 if (!(crPos == KErrNotFound)) |
|
96 { |
|
97 aLineEndOffset = 1; |
|
98 if (!(lfPos == KErrNotFound)) |
|
99 { |
|
100 if (crPos < lfPos) |
|
101 { |
|
102 if (crPos+1 == lfPos) aLineEndOffset = 2; |
|
103 pos = crPos; |
|
104 } |
|
105 else |
|
106 { |
|
107 pos = lfPos; |
|
108 } |
|
109 } |
|
110 else |
|
111 { |
|
112 pos = crPos; |
|
113 } |
|
114 } |
|
115 else |
|
116 { |
|
117 if (!(lfPos == KErrNotFound)) |
|
118 { |
|
119 aLineEndOffset = 1; |
|
120 pos = lfPos; |
|
121 } |
|
122 } |
|
123 return pos; |
|
124 } |