From 0d14833a9c76c51cc7417d8fd60bec9d92714b8e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 31 Jul 1999 18:44:53 +0000 Subject: Further development work. Parser nearly finished [originally from svn r187] --- ustring.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ustring.c (limited to 'ustring.c') diff --git a/ustring.c b/ustring.c new file mode 100644 index 0000000..00e26b6 --- /dev/null +++ b/ustring.c @@ -0,0 +1,47 @@ +/* + * ustring.c: Unicode string routines + */ + +#include +#include "buttress.h" + +wchar_t *ustrdup(wchar_t *s) { + wchar_t *r; + if (s) { + r = smalloc((1+ustrlen(s)) * sizeof(wchar_t)); + ustrcpy(r, s); + } else { + r = smalloc(1); + *r = 0; + } + return r; +} + +char *ustrtoa(wchar_t *s, char *outbuf, int size) { + char *p; + if (!s) { + *outbuf = '\0'; + return outbuf; + } + for (p = outbuf; *s && p < outbuf+size; p++,s++) + *p = *s; + if (p < outbuf+size) + *p = '\0'; + else + outbuf[size-1] = '\0'; + return outbuf; +} + +int ustrlen(wchar_t *s) { + int len = 0; + while (*s++) len++; + return len; +} + +wchar_t *ustrcpy(wchar_t *dest, wchar_t *source) { + wchar_t *ret = dest; + do { + *dest++ = *source; + } while (*source++); + return ret; +} -- cgit v1.1