Diffstat (limited to 'noncore/apps/opie-reader/ustring.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/ustring.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/ustring.h b/noncore/apps/opie-reader/ustring.h new file mode 100644 index 0000000..a4dc048 --- a/dev/null +++ b/noncore/apps/opie-reader/ustring.h | |||
@@ -0,0 +1,71 @@ | |||
1 | #include <qstring.h> | ||
2 | |||
3 | #ifdef _UNICODE | ||
4 | inline size_t ustrlen(const tchar* _p) | ||
5 | { | ||
6 | if (_p == NULL) return 0; | ||
7 | const tchar *p = _p; | ||
8 | while (*p != 0) | ||
9 | { | ||
10 | p++; | ||
11 | /* | ||
12 | if (p - _p == 20) | ||
13 | { | ||
14 | printf("ustrlen::String too long:"); | ||
15 | for (int i = 0; i < 20; i++) printf("%c",_p[i]); | ||
16 | printf("\n"); | ||
17 | } | ||
18 | */ | ||
19 | } | ||
20 | return p - _p; | ||
21 | } | ||
22 | |||
23 | inline int ustrcmp(const tchar* _p1, const tchar* _p2) | ||
24 | { | ||
25 | if (_p1 == 0) return 1; | ||
26 | if (_p2 == 0) return -1; | ||
27 | const tchar* p1 = _p1, *p2 = _p2; | ||
28 | while (*p1 != 0) | ||
29 | { | ||
30 | /* | ||
31 | if (p1 - _p1 == 20) | ||
32 | { | ||
33 | printf("ustrcmp::String too long:"); | ||
34 | for (int i = 0; i < 20; i++) printf("%c",_p1[i]); | ||
35 | printf("\n"); | ||
36 | } | ||
37 | */ | ||
38 | if (*p1 < *p2) return -1; | ||
39 | if (*p1 > *p2) return 1; | ||
40 | if (*p2 == 0) return 1; | ||
41 | p1++, p2++; | ||
42 | } | ||
43 | if (*p2 != 0) return -1; | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | inline QString toQString(tchar *_p) | ||
48 | { | ||
49 | if (_p == NULL) return 0; | ||
50 | int i = 0; | ||
51 | tchar *p = _p; | ||
52 | QString ret; | ||
53 | while (*p != 0) ret[i++] = *(p++); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | inline QString toQString(tchar *_p, unsigned int len) | ||
58 | { | ||
59 | if (_p == NULL) return 0; | ||
60 | unsigned int i = 0; | ||
61 | tchar *p = _p; | ||
62 | QString ret; | ||
63 | while (*p != 0 && i < len) ret[i++] = *(p++); | ||
64 | return ret; | ||
65 | } | ||
66 | #else | ||
67 | |||
68 | inline size_t ustrlen(const tchar* _p) { return strlen(_p); } | ||
69 | inline int ustrcmp(const tchar* _p1, const tchar* _p2) { return strcmp(_p1, _p2); } | ||
70 | |||
71 | #endif | ||