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