6 #include "base/fscapi.h"
7 #include "base/util/utils.h"
8 #include "base/util/symbianUtils.h"
10 wchar_t * wcsncpy (wchar_t *dst, const wchar_t *src, size_t count) {
11 memcpy(dst, src, count * sizeof(wchar_t));
17 tmpStr[0] = (wchar_t)c;
18 TBuf16<1> buf = (const TUint16*)tmpStr;
20 const TUint16* resStr = buf.Ptr();
26 tmpStr[0] = (wchar_t)c;
27 TBuf16<1> buf = (const TUint16*)tmpStr;
29 const TUint16* resStr = buf.Ptr();
33 size_t vsnprintf(char* s, size_t size, const char* format, PLATFORM_VA_LIST aq) {
35 TPtrC8 formatBuf((const unsigned char*)format);
39 TRAP(error, formattedBuf.CreateL(size));
40 if (error == KErrNone) {
41 TRAP(error, formattedBuf.FormatList(formatBuf, aq));
42 if (error == KErrNone) {
43 char* ptr = (char *) formattedBuf.Ptr();
44 size_t finalSize = formattedBuf.Length();
45 if (finalSize < size) {
46 memcpy(s, ptr, finalSize);
47 s[finalSize] = 0; // Symbian descriptors don't have the trailing null char
50 // In this case we truncate. We signal this by returning -1
56 // We cannot format the string. Return -1.
61 // TODO: convert to the specified encoding, assuming wc is UTF-8
62 char* toMultibyte(const WCHAR *wc, const char *encoding)
65 size_t length = wcstombs(NULL, wc, 0) + 1;
66 if(length == (size_t)-1) {
67 //LOG.error("toMultibyte: invalid string.");
70 char* ret = new char[length];
71 wcstombs(ret, wc, length);
79 // TODO: convert to UTF-8 from the specified encoding
80 WCHAR* toWideChar(const char *mb, const char *encoding)
83 size_t length = mbstowcs(NULL, mb, 0) + 1;
84 if(length == (size_t)-1) {
85 //LOG.error("toWideChar: invalid string.");
86 return wstrdup(TEXT(""));
88 WCHAR* ret = new WCHAR[length];
89 mbstowcs(ret, mb, length);
98 size_t snwprintf(WCHAR *v, size_t size, const WCHAR* format, unsigned long value) {
100 TPtrC16 formatBuf((const TUint16*)format);
104 TRAP(error, formattedBuf.CreateL(size));
105 if (error == KErrNone) {
106 TRAP(error, formattedBuf.Format(formatBuf, value));
107 if (error == KErrNone) {
108 WCHAR* ptr = (WCHAR *) formattedBuf.Ptr();
109 size_t finalSize = formattedBuf.Length() * sizeof(WCHAR);
110 if (finalSize < size) {
111 memcpy(v, ptr, finalSize);
112 v[finalSize] = 0; // Symbian descriptors don't have the trailing null char
115 // In this case we truncate. We signal this by returning -1
116 memcpy(v, ptr, size);
117 v[size] = 0; // Symbian descriptors don't have the trailing null char
122 // We cannot format the string. Return -1.
127 WCHAR *wcschr(const WCHAR *ws, WCHAR wc) {
131 WCHAR *wcsstr(WCHAR *ws1, WCHAR *ws2) {
135 WCHAR *wcstok(WCHAR *ws1, const WCHAR *ws2) {
139 WCHAR *wcsncat(WCHAR *ws1, const WCHAR *ws2, size_t n) {
143 double wcstod(const WCHAR *nptr, WCHAR **endptr) {
147 int _wtoi(const WCHAR *str) {