utilitylibraries/libutils/src/descriptor8towstring.cpp
changeset 0 e4d67989cc36
child 34 5fae379060a7
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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:   Contains the source for Descriptor to wstring conversions
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19  		
       
    20 #include "libutils.h"
       
    21   
       
    22 
       
    23  		
       
    24  /**
       
    25    * Converts a descriptor of type Tptrc8 to Wstring
       
    26    *
       
    27    * @param aSrc is the descriptor to be converted , aDes is the 
       
    28    * reference to the wstring array where the result of conversion 
       
    29    * is stored  
       
    30    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, 
       
    31    * -5 is EDescriptorNoData)
       
    32    */ 	
       
    33 
       
    34 EXPORT_C int Tptrc8ToWstring(TPtrC8& aSrc, wstring& aDes)
       
    35 {
       
    36     int retval = ESuccess;
       
    37     int ilen = aSrc.Length();
       
    38     int minusone = -1;
       
    39     
       
    40 	if (0 == ilen)
       
    41 	{
       
    42 		return EDescriptorNoData;
       
    43 	}
       
    44 	
       
    45 	wchar_t* wcharString = new wchar_t[ilen+1];
       
    46 	
       
    47 	if (!wcharString)
       
    48 	{
       
    49 		return EInsufficientSystemMemory;
       
    50 	}
       
    51 	
       
    52 	if(minusone != mbstowcs (wcharString, (const char*)aSrc.Ptr(), ilen))
       
    53 	{
       
    54 	    wcharString[ilen] = L'\0';
       
    55 		aDes.assign(wcharString); 	
       
    56 	}
       
    57 	else 
       
    58 	{
       
    59 		retval = EInvalidMBSSequence;
       
    60 	}
       
    61 	
       
    62     delete []wcharString;	
       
    63 	return retval;
       
    64 }
       
    65 
       
    66  /**
       
    67    * Converts a descriptor of type TBuf8 to wstring
       
    68    *
       
    69    * @param aSrc is the descriptor to be converted , aDes is the 
       
    70    * reference to the wstring array where the result of conversion 
       
    71    * is stored  
       
    72    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, 
       
    73    * -5 is EDescriptorNoData)
       
    74    */
       
    75 
       
    76 EXPORT_C int Tbuf8ToWstring(TDes8& aSrc, wstring& aDes)
       
    77 {
       
    78     int retval = ESuccess;
       
    79     unsigned int ilen = aSrc.Length();
       
    80     int minusone = -1;
       
    81     
       
    82 	if (0 == ilen)
       
    83 	{
       
    84 		return EDescriptorNoData;
       
    85 	}
       
    86 	
       
    87 	wchar_t* wcharString = new wchar_t[ilen+1];
       
    88 	
       
    89 	if (!wcharString)
       
    90 	{
       
    91 		return EInsufficientSystemMemory;
       
    92 	}
       
    93 	
       
    94 	if(minusone != mbstowcs (wcharString, (const char*)aSrc.Ptr(), ilen))
       
    95 	{
       
    96 	    wcharString[ilen] = L'\0';
       
    97 		aDes.assign(wcharString); 	
       
    98 	}
       
    99 	else 
       
   100 	{
       
   101 		retval = EInvalidMBSSequence;
       
   102 	}
       
   103 	
       
   104     delete []wcharString;	
       
   105 	return retval;
       
   106 }
       
   107 
       
   108  /**
       
   109    * Converts a descriptor of type TBufC8 to wstring
       
   110    *
       
   111    * @param aSrc is the descriptor to be converted , aDes is the 
       
   112    * reference to the wstring array where the result of conversion 
       
   113    * is stored  
       
   114    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, 
       
   115    * -5 is EDescriptorNoData)
       
   116    */
       
   117 
       
   118 EXPORT_C int Tbufc8ToWstring(TDesC8& aSrc, wstring& aDes)
       
   119 {
       
   120  
       
   121     int retval = ESuccess;
       
   122     unsigned int ilen = aSrc.Length();
       
   123     int minusone = -1;
       
   124     
       
   125 	if (0 == ilen)
       
   126 	{
       
   127 		return EDescriptorNoData;
       
   128 	}
       
   129 	
       
   130 	wchar_t* wcharString = new wchar_t[ilen+1];
       
   131 	
       
   132 	if (!wcharString)
       
   133 	{
       
   134 		return EInsufficientSystemMemory;
       
   135 	}
       
   136 	
       
   137 	if(minusone != mbstowcs (wcharString, (const char*)aSrc.Ptr(), ilen))
       
   138 	{
       
   139 	    wcharString[ilen] = L'\0';
       
   140 		aDes.assign (wcharString); 	
       
   141 	}
       
   142 	else 
       
   143 	{
       
   144 		retval = EInvalidMBSSequence;
       
   145 	}
       
   146 	
       
   147     delete []wcharString;	
       
   148 	return retval;
       
   149 }
       
   150 
       
   151  /**
       
   152    * Converts a descriptor of type Tptr8 to wstring
       
   153    *
       
   154    * @param aSrc is the descriptor to be converted , aDes is the 
       
   155    * reference to the wstring array where the result of conversion 
       
   156    * is stored  
       
   157    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, 
       
   158    * -5 is EDescriptorNoData)
       
   159    */
       
   160 
       
   161 EXPORT_C int Tptr8ToWstring(TPtr8& aSrc, wstring& aDes)
       
   162 {
       
   163     int retval= ESuccess;
       
   164     unsigned int ilen = aSrc.Length();
       
   165     int minusone = -1;
       
   166     
       
   167 	if (0 == ilen)
       
   168 	{
       
   169 		return EDescriptorNoData;
       
   170 	}
       
   171 
       
   172 	wchar_t* wcharString = new wchar_t[ilen+1];
       
   173 	if (!wcharString)
       
   174 	{
       
   175 		return EInsufficientSystemMemory;
       
   176 	}
       
   177 	
       
   178 	if(minusone != mbstowcs(wcharString, (const char*)aSrc.Ptr(), ilen))
       
   179 	{
       
   180 	    wcharString[ilen] = L'\0';
       
   181 	    aDes.assign(wcharString);
       
   182 	}
       
   183 	else
       
   184 	{
       
   185 		retval= EInvalidMBSSequence;
       
   186 	}
       
   187 	
       
   188     delete []wcharString;
       
   189 	return retval;
       
   190 }
       
   191 
       
   192  /**
       
   193    * Converts a descriptor of type RBuf8 to wstring
       
   194    *
       
   195    * @param aSrc is the descriptor to be converted , aDes is the 
       
   196    * reference to the wstring array where the result of conversion 
       
   197    * is stored  
       
   198    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, 
       
   199    * -5 is EDescriptorNoData)
       
   200    */
       
   201 
       
   202 EXPORT_C int Rbuf8ToWstring(TDes8& aSrc, wstring& aDes)
       
   203 {
       
   204     int retval = ESuccess; 
       
   205     unsigned int ilen = aSrc.Length();
       
   206     int minusone = -1;
       
   207     if (0 == ilen)
       
   208     {
       
   209     	return EDescriptorNoData;
       
   210     }
       
   211     
       
   212     wchar_t* buf = new wchar_t[ilen+1];
       
   213     if(!buf)
       
   214     {
       
   215     	return EInsufficientSystemMemory;
       
   216     }
       
   217     
       
   218     if(minusone != mbstowcs(buf, (char *)aSrc.Ptr(), ilen))
       
   219     {
       
   220         buf[ilen] = L'\0';
       
   221     	aDes.assign(buf);
       
   222     }
       
   223     else
       
   224     {
       
   225         retval = EInvalidMBSSequence;
       
   226     }
       
   227     
       
   228     delete []buf;
       
   229     return retval;
       
   230 }
       
   231 
       
   232  /**
       
   233    * Converts a descriptor of type HBuf8 to wstring
       
   234    *
       
   235    * @param aSrc is the descriptor to be converted , aDes is the 
       
   236    * reference to the wstring array where the result of conversion 
       
   237    * is stored  
       
   238    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, 
       
   239    * -4 is EInvalidPointer , -5 is EDescriptorNoData)
       
   240    */
       
   241 
       
   242 EXPORT_C int Hbufc8ToWstring(HBufC8* aSrc, wstring& aDes)
       
   243 {	
       
   244     unsigned int ilen =  0;
       
   245     int retval = ESuccess;
       
   246     int minusone = -1;
       
   247     	
       
   248     if (!aSrc)
       
   249     {
       
   250     	return EInvalidPointer;
       
   251     }
       
   252     else
       
   253     {
       
   254         ilen = aSrc->Length();
       
   255         if (0 == ilen )
       
   256         {
       
   257         	return EDescriptorNoData;	
       
   258         }  	
       
   259     }
       
   260     			
       
   261 	wchar_t* buff = new wchar_t[ilen+1];
       
   262 	if (!buff)
       
   263 	{
       
   264 		return EInsufficientSystemMemory;
       
   265 	}
       
   266     
       
   267     if(minusone != mbstowcs(buff, (char *)aSrc->Ptr(), ilen))
       
   268     {
       
   269         buff[ilen] = L'\0';
       
   270     	aDes.assign(buff);
       
   271     }
       
   272     else
       
   273     {
       
   274         retval = EInvalidMBSSequence;
       
   275     }
       
   276     
       
   277     delete []buff;
       
   278     return retval;
       
   279 }
       
   280 
       
   281  /**
       
   282     * Converts a descriptor of type Tlitc8 to wstring
       
   283     *
       
   284     * @param aSrc is the descriptor to be converted , aDes is the 
       
   285     * reference to the wstring array where the result of conversion 
       
   286     * is stored  
       
   287     * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, 
       
   288     * -5 is EDescriptorNoData)
       
   289     */
       
   290 
       
   291 EXPORT_C int Tlitc8ToWstring(TDes8& aSrc, wstring& aDes)
       
   292 {
       
   293     int retval= ESuccess;
       
   294     unsigned int ilen = aSrc.Length();
       
   295     int minusone = -1;
       
   296     
       
   297 	if (0 == ilen)
       
   298 	{
       
   299 		return EDescriptorNoData;
       
   300 	}
       
   301 
       
   302 	wchar_t* wcharString = new wchar_t[ilen+1];
       
   303 	if (!wcharString)
       
   304 	{
       
   305 		return EInsufficientSystemMemory;
       
   306 	}
       
   307 	
       
   308 	if(minusone != mbstowcs(wcharString, (const char*)aSrc.Ptr(), ilen))
       
   309 	{
       
   310 	    wcharString[ilen] = L'\0';
       
   311 	    aDes.assign(wcharString);
       
   312 	}
       
   313 	else
       
   314 	{
       
   315 		retval= EInvalidMBSSequence;
       
   316 	}
       
   317 	
       
   318     delete []wcharString;
       
   319 	return retval;
       
   320 }
       
   321