utilitylibraries/libutils/src/chartodescriptor8.cpp
changeset 34 5fae379060a7
parent 0 e4d67989cc36
child 57 2efc27d87e1c
equal deleted inserted replaced
31:ce057bb09d0b 34:5fae379060a7
    27    * @param aSrc is char* which is to be converted to TBuf8
    27    * @param aSrc is char* which is to be converted to TBuf8
    28    * @param aDes is the pointer to the descriptor of type TBuf8 which will hold
    28    * @param aDes is the pointer to the descriptor of type TBuf8 which will hold
    29    * the result of conversion.aDes needs to be allocated with sufficient amount 
    29    * the result of conversion.aDes needs to be allocated with sufficient amount 
    30    * of memory before being passed to function. This Descriptor should have 
    30    * of memory before being passed to function. This Descriptor should have 
    31    * a allocation that is equal to or greater than char*
    31    * a allocation that is equal to or greater than char*
       
    32    *
       
    33    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer)
    32    */
    34    */
    33    
    35    
    34 EXPORT_C  int CharToTbuf8 (const char* aSrc, TDes8& aDes)
    36 EXPORT_C  int CharToTbuf8 (const char* aSrc, TDes8& aDes)
    35 {
    37 {
    36 	if (!aSrc)
    38 	if (!aSrc)
    55    * @param aSrc is char* which is to be converted to HBufC8
    57    * @param aSrc is char* which is to be converted to HBufC8
    56    * @param aDes is the pointer to the descriptor of type HBufC8 which will hold
    58    * @param aDes is the pointer to the descriptor of type HBufC8 which will hold
    57    * the result of conversion.aDes needs to be allocated with sufficient amount 
    59    * the result of conversion.aDes needs to be allocated with sufficient amount 
    58    * of memory before being passed to function. This Descriptor should have 
    60    * of memory before being passed to function. This Descriptor should have 
    59    * a allocation that is equal to or greater than char*
    61    * a allocation that is equal to or greater than char*
       
    62    *
       
    63    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer, -6 is EUseNewMaxL)
    60    */
    64    */
    61    
    65    
    62 EXPORT_C int CharToHbufc8(const char* aSrc, HBufC8* aDes)
    66 EXPORT_C int CharToHbufc8(const char* aSrc, HBufC8* aDes)
    63 {
    67 {
    64     unsigned int ilendes = 0;
    68     unsigned int ilendes = 0;
    89    * @param aSrc is char* which is to be converted to TPtr8
    93    * @param aSrc is char* which is to be converted to TPtr8
    90    * @param aDes is the pointer to the descriptor of type TPtr8 which will hold
    94    * @param aDes is the pointer to the descriptor of type TPtr8 which will hold
    91    * the result of conversion.aDes needs to be allocated with sufficient amount 
    95    * the result of conversion.aDes needs to be allocated with sufficient amount 
    92    * of memory before being passed to function. This Descriptor should have 
    96    * of memory before being passed to function. This Descriptor should have 
    93    * a allocation that is equal to or greater than char*
    97    * a allocation that is equal to or greater than char*
       
    98    *
       
    99    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer)
    94    */
   100    */
    95    
   101    
    96 EXPORT_C int CharpToTptr8( const char* aSrc, TPtr8& aDes )
   102 EXPORT_C int CharpToTptr8( const char* aSrc, TPtr8& aDes )
    97 {
   103 {
    98     unsigned int ilen = 0, ilendes = 0;
   104     unsigned int ilen = 0, ilendes = 0;
   119    * @param aSrc is char* which is to be converted to TPtrc8
   125    * @param aSrc is char* which is to be converted to TPtrc8
   120    * @param aDes is the pointer to the descriptor of type TPtrc8 which will hold
   126    * @param aDes is the pointer to the descriptor of type TPtrc8 which will hold
   121    * the result of conversion.aDes needs to be allocated with sufficient amount 
   127    * the result of conversion.aDes needs to be allocated with sufficient amount 
   122    * of memory before being passed to function. This Descriptor should have 
   128    * of memory before being passed to function. This Descriptor should have 
   123    * a allocation that is equal to or greater than char*
   129    * a allocation that is equal to or greater than char*
       
   130    *
       
   131    * @return Status code (0 is ESuccess, -4 is EInvalidPointer)  
   124    */
   132    */
   125    
   133    
   126 EXPORT_C int CharpToTptrc8(const char* aSrc, TPtrC8& aDes)
   134 EXPORT_C int CharpToTptrc8(const char* aSrc, TPtrC8& aDes)
   127 {    
   135 {    
   128 	if ( !aSrc )
   136 	if ( !aSrc )
   140    * @param aSrc is char* which is to be converted to RBuf8
   148    * @param aSrc is char* which is to be converted to RBuf8
   141    * @param aDes is the pointer to the descriptor of type RBuf8 which will hold
   149    * @param aDes is the pointer to the descriptor of type RBuf8 which will hold
   142    * the result of conversion.aDes needs to be allocated with sufficient amount 
   150    * the result of conversion.aDes needs to be allocated with sufficient amount 
   143    * of memory before being passed to function. This Descriptor should have 
   151    * of memory before being passed to function. This Descriptor should have 
   144    * a allocation that is equal to or greater than char*
   152    * a allocation that is equal to or greater than char*
       
   153    *
       
   154    * @return Status code (0 is ESuccess, -1 is EInsufficientMemory, -4 is EInvalidPointer)
   145    */
   155    */
   146 
   156 
   147 EXPORT_C int CharToRbuf8(const char* aSrc, RBuf8& aDes)
   157 EXPORT_C int CharToRbuf8(const char* aSrc, RBuf8& aDes)
   148 {   
   158 {    
   149     int retval = ESuccess, ilen = 0;
   159   if ( !aSrc )
   150     
   160   {
   151     if ( !aSrc )
   161     return EInvalidPointer;
   152     {
   162   }
   153     	return EInvalidPointer;
   163         
   154     }
   164   aDes.Copy((const unsigned char *)aSrc, strlen(aSrc));
   155     
       
   156     ilen = strlen(aSrc);
       
   157     
       
   158     if (KErrNone == aDes.Create(ilen))
       
   159     {
       
   160     	aDes.Copy((const unsigned char *)aSrc, ilen);
       
   161     }
       
   162 	else
       
   163 	{
       
   164 		retval = EInsufficientSystemMemory;
       
   165 	}
       
   166 	
   165 	
   167 	return retval;	
   166 	return ESuccess;	
   168 }
   167 }
       
   168