00001 /* 00002 * ============================================================================== 00003 * Name : stringutils.cpp 00004 * Part of : OpenCStringUtilsEx 00005 * Interface : 00006 * Description : Source file for stringutils 00007 * Version : 00008 * 00009 * Copyright (c) 2005-2007 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // GCCE header 00017 //#ifdef __GCCE__ 00018 //#include <staticlibinit_gcce.h> 00019 //#endif //__GCCE__ 00020 00021 //System headers 00022 #include <string.h> 00023 #include <stdlib.h> 00024 00025 //User-definied headers 00026 #include "stringutils.h" 00027 00028 00029 EXPORT_C wchar_t* tbuf16towchar(TDes& aArg) 00030 { 00031 return (wchar_t*)aArg.PtrZ(); 00032 } 00033 00034 EXPORT_C char* tbuf8tochar(TDes8& aArg) 00035 { 00036 return (char*)aArg.PtrZ(); 00037 } 00038 00039 EXPORT_C int tbuf16tochar(TDes& aSrc, char* aDes) 00040 { 00041 const TUint16 *wideString = aSrc.PtrZ(); 00042 00043 TInt ret = wcstombs(aDes, (const wchar_t*)wideString, KMaxFileName ); 00044 00045 return ret; 00046 } 00047 00048 EXPORT_C int tbuf8towchar(TDes8& aSrc ,wchar_t* aDes) 00049 { 00050 const char *charString = (const char*)aSrc.PtrZ(); 00051 00052 TInt ret = mbstowcs(aDes, charString, KMaxFileName ); 00053 00054 return ret; 00055 } 00056 00057 00058 EXPORT_C void tbufC16towchar(TDesC& aSrc ,wchar_t *aDes) 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 } 00065 00066 EXPORT_C void tbufC8tochar(TDesC8& aSrc, char* aDes) 00067 { 00068 char *temp = (char*)aSrc.Ptr(); 00069 const TInt size = aSrc.Length(); 00070 *(temp + size) = '\0'; 00071 strcpy(aDes, temp); 00072 } 00073 00074 EXPORT_C int tbufC16tochar(TDesC& aSrc, char* aDes) 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 } 00084 00085 00086 EXPORT_C int tbufC8towchar(TDesC8& aSrc, wchar_t* aDes) 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 } 00095 00096 EXPORT_C void wchartotbuf16(const wchar_t *aSrc, TDes16 &aDes) 00097 { 00098 aDes = (const TUint16*)aSrc; 00099 } 00100 00101 EXPORT_C int chartotbuf16(const char *aSrc, TDes16 &aDes) 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 } 00114 00115 EXPORT_C int wchartotbuf8(const wchar_t *aSrc, TDes8 &aDes) 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 } 00128 00129 EXPORT_C void chartotbuf8 (const char *aSrc, TDes8 &aDes) 00130 { 00131 aDes = (const TUint8*)aSrc; 00132 } 00133 00134 EXPORT_C void wchartohbufc16 (const wchar_t* aSrc ,HBufC16& aDes ) 00135 { 00136 aDes = (const TUint16*)aSrc; 00137 } 00138 00139 EXPORT_C int chartohbufc16(const char* aSrc, HBufC16& aDes) 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 } 00152 00153 EXPORT_C void chartohbufc8(const char* aSrc, HBufC8& aDes) 00154 { 00155 aDes = (const TUint8*)aSrc; 00156 } 00157 00158 EXPORT_C int wchartohbufc8(const wchar_t* aSrc, HBufC8& aDes) 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 } 00171 00172 // End of file
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.