multimediacommsengine/mmcesrv/mmcemediamanager/src/mceloglineparser.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 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 
       
    19 
       
    20 #include "mceloglineparser.h"
       
    21 
       
    22 // -----------------------------------------------------------------------------
       
    23 // TMceLogLineParser::TMceLogLineParser
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 TMceLogLineParser::TMceLogLineParser(
       
    27     const TDesC8& aMessage,
       
    28     TUint aMaxLineLength)
       
    29  : iMaxLineLength(aMaxLineLength),
       
    30    iMessage(aMessage),
       
    31    iCurrentPos(0)
       
    32 	{
       
    33 	}
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // TMceLogLineParser::End
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 TBool TMceLogLineParser::End()
       
    40 	{
       
    41 	return (iCurrentPos >= iMessage.Length());
       
    42 	}
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // TMceLogLineParser::GetLine
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 TPtrC8 TMceLogLineParser::GetLine()
       
    49 	{
       
    50 	if (End())
       
    51 	    {
       
    52 	    return TPtrC8();
       
    53 	    }
       
    54     TPtrC8 ptr(iMessage.Mid(iCurrentPos));
       
    55     TUint lineEndOffset = 0;
       
    56     TInt nextLineEndPos = FindNextLineEndPos(ptr,lineEndOffset);
       
    57     TUint length;
       
    58     if (nextLineEndPos == KErrNotFound)
       
    59 		{
       
    60         if (ptr.Length() < iMaxLineLength) 
       
    61 			{
       
    62             length = ptr.Length();
       
    63 			}
       
    64         else
       
    65 			{
       
    66             length = iMaxLineLength;
       
    67 			}
       
    68 		}
       
    69     else
       
    70 		{
       
    71         if (nextLineEndPos <= iMaxLineLength)
       
    72 			{
       
    73             length = nextLineEndPos;
       
    74             iCurrentPos += lineEndOffset;
       
    75 			}
       
    76         else
       
    77 			{
       
    78             length = iMaxLineLength;
       
    79 			}
       
    80 		}
       
    81     iCurrentPos += length;
       
    82     return ptr.Left(length);
       
    83 	}
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // TMceLogLineParser::FindNextLineEndPos
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TInt TMceLogLineParser::FindNextLineEndPos(
       
    90     const TDesC8& aDes,
       
    91     TUint& aLineEndOffset)
       
    92 	{
       
    93     TInt crPos = aDes.Locate ('\r');
       
    94     TInt lfPos = aDes.Locate ('\n');
       
    95 
       
    96     TInt pos = KErrNotFound;
       
    97     if (!(crPos == KErrNotFound))
       
    98 		{
       
    99         aLineEndOffset = 1;
       
   100         if (!(lfPos == KErrNotFound))
       
   101 			{
       
   102             if (crPos < lfPos)
       
   103 				{
       
   104                 if (crPos+1 == lfPos) aLineEndOffset = 2;
       
   105                 pos = crPos;
       
   106 				}
       
   107             else
       
   108 				{
       
   109                 pos = lfPos;
       
   110 				}
       
   111 			}
       
   112         else
       
   113 			{
       
   114             pos = crPos;
       
   115 			}
       
   116 		}
       
   117     else
       
   118 		{
       
   119         if (!(lfPos == KErrNotFound))
       
   120 			{
       
   121             aLineEndOffset = 1;
       
   122             pos = lfPos;
       
   123 			}
       
   124 		}
       
   125     return pos;
       
   126 	}