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