equal
deleted
inserted
replaced
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include "TXTETEXT.H" |
19 #include "TXTETEXT.H" |
20 #include "TXTSTD.H" |
20 #include "TXTSTD.H" |
|
21 #include "OstTraceDefinitions.h" |
|
22 #ifdef OST_TRACE_COMPILER_IN_USE |
|
23 #include "TXTSCANTraces.h" |
|
24 #endif |
|
25 |
21 |
26 |
22 |
27 |
23 EXPORT_C TInt CPlainText::CharPosOfParagraph(TInt& aLength,TInt aParaOffset)const |
28 EXPORT_C TInt CPlainText::CharPosOfParagraph(TInt& aLength,TInt aParaOffset)const |
24 /** Finds the length and the start position of a paragraph identified by its |
29 /** Finds the length and the start position of a paragraph identified by its |
25 paragraph number the first paragraph is numbered zero. |
30 paragraph number the first paragraph is numbered zero. |
59 @return The number of the paragraph containing the specified document position. |
64 @return The number of the paragraph containing the specified document position. |
60 The first paragraph is numbered zero. */ |
65 The first paragraph is numbered zero. */ |
61 { |
66 { |
62 __TEST_INVARIANT; |
67 __TEST_INVARIANT; |
63 |
68 |
|
69 if (aPos<0 || aPos>DocumentLength()) |
|
70 { |
|
71 OstTrace0( TRACE_FATAL, CPLAINTEXT_PARAGRAPHNUMBERFORPOS, "ECharPosBeyondDocument" ); |
|
72 } |
64 __ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
73 __ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
65 TUint scanMask=(EScanBackwards|EScanStayIfBoundary|EScanToUnitStart); |
74 TUint scanMask=(EScanBackwards|EScanStayIfBoundary|EScanToUnitStart); |
66 ScanParas(aPos,scanMask); |
75 ScanParas(aPos,scanMask); |
67 // aPos now holds the 1st char of the paragraph. |
76 // aPos now holds the 1st char of the paragraph. |
68 TInt paraOffset=0,currentPos=0; |
77 TInt paraOffset=0,currentPos=0; |
91 @param aPunctuationIsDelimiter ETrue if punctuation characters should be treated |
100 @param aPunctuationIsDelimiter ETrue if punctuation characters should be treated |
92 as word delimiters, EFalse if not. */ |
101 as word delimiters, EFalse if not. */ |
93 { |
102 { |
94 __TEST_INVARIANT; |
103 __TEST_INVARIANT; |
95 |
104 |
|
105 if (aCurrentPos<0 || aCurrentPos>DocumentLength()) |
|
106 { |
|
107 OstTrace0( TRACE_FATAL, CPLAINTEXT_GETWORDINFO, "ECharPosBeyondDocument" ); |
|
108 } |
96 __ASSERT_ALWAYS(aCurrentPos>=0 && aCurrentPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
109 __ASSERT_ALWAYS(aCurrentPos>=0 && aCurrentPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
97 aStartPos=aLength=aCurrentPos; |
110 aStartPos=aLength=aCurrentPos; |
98 // First find the start of the word. |
111 // First find the start of the word. |
99 TUint scanMask=(EScanBackwards| |
112 TUint scanMask=(EScanBackwards| |
100 EScanStayIfBoundary| |
113 EScanStayIfBoundary| |
110 scanMask|=EScanPictureIsDelimiter; |
123 scanMask|=EScanPictureIsDelimiter; |
111 if (aPunctuationIsDelimiter) |
124 if (aPunctuationIsDelimiter) |
112 scanMask|=EScanPunctuationIsDelimiter; |
125 scanMask|=EScanPunctuationIsDelimiter; |
113 ScanWords(aLength,scanMask); |
126 ScanWords(aLength,scanMask); |
114 aLength-=aStartPos; |
127 aLength-=aStartPos; |
|
128 if (aLength+aStartPos>(DocumentLength()+1)) |
|
129 { |
|
130 OstTrace0( TRACE_DUMP, DUP2_CPLAINTEXT_GETWORDINFO, "ECharPosBeyondDocument" ); |
|
131 } |
115 __ASSERT_DEBUG(aLength+aStartPos<=(DocumentLength()+1),Panic(ECharPosBeyondDocument)); |
132 __ASSERT_DEBUG(aLength+aStartPos<=(DocumentLength()+1),Panic(ECharPosBeyondDocument)); |
116 |
133 |
117 __TEST_INVARIANT; |
134 __TEST_INVARIANT; |
118 } |
135 } |
119 |
136 |
126 which it is located. |
143 which it is located. |
127 @return The number of characters skipped in scanning to the start of the |
144 @return The number of characters skipped in scanning to the start of the |
128 paragraph. */ |
145 paragraph. */ |
129 { |
146 { |
130 __TEST_INVARIANT; |
147 __TEST_INVARIANT; |
|
148 if (aPos<0 || aPos>DocumentLength()) |
|
149 { |
|
150 OstTrace0( TRACE_FATAL, CPLAINTEXT_TOPARAGRAPHSTART, "ECharPosBeyondDocument" ); |
|
151 } |
131 __ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
152 __ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
132 |
153 |
133 int skipped = 0; |
154 int skipped = 0; |
134 while (aPos > 0) |
155 while (aPos > 0) |
135 { |
156 { |
211 panic occurs. On return, contains the new document position. |
232 panic occurs. On return, contains the new document position. |
212 @param aScanMask The scan mask. See the enumeration whose values begin with |
233 @param aScanMask The scan mask. See the enumeration whose values begin with |
213 CPlainText::EScanBackwards. |
234 CPlainText::EScanBackwards. |
214 @return The number of characters skipped to reach the new document position. */ |
235 @return The number of characters skipped to reach the new document position. */ |
215 { |
236 { |
|
237 if (aPos<0 || aPos>DocumentLength()) |
|
238 { |
|
239 OstTrace0( TRACE_FATAL, CPLAINTEXT_SCANWORDS, "ECharPosBeyondDocument" ); |
|
240 } |
216 __ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
241 __ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
217 SScanData scanData; |
242 SScanData scanData; |
218 InitScanControl(aPos,aScanMask,EUnitIsWord,scanData); |
243 InitScanControl(aPos,aScanMask,EUnitIsWord,scanData); |
219 return ScanUnit(aPos,EUnitIsWord,scanData); |
244 return ScanUnit(aPos,EUnitIsWord,scanData); |
220 } |
245 } |
234 On return, contains the new document position. |
259 On return, contains the new document position. |
235 @param aScanMask The scan mask. See the enumeration whose values begin with |
260 @param aScanMask The scan mask. See the enumeration whose values begin with |
236 CPlainText::EScanBackwards. |
261 CPlainText::EScanBackwards. |
237 @return The number of characters skipped to reach the new document position. */ |
262 @return The number of characters skipped to reach the new document position. */ |
238 { |
263 { |
|
264 if (aPos<0 || aPos>DocumentLength()) |
|
265 { |
|
266 OstTrace0( TRACE_FATAL, CPLAINTEXT_SCANPARAS, "ECharPosBeyondDocument" ); |
|
267 } |
239 __ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
268 __ASSERT_ALWAYS(aPos>=0 && aPos<=DocumentLength(),Panic(ECharPosBeyondDocument)); |
240 SScanData scanData; |
269 SScanData scanData; |
241 InitScanControl(aPos,aScanMask,EUnitIsParagraph,scanData); |
270 InitScanControl(aPos,aScanMask,EUnitIsParagraph,scanData); |
242 return ScanUnit(aPos,EUnitIsParagraph,scanData); |
271 return ScanUnit(aPos,EUnitIsParagraph,scanData); |
243 } |
272 } |