|
1 /* |
|
2 * Copyright (c) 2004-2008 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 using System; |
|
19 using System.Text; |
|
20 using System.Collections; |
|
21 using SymBuildParsingLib.Lexer; |
|
22 using SymBuildParsingLib.Utils; |
|
23 |
|
24 namespace SymBuildParsingLib.Lexer |
|
25 { |
|
26 public class SymLexerWorkerLine : SymLexerWorker, ISymLexerPositionProvider |
|
27 { |
|
28 #region Constructors & destructor |
|
29 public SymLexerWorkerLine( SymLexer aLexer ) |
|
30 : base( aLexer ) |
|
31 { |
|
32 } |
|
33 #endregion |
|
34 |
|
35 #region Properties |
|
36 public char LastCharacter |
|
37 { |
|
38 get { return iLastCharacter; } |
|
39 set { iLastCharacter = value; } |
|
40 } |
|
41 #endregion |
|
42 |
|
43 #region SymLexerWorker Members |
|
44 public override bool ProcessCharacter( char aCharacter ) |
|
45 { |
|
46 bool consumed = false; |
|
47 |
|
48 // At the end of a line if we see 0x0A or then 0x0D and the next character is not 0x0A |
|
49 if ( aCharacter == KSymLineFeed || aCharacter == KSymCarriageReturn ) |
|
50 { |
|
51 if ( aCharacter == KSymLineFeed ) |
|
52 { |
|
53 // This is definitely the end of a line. If the last |
|
54 // character was a carriage return, then we mark |
|
55 // the start of the end-of-line as the previous |
|
56 // character. Otherwise, its this one. |
|
57 AddNewEndOfLinePosition(); |
|
58 } |
|
59 else |
|
60 { |
|
61 // Its a CR (0x0D) but it might be followed by a LF |
|
62 // so don't do anything yet. |
|
63 LastCharacter = aCharacter; |
|
64 } |
|
65 |
|
66 consumed = true; |
|
67 } |
|
68 else if ( LastCharacter == KSymCarriageReturn ) |
|
69 { |
|
70 // The current character is not a line feed, but the last |
|
71 // char was a carriage return => implicitly, the last |
|
72 // character was an end of line. |
|
73 AddNewEndOfLinePosition(); |
|
74 } |
|
75 else |
|
76 { |
|
77 iCurrentPosition.Inc(); |
|
78 LastCharacter = aCharacter; |
|
79 } |
|
80 |
|
81 return consumed; |
|
82 } |
|
83 |
|
84 public override void StartedNewLine( SymTextPosition aEOLPosition ) |
|
85 { |
|
86 } |
|
87 #endregion |
|
88 |
|
89 #region ISymLexerPositionProvider Members |
|
90 public SymTextPosition CurrentPosition |
|
91 { |
|
92 get |
|
93 { |
|
94 return new SymTextPosition( iCurrentPosition ); |
|
95 } |
|
96 } |
|
97 |
|
98 public void SetObserver( ISymLexerPositionObserver aObserver ) |
|
99 { |
|
100 } |
|
101 #endregion |
|
102 |
|
103 #region Internal methods |
|
104 private void AddNewEndOfLinePosition() |
|
105 { |
|
106 iLineEndingPositions.Add( iCurrentPosition ); |
|
107 Lexer.HandleEndOfLineDetected( iCurrentPosition ); |
|
108 |
|
109 iCurrentPosition.NewLine(); |
|
110 iLastCharacter = '\0'; |
|
111 } |
|
112 #endregion |
|
113 |
|
114 #region Internal constants |
|
115 const int KSymLineFeed = 0xA; |
|
116 const int KSymCarriageReturn = 0xD; |
|
117 #endregion |
|
118 |
|
119 #region Data members |
|
120 private char iLastCharacter = '\0'; |
|
121 private ArrayList iLineEndingPositions = new ArrayList( 1024 ); |
|
122 private SymTextPosition iCurrentPosition = new SymTextPosition(); |
|
123 #endregion |
|
124 } |
|
125 } |