os/security/cryptomgmtlibs/securityutils/source/sectcbutil/miscutil.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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  @file
    22 */
    23 
    24 #include "miscutil.h"
    25 
    26 namespace MiscUtil
    27 {
    28 /*
    29  * Function used to extract lines of text from a buffer. Note that this only works for non-unicode text. It skips
    30  * over blank lines and the characters '\n' or '\r' are treated as end-of-line markers.
    31  *
    32  * @param aBuffer		Input buffer
    33  * @param aPos		Starting index into aBuffer
    34  * @return			ETrue if a line was successfully extracted from the buffer, EFalse if end of buffer reached
    35  */
    36 
    37 EXPORT_C TBool ReadNonEmptyLineL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine)
    38 	{
    39 	TBool lineIdentified = ETrue;
    40 	aLine.Set(NULL, 0);
    41 
    42 	TInt bufferLength = aBuffer.Length();
    43 	__ASSERT_ALWAYS(aPos >=0 && aPos <= bufferLength, User::Leave(KErrArgument));
    44 
    45 	// Skip blank lines
    46 	while (aPos < bufferLength)
    47 		{
    48 		TChar  c = aBuffer[aPos];
    49 		if (c != '\r' && c != '\n')
    50 			{
    51 			break;
    52 			}
    53 		aPos++;
    54 		}
    55 
    56 	// Find the position of the next delimter
    57 	TInt endPos = aPos;
    58 	while (endPos < bufferLength)
    59 		{
    60 		TChar c = aBuffer[endPos];
    61 		if (c == '\n' || c == '\r') 	// Find end of line
    62 			{
    63 			break;
    64 			}
    65 		endPos++;
    66 		}
    67 
    68 	if (endPos != aPos)
    69 		{
    70 		TInt tokenLen = endPos - aPos;
    71 		aLine.Set(&aBuffer[aPos], tokenLen);
    72 		}
    73 	else
    74 		{
    75 		lineIdentified = EFalse; // End of buffer
    76 		}
    77 
    78 	aPos = endPos;
    79 	return lineIdentified;
    80 	}
    81 
    82 /*
    83  * Recursively deletes all folders in the path (as long as they are empty)
    84  *
    85  * @param aFs		Connected  filesystem session
    86  * @param aPath		Fully qualified path to start the recursive delete
    87  */
    88 EXPORT_C void DeletePathIfEmpty(RFs& aFs, const TDesC& aPath)
    89 	{
    90 	TParse path;
    91 	path.Set(aPath,NULL,NULL);
    92 
    93 	if (path.PathPresent())
    94 		{
    95 		while ((aFs.RmDir(path.DriveAndPath()) == KErrNone) && (path.PopDir() == KErrNone))
    96 			;
    97 		}		
    98 	}
    99 
   100 }	// namespace MiscUtil