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 uisalpha(wchar_t c
) {
77 /* FIXME: this doesn't even come close */
78 return (c
>= 'A' && c
<= 'Z') || (c
>= 'a' && c
<= 'z');
81 int ustricmp(wchar_t *lhs
, wchar_t *rhs
) {
83 while ((lc
= utolower(*lhs
)) == (rc
= utolower(*rhs
)) && lc
&& rc
)
93 wchar_t *ustrlow(wchar_t *s
) {
102 int utoi(wchar_t *s
) {
112 while (*s
&& *s
>= L
'0' && *s
<= L
'9') {
121 int utob(wchar_t *s
) {
122 if (!ustricmp(s
, L
"yes") || !ustricmp(s
, L
"y") ||
123 !ustricmp(s
, L
"true") || !ustricmp(s
, L
"t"))
128 int uisdigit(wchar_t c
) {
129 return c
>= L
'0' && c
<= L
'9';
132 #define USTRFTIME_DELTA 128
133 wchar_t *ustrftime(wchar_t *wfmt
, struct tm
*timespec
) {
136 char *fmt
, *text
, *p
;
141 * strftime has the entertaining property that it returns 0
142 * _either_ on out-of-space _or_ on successful generation of
143 * the empty string. Hence we must ensure our format can never
144 * generate the empty string. Somebody throw a custard pie at
145 * whoever was responsible for that. Please?
149 fmt
= mknewa(char, 2+len
);
150 ustrtoa(wfmt
, fmt
+1, len
+1);
156 size
+= USTRFTIME_DELTA
;
157 blk
= resize((char *)blk
, size
);
158 len
= strftime((char *)blk
, size
-1, fmt
, timespec
);
163 /* Note: +1 for the terminating 0, -1 for the initial space in fmt */
164 wblk
= resize((wchar_t *)blk
, len
);
165 text
= mknewa(char, len
);
166 strftime(text
, len
, fmt
+1, timespec
);
168 * We operate in the C locale, so this all ought to be kosher
169 * ASCII. If we ever move outside ASCII machines, we may need
170 * to make this more portable...
172 for (wp
= wblk
, p
= text
; *p
; p
++, wp
++)