2 * ustring.c: Unicode string routines
9 wchar_t *ustrdup(wchar_t *s
) {
12 r
= mknewa(wchar_t, 1+ustrlen(s
));
21 char *ustrtoa(wchar_t *s
, char *outbuf
, int size
) {
27 for (p
= outbuf
; *s
&& p
< outbuf
+size
; p
++,s
++)
32 outbuf
[size
-1] = '\0';
36 int ustrlen(wchar_t *s
) {
42 wchar_t *uadv(wchar_t *s
) {
43 return s
+ 1 + ustrlen(s
);
46 wchar_t *ustrcpy(wchar_t *dest
, wchar_t *source
) {
54 int ustrcmp(wchar_t *lhs
, wchar_t *rhs
) {
55 if (!lhs
&& !rhs
) return 0;
58 while (*lhs
&& *rhs
&& *lhs
==*rhs
)
67 wchar_t utolower(wchar_t c
) {
69 return c
; /* this property needed by ustricmp */
70 /* FIXME: this doesn't even come close */
71 if (c
>= 'A' && c
<= 'Z')
76 int ustricmp(wchar_t *lhs
, wchar_t *rhs
) {
78 while ((lc
= utolower(*lhs
)) == (rc
= utolower(*rhs
)) && lc
&& rc
)
88 wchar_t *ustrlow(wchar_t *s
) {
97 int utoi(wchar_t *s
) {
107 while (*s
&& *s
>= L
'0' && *s
<= L
'9') {
116 int utob(wchar_t *s
) {
117 if (!ustricmp(s
, L
"yes") || !ustricmp(s
, L
"y") ||
118 !ustricmp(s
, L
"true") || !ustricmp(s
, L
"t"))
123 int uisdigit(wchar_t c
) {
124 return c
>= L
'0' && c
<= L
'9';
127 #define USTRFTIME_DELTA 128
128 wchar_t *ustrftime(wchar_t *wfmt
, struct tm
*timespec
) {
131 char *fmt
, *text
, *p
;
136 * strftime has the entertaining property that it returns 0
137 * _either_ on out-of-space _or_ on successful generation of
138 * the empty string. Hence we must ensure our format can never
139 * generate the empty string. Somebody throw a custard pie at
140 * whoever was responsible for that. Please?
144 fmt
= mknewa(char, 2+len
);
145 ustrtoa(wfmt
, fmt
+1, len
+1);
151 size
+= USTRFTIME_DELTA
;
152 blk
= resize((char *)blk
, size
);
153 len
= strftime((char *)blk
, size
-1, fmt
, timespec
);
158 /* Note: +1 for the terminating 0, -1 for the initial space in fmt */
159 wblk
= resize((wchar_t *)blk
, len
);
160 text
= mknewa(char, len
);
161 strftime(text
, len
, fmt
+1, timespec
);
163 * We operate in the C locale, so this all ought to be kosher
164 * ASCII. If we ever move outside ASCII machines, we may need
165 * to make this more portable...
167 for (wp
= wblk
, p
= text
; *p
; p
++, wp
++)