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.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Contains miscellaneous utility functions that can be used by any code in security component
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include "miscutil.h"
sl@0
    25
sl@0
    26
namespace MiscUtil
sl@0
    27
{
sl@0
    28
/*
sl@0
    29
 * Function used to extract lines of text from a buffer. Note that this only works for non-unicode text. It skips
sl@0
    30
 * over blank lines and the characters '\n' or '\r' are treated as end-of-line markers.
sl@0
    31
 *
sl@0
    32
 * @param aBuffer		Input buffer
sl@0
    33
 * @param aPos		Starting index into aBuffer
sl@0
    34
 * @return			ETrue if a line was successfully extracted from the buffer, EFalse if end of buffer reached
sl@0
    35
 */
sl@0
    36
sl@0
    37
EXPORT_C TBool ReadNonEmptyLineL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine)
sl@0
    38
	{
sl@0
    39
	TBool lineIdentified = ETrue;
sl@0
    40
	aLine.Set(NULL, 0);
sl@0
    41
sl@0
    42
	TInt bufferLength = aBuffer.Length();
sl@0
    43
	__ASSERT_ALWAYS(aPos >=0 && aPos <= bufferLength, User::Leave(KErrArgument));
sl@0
    44
sl@0
    45
	// Skip blank lines
sl@0
    46
	while (aPos < bufferLength)
sl@0
    47
		{
sl@0
    48
		TChar  c = aBuffer[aPos];
sl@0
    49
		if (c != '\r' && c != '\n')
sl@0
    50
			{
sl@0
    51
			break;
sl@0
    52
			}
sl@0
    53
		aPos++;
sl@0
    54
		}
sl@0
    55
sl@0
    56
	// Find the position of the next delimter
sl@0
    57
	TInt endPos = aPos;
sl@0
    58
	while (endPos < bufferLength)
sl@0
    59
		{
sl@0
    60
		TChar c = aBuffer[endPos];
sl@0
    61
		if (c == '\n' || c == '\r') 	// Find end of line
sl@0
    62
			{
sl@0
    63
			break;
sl@0
    64
			}
sl@0
    65
		endPos++;
sl@0
    66
		}
sl@0
    67
sl@0
    68
	if (endPos != aPos)
sl@0
    69
		{
sl@0
    70
		TInt tokenLen = endPos - aPos;
sl@0
    71
		aLine.Set(&aBuffer[aPos], tokenLen);
sl@0
    72
		}
sl@0
    73
	else
sl@0
    74
		{
sl@0
    75
		lineIdentified = EFalse; // End of buffer
sl@0
    76
		}
sl@0
    77
sl@0
    78
	aPos = endPos;
sl@0
    79
	return lineIdentified;
sl@0
    80
	}
sl@0
    81
sl@0
    82
/*
sl@0
    83
 * Recursively deletes all folders in the path (as long as they are empty)
sl@0
    84
 *
sl@0
    85
 * @param aFs		Connected  filesystem session
sl@0
    86
 * @param aPath		Fully qualified path to start the recursive delete
sl@0
    87
 */
sl@0
    88
EXPORT_C void DeletePathIfEmpty(RFs& aFs, const TDesC& aPath)
sl@0
    89
	{
sl@0
    90
	TParse path;
sl@0
    91
	path.Set(aPath,NULL,NULL);
sl@0
    92
sl@0
    93
	if (path.PathPresent())
sl@0
    94
		{
sl@0
    95
		while ((aFs.RmDir(path.DriveAndPath()) == KErrNone) && (path.PopDir() == KErrNone))
sl@0
    96
			;
sl@0
    97
		}		
sl@0
    98
	}
sl@0
    99
sl@0
   100
}	// namespace MiscUtil