Nokia N97 SDK
Example Applications Guide

stringutils.h File Reference


Detailed Description

stringutils is a DLL that exports some set of genaralized APIs using which user can convert the SYMBIAN descriptors to standard C character/wide-character strings and vice-versa

Definition in file stringutils.h.

#include <e32cmn.h>
#include <wchar.h>

Go to the source code of this file.


Defines

#define  hbufC16towchar   tbufC16towchar
#define  hbufC16tochar   tbufC16tochar
#define  hbufC8towchar   tbufC8towchar
#define  hbufC8tochar   tbufC8tochar

Functions

IMPORT_C wchar_t *  tbuf16towchar (TDes &aArg)
IMPORT_C char *  tbuf8tochar (TDes8 &aArg)
IMPORT_C int  tbuf16tochar (TDes &aSrc, char *aDes)
IMPORT_C int  tbuf8towchar (TDes8 &aSrc, wchar_t *aDes)
IMPORT_C void  tbufC16towchar (TDesC &aSrc, wchar_t *aDes)
IMPORT_C void  tbufC8tochar (TDesC8 &aSrc, char *aDes)
IMPORT_C int  tbufC16tochar (TDesC &aSrc, char *aDes)
IMPORT_C int  tbufC8towchar (TDesC8 &aSrc, wchar_t *aDes)
IMPORT_C void  wchartotbuf16 (const wchar_t *aSrc, TDes16 &aDes)
IMPORT_C int  chartotbuf16 (const char *aSrc, TDes16 &aDes)
IMPORT_C int  wchartotbuf8 (const wchar_t *aSrc, TDes8 &aDes)
IMPORT_C void  chartotbuf8 (const char *aSrc, TDes8 &aDes)
IMPORT_C void  wchartohbufc16 (const wchar_t *aSrc, HBufC16 &aDes)
IMPORT_C int  chartohbufc16 (const char *aSrc, HBufC16 &aDes)
IMPORT_C int  wchartohbufc8 (const wchar_t *aSrc, HBufC8 &aDes)
IMPORT_C void  chartohbufc8 (const char *aSrc, HBufC8 &aDes)


Define Documentation

#define hbufC16towchar   tbufC16towchar
 

Alias to the function tbufC16towchar

Definition at line 40 of file stringutils.h.

#define hbufC16tochar   tbufC16tochar
 

Alias to the function tbufC16tochar

Definition at line 44 of file stringutils.h.

#define hbufC8towchar   tbufC8towchar
 

Alias to the function tbufC8towchar

Definition at line 48 of file stringutils.h.

#define hbufC8tochar   tbufC8tochar
 

Alias to the function tbufC8tochar

Definition at line 52 of file stringutils.h.


Function Documentation

IMPORT_C wchar_t* tbuf16towchar (  TDes &  aArg  ) 
 

This Api converts the tbuf16 to a wide-character string

Parameters:
aArg  TDes object
Returns:
a pointer to a wide-character string

Definition at line 29 of file stringutils.cpp.

References tbuf16towchar().

Referenced by tbuf16towchar().

00030 {
00031         return (wchar_t*)aArg.PtrZ();
00032 }

IMPORT_C char* tbuf8tochar (  TDes8 &  aArg  ) 
 

This Api converts the tbuf8 to a character string

Parameters:
aArg  TDes8 object
Returns:
a pointer to a character string

Definition at line 34 of file stringutils.cpp.

References tbuf8tochar().

Referenced by tbuf8tochar().

00035 {
00036         return (char*)aArg.PtrZ();
00037 }

IMPORT_C int tbuf16tochar (  TDes &  aSrc,
char *  aDes
) 
 

This Api converts the tbuf16 to a character string. It is user responsibality to allocate a required size of char object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  TDes16 object
aDes  character pointer, to which the resultant string will be copied.
Returns:
returns an integer value.

Api returns -1 in case of any error.

Definition at line 39 of file stringutils.cpp.

References tbuf16tochar().

Referenced by tbuf16tochar().

