00001 #include <qstring.h>
00002
00003 #ifdef _UNICODE
00004 inline size_t ustrlen(const tchar* _p)
00005 {
00006 if (_p == NULL) return 0;
00007 const tchar *p = _p;
00008 while (*p != 0)
00009 {
00010 p++;
00011
00012
00013
00014
00015
00016
00017
00018
00019 }
00020 return p - _p;
00021 }
00022
00023 inline int ustrcmp(const tchar* _p1, const tchar* _p2)
00024 {
00025 if (_p1 == 0) return 1;
00026 if (_p2 == 0) return -1;
00027 const tchar* p1 = _p1, *p2 = _p2;
00028 while (*p1 != 0)
00029 {
00030
00031
00032
00033
00034
00035
00036
00037
00038 if (*p1 < *p2) return -1;
00039 if (*p1 > *p2) return 1;
00040 if (*p2 == 0) return 1;
00041 p1++, p2++;
00042 }
00043 if (*p2 != 0) return -1;
00044 return 0;
00045 }
00046
00047 inline QString toQString(tchar *_p)
00048 {
00049 if (_p == NULL) return 0;
00050 int i = 0;
00051 tchar *p = _p;
00052 QString ret;
00053 while (*p != 0) ret[i++] = *(p++);
00054 return ret;
00055 }
00056
00057 inline QString toQString(tchar *_p, unsigned int len)
00058 {
00059 if (_p == NULL) return 0;
00060 unsigned int i = 0;
00061 tchar *p = _p;
00062 QString ret;
00063 #ifdef _WINDOWS
00064
00065 for (i = 0; i < len; i++)
00066 {
00067 if (p[i] == 0) break;
00068 ret.at((uint)i) = p[i];
00069 }
00070
00071 #else
00072 while (*p != 0 && i < len) ret[i++] = *(p++);
00073 #endif
00074 return ret;
00075 }
00076
00077 inline tchar* fromQString(const QString& qs)
00078 {
00079 int len = qs.length();
00080 tchar* ret = new tchar[len+1];
00081 for (int i = 0; i < len; i++)
00082 {
00083 ret[i] = qs[i].unicode();
00084 }
00085 ret[len] = 0;
00086 return ret;
00087 }
00088 #else
00089
00090 inline size_t ustrlen(const tchar* _p) { return strlen(_p); }
00091 inline int ustrcmp(const tchar* _p1, const tchar* _p2) { return strcmp(_p1, _p2); }
00092
00093 #endif