sl@0: /* sl@0: * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Contains miscellaneous utility functions that can be used by any code in security component sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include "miscutil.h" sl@0: sl@0: namespace MiscUtil sl@0: { sl@0: /* sl@0: * Function used to extract lines of text from a buffer. Note that this only works for non-unicode text. It skips sl@0: * over blank lines and the characters '\n' or '\r' are treated as end-of-line markers. sl@0: * sl@0: * @param aBuffer Input buffer sl@0: * @param aPos Starting index into aBuffer sl@0: * @return ETrue if a line was successfully extracted from the buffer, EFalse if end of buffer reached sl@0: */ sl@0: sl@0: EXPORT_C TBool ReadNonEmptyLineL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine) sl@0: { sl@0: TBool lineIdentified = ETrue; sl@0: aLine.Set(NULL, 0); sl@0: sl@0: TInt bufferLength = aBuffer.Length(); sl@0: __ASSERT_ALWAYS(aPos >=0 && aPos <= bufferLength, User::Leave(KErrArgument)); sl@0: sl@0: // Skip blank lines sl@0: while (aPos < bufferLength) sl@0: { sl@0: TChar c = aBuffer[aPos]; sl@0: if (c != '\r' && c != '\n') sl@0: { sl@0: break; sl@0: } sl@0: aPos++; sl@0: } sl@0: sl@0: // Find the position of the next delimter sl@0: TInt endPos = aPos; sl@0: while (endPos < bufferLength) sl@0: { sl@0: TChar c = aBuffer[endPos]; sl@0: if (c == '\n' || c == '\r') // Find end of line sl@0: { sl@0: break; sl@0: } sl@0: endPos++; sl@0: } sl@0: sl@0: if (endPos != aPos) sl@0: { sl@0: TInt tokenLen = endPos - aPos; sl@0: aLine.Set(&aBuffer[aPos], tokenLen); sl@0: } sl@0: else sl@0: { sl@0: lineIdentified = EFalse; // End of buffer sl@0: } sl@0: sl@0: aPos = endPos; sl@0: return lineIdentified; sl@0: } sl@0: sl@0: /* sl@0: * Recursively deletes all folders in the path (as long as they are empty) sl@0: * sl@0: * @param aFs Connected filesystem session sl@0: * @param aPath Fully qualified path to start the recursive delete sl@0: */ sl@0: EXPORT_C void DeletePathIfEmpty(RFs& aFs, const TDesC& aPath) sl@0: { sl@0: TParse path; sl@0: path.Set(aPath,NULL,NULL); sl@0: sl@0: if (path.PathPresent()) sl@0: { sl@0: while ((aFs.RmDir(path.DriveAndPath()) == KErrNone) && (path.PopDir() == KErrNone)) sl@0: ; sl@0: } sl@0: } sl@0: sl@0: } // namespace MiscUtil