00040 {
00041         const TUint16 *wideString = aSrc.PtrZ();
00042         
00043         TInt ret = wcstombs(aDes, (const wchar_t*)wideString, KMaxFileName );
00044         
00045         return ret;
00046 }

IMPORT_C int tbuf8towchar (  TDes8 &  aSrc,
wchar_t *  aDes
) 
 

This Api converts the tbuf8 to a wide-character string. It is user responsibality to allocate a required size of wide-char object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  TDes8 object
aDes  wide-character pointer, to which the resultant string will be copied.
Returns:
returns an integer value.

Api returns -1 in case of any error.

Definition at line 48 of file stringutils.cpp.

References tbuf8towchar().

Referenced by tbuf8towchar().

00049 {
00050         const char *charString = (const char*)aSrc.PtrZ();
00051         
00052         TInt ret = mbstowcs(aDes, charString, KMaxFileName );
00053         
00054         return ret;
00055 }

IMPORT_C void tbufC16towchar (  TDesC &  aSrc,
wchar_t *  aDes
) 
 

This Api converts the tbuf16 to a wide-character string. It is user responsibality to allocate a required size of wide-char object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  TDes16 object
aDes  wide-character pointer, to which the resultant string will be copied.
Returns:
none

Definition at line 58 of file stringutils.cpp.

References tbufC16towchar().

Referenced by tbufC16towchar().

00059 {
00060         wchar_t *temp = (wchar_t*)aSrc.Ptr();
00061         const TInt size = aSrc.Size();
00062         *(temp + size/2 ) = L'\0';
00063         wcscpy(aDes, temp);
00064 }

IMPORT_C void tbufC8tochar (  TDesC8 &  aSrc,
char *  aDes
) 
 

This Api converts the tbufC8 to a character string. It is user responsibality to allocate a required size of wide-char object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  TDesC8 object
aDes  character pointer, to which the resultant string will be copied.
Returns:
none

Definition at line 66 of file stringutils.cpp.

References tbufC8tochar().

Referenced by tbufC8tochar().

00067 {
00068         char *temp = (char*)aSrc.Ptr();
00069         const TInt size = aSrc.Length();
00070         *(temp + size) = '\0';
00071         strcpy(aDes, temp);
00072 }

IMPORT_C int tbufC16tochar (  TDesC &  aSrc,
char *  aDes
) 
 

This Api converts the TBufC16 to a character string. It is user responsibality to allocate a required size of wide-char object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  TDesC object
aDes  character pointer, to which the resultant string will be copied.
Returns:
returns an integer value.

Api returns -1 in case of any error.

Definition at line 74 of file stringutils.cpp.

References tbufC16tochar().

Referenced by tbufC16tochar().

00075 {
00076         TUint16* wideString = (TUint16*)aSrc.Ptr();
00077         const TInt size = aSrc.Length();
00078         *(wideString + size) = L'\0';
00079         
00080         
00081         TInt ret = wcstombs(aDes, (const wchar_t*)wideString, size*2 );
00082         return ret;     
00083 }

IMPORT_C int tbufC8towchar (  TDesC8 &  aSrc,
wchar_t *  aDes
) 
 

This Api converts the TBufC8 to a wide-character string. It is user responsibality to allocate a required size of wide-char object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  TDesC8 object
aDes  wide-character pointer, to which the resultant string will be copied.
Returns:
returns an integer value.

Api returns -1 in case of any error.

Definition at line 86 of file stringutils.cpp.

References tbufC8towchar().

Referenced by tbufC8towchar().

00087 {
00088         TUint8* charString = (TUint8*)aSrc.Ptr();
00089         const TInt size = aSrc.Length();
00090         *(charString + size) = '\0';
00091         
00092         TInt ret = mbstowcs(aDes, (const char*)charString, KMaxFileName );
00093         return ret;
00094 }

IMPORT_C void wchartotbuf16 (  const wchar_t *  aSrc,
TDes16 &  aDes
) 
 

This Api converts the wide-char to a TBuf16. It is user responsibality to allocate a required size of TBuf16 object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  wide-character pointer.
aDes  TBuf16 object, to which the resultant string will be copied.
Returns:
none

Definition at line 96 of file stringutils.cpp.

