cryptomgmtlibs/securityutils/source/sectcbutil/miscutil.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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 the License "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 * Contains miscellaneous utility functions that can be used by any code in security component
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file
       
    24 */
       
    25 
       
    26 #include "miscutil.h"
       
    27 
       
    28 namespace MiscUtil
       
    29 {
       
    30 /*
       
    31  * Function used to extract lines of text from a buffer. Note that this only works for non-unicode text. It skips
       
    32  * over blank lines and the characters '\n' or '\r' are treated as end-of-line markers.
       
    33  *
       
    34  * @param aBuffer		Input buffer
       
    35  * @param aPos		Starting index into aBuffer
       
    36  * @return			ETrue if a line was successfully extracted from the buffer, EFalse if end of buffer reached
       
    37  */
       
    38 
       
    39 EXPORT_C TBool ReadNonEmptyLineL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine)
       
    40 	{
       
    41 	TBool lineIdentified = ETrue;
       
    42 	aLine.Set(NULL, 0);
       
    43 
       
    44 	TInt bufferLength = aBuffer.Length();
       
    45 	__ASSERT_ALWAYS(aPos >=0 && aPos <= bufferLength, User::Leave(KErrArgument));
       
    46 
       
    47 	// Skip blank lines
       
    48 	while (aPos < bufferLength)
       
    49 		{
       
    50 		TChar  c = aBuffer[aPos];
       
    51 		if (c != '\r' && c != '\n')
       
    52 			{
       
    53 			break;
       
    54 			}
       
    55 		aPos++;
       
    56 		}
       
    57 
       
    58 	// Find the position of the next delimter
       
    59 	TInt endPos = aPos;
       
    60 	while (endPos < bufferLength)
       
    61 		{
       
    62 		TChar c = aBuffer[endPos];
       
    63 		if (c == '\n' || c == '\r') 	// Find end of line
       
    64 			{
       
    65 			break;
       
    66 			}
       
    67 		endPos++;
       
    68 		}
       
    69 
       
    70 	if (endPos != aPos)
       
    71 		{
       
    72 		TInt tokenLen = endPos - aPos;
       
    73 		aLine.Set(&aBuffer[aPos], tokenLen);
       
    74 		}
       
    75 	else
       
    76 		{
       
    77 		lineIdentified = EFalse; // End of buffer
       
    78 		}
       
    79 
       
    80 	aPos = endPos;
       
    81 	return lineIdentified;
       
    82 	}
       
    83 
       
    84 }	// namespace MiscUtil