imservices/ossprotocoladaptation/src/ossprotocoladaptutils.cpp
branchRCL_3
changeset 14 7797b2f86d2b
parent 13 b6f2a363adf7
child 16 cfe5eb8bb9ca
equal deleted inserted replaced
13:b6f2a363adf7 14:7797b2f86d2b
     1 /*
       
     2 * Copyright (c) 2008 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 "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:  Utils for OSSProtocolAdaptation modules.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "ossprotocoladaptutils.h"
       
    21 #include <stdio.h>
       
    22 #include <stdlib.h>
       
    23 #include <string.h>
       
    24 #include "escapeutils.h"
       
    25 #include "stringutils.h"
       
    26   
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // OssProtocolAdapUtils::OssProtocolAdapUtils::ConvertCharToTUint16L
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 HBufC16* OssProtocolAdapUtils::ConvertCharToTUint16LC( const char *pcSrc )
       
    33 	{
       
    34 	TUint8* scr = (TUint8*)pcSrc;
       
    35 	TPtrC8 ptr;
       
    36 	ptr.Set(scr);
       
    37 	HBufC16* buf = EscapeUtils::ConvertToUnicodeFromUtf8L(ptr);
       
    38 	CleanupStack::PushL(buf);
       
    39 	return buf;	
       
    40 	}
       
    41 	
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // OssProtocolAdapUtils::OssProtocolAdapUtils::ConvertTUint16ToCharL
       
    45 // ---------------------------------------------------------------------------
       
    46 //	
       
    47 charFormatData OssProtocolAdapUtils::ConvertTUint16ToCharLC( const TDesC &aData )
       
    48 	{
       
    49 	HBufC8 * data = EscapeUtils::ConvertFromUnicodeToUtf8L( aData );
       
    50 	CleanupStack::PushL(data);
       
    51 	
       
    52 	TPtr8 ptr = data->Des();
       
    53 	TInt length = ptr.Length();
       
    54 	
       
    55 	//allocate new contiguous buffer as returned buffer may be fragmented.	
       
    56 	HBufC8* newBuf = HBufC8::NewLC( length + 1 );//+1 space for '\0'
       
    57 	TPtr8 newBufPtr = newBuf->Des();
       
    58 	newBufPtr.Copy(ptr);
       
    59 	
       
    60 	char* chPtrTemp = ( char* )newBufPtr.PtrZ(); 
       
    61 	char* chPtr = (char*) User::AllocL( length + 1 );
       
    62 	strcpy( chPtr , chPtrTemp );
       
    63 	
       
    64 	CleanupStack::PopAndDestroy( 2 );//newBuf,data.
       
    65 	
       
    66 	charFormatData charData ;
       
    67 	charData.data = chPtr;
       
    68 	charData.dataSize = length + 1; //+1 space for '\0'
       
    69 	
       
    70 	CleanupStack::PushL(chPtr);
       
    71 	return charData;
       
    72 	}
       
    73 // ---------------------------------------------------------------------------
       
    74 // OssProtocolAdapUtils::ConvertTDesC8toChar
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void OssProtocolAdapUtils::ConvertTDesC8toChar(const TDesC8& aSrc, char* aDes)
       
    78 {
       
    79     char *temp = (char*)aSrc.Ptr();
       
    80     const TInt size = aSrc.Length();
       
    81     *(temp + size) = '\0';
       
    82     memcpy( aDes, temp, size );
       
    83 }
       
    84 
       
    85 // End of file