References wchartotbuf16().

Referenced by wchartotbuf16().

00097 {
00098         aDes = (const TUint16*)aSrc;
00099 }

IMPORT_C int chartotbuf16 (  const char *  aSrc,
TDes16 &  aDes
) 
 

This Api converts the char to a TBuf16. It is user responsibality to allocate a required size of TBuf16 object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  character pointer.
aDes  TBuf16 object, to which the resultant string will be copied.
Returns:
returns an integer value.

Api returns -1 in case of any error.

Definition at line 101 of file stringutils.cpp.

References chartotbuf16().

Referenced by chartotbuf16().

00102 {
00103         int len = strlen(aSrc);
00104         wchar_t *buf = new wchar_t[len];
00105         
00106         TInt ret = mbstowcs(buf, (const char*)aSrc, len + 1 );
00107         
00108         if( ret != -1)
00109                 aDes = (const TUint16*)buf;
00110         
00111         delete buf;
00112         return ret;
00113 }

IMPORT_C int wchartotbuf8 (  const wchar_t *  aSrc,
TDes8 &  aDes
) 
 

This Api converts the wide-char string to a TBuf8. It is user responsibality to allocate a required size of TBuf8 object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  wide-character pointer.
aDes  TBuf8 object, to which the resultant string will be copied.
Returns:
returns an integer value.

Api returns -1 in case of any error.

Definition at line 115 of file stringutils.cpp.

References wchartotbuf8().

Referenced by wchartotbuf8().

00116 {
00117         int len = wcslen(aSrc);
00118         char *buf = new char[len];
00119         
00120         TInt ret = wcstombs(buf, (const wchar_t*)aSrc, len + 1);
00121         
00122         if( ret != -1)
00123                 aDes = (const TUint8*)buf;
00124         
00125         delete buf;
00126         return ret;
00127 }

IMPORT_C void wchartohbufc16 (  const wchar_t *  aSrc,
HBufC16 &  aDes
) 
 

This Api converts the wide-char to a HBufC16. It is user responsibality to allocate a required size of HBufC16 object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  wide-character pointer.
aDes  HBufC16 object, to which the resultant string will be copied.
Returns:
none

Definition at line 134 of file stringutils.cpp.

00135 {
00136         aDes = (const TUint16*)aSrc;            
00137 }

IMPORT_C int chartohbufc16 (  const char *  aSrc,
HBufC16 &  aDes
) 
 

This Api converts the char to a HBufC16. It is user responsibality to allocate a required size of HBufC16 object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  character pointer.
aDes  HBufC16 object, to which the resultant string will be copied.
Returns:
returns an integer value.

Api returns -1 in case of any error.

Definition at line 139 of file stringutils.cpp.

References chartohbufc16().

Referenced by chartohbufc16().

00140 {       
00141         int len = strlen(aSrc);
00142         wchar_t *buf = new wchar_t[len];
00143         
00144         TInt ret = mbstowcs(buf, (const char*)aSrc, len + 1);
00145         
00146         if( ret != -1)
00147                 aDes = (const TUint16*)buf;
00148         
00149         delete buf;
00150         return ret;
00151 }

IMPORT_C int wchartohbufc8 (  const wchar_t *  aSrc,
HBufC8 &  aDes
) 
 

This Api converts the wide-char to a HBufC8. It is user responsibality to allocate a required size of HBufC8 object. Api may resulting in crash, if the destination object size is smaller than that of the source.

Parameters:
aSrc  wide-character pointer.
aDes  HBufC8 object, to which the resultant string will be copied.
Returns:
returns an integer value.

Api returns -1 in case of any error.

Definition at line 158 of file stringutils.cpp.

References wchartohbufc8().

Referenced by wchartohbufc8().

00159 {
00160         int len = wcslen(aSrc);
00161         char *buf = new char[len];
00162         
00163         TInt ret = wcstombs(buf, aSrc, len + 1 );
00164         
00165         if( ret != -1)
00166                 aDes = (const TUint8*)buf;
00167         
00168         delete buf;
00169         return ret;
00170 }


© Nokia 2009

Back to top