phonebookengines/VirtualPhonebook/VPbkEngUtils/src/VPbkEngUtils.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 02 Feb 2010 10:12:17 +0200
changeset 0 e686773b3f54
permissions -rw-r--r--
Revision: 201003 Kit: 201005

/*
* Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Virtual phonebook engine utils
*
*/


#include "VPbkEngUtils.h"

namespace VPbkEngUtils {

// FUNCTIONS

void ExpandL(HBufC*& aBuffer, TInt aLength)
	{
    if (!aBuffer)
        {
        aBuffer = HBufC::NewL(aLength);
        }
    TPtr bufPtr(aBuffer->Des());
    const TInt maxLength = bufPtr.MaxLength();
    if (maxLength < aLength)
        {
        aBuffer = aBuffer->ReAllocL(Max(2*maxLength, aLength));
        }
	}

const TDesC& ReverseL(HBufC*& aBuffer, const TDesC& aText)
    {
    const TInt length = aText.Length();
	ExpandL(aBuffer, length);
	TPtr bufPtr(aBuffer->Des());
    bufPtr.Zero();
    for (TInt i = length-1; i >= 0; --i)
        {
        bufPtr.Append(aText[i]);
        }
    return *aBuffer;
    }

/**
 * Counts and returns the number of decimal digit characters in aText.
 */
TInt CountDigits(const TDesC& aText)
    {
    TInt result = 0;
    const TInt length = aText.Length();
    for (TInt textPos = 0; textPos < length; ++textPos)
        {
        const TInt numVal = TChar(aText[textPos]).GetNumericValue();
        if (numVal >= 0 && numVal <= 9)
            {
            ++result;
            }
        }
    return result;
    }

} // namespace VPbkEngUtils