1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

Implement few wide char functions.

This commit is contained in:
Sebastian Bauer
2018-03-28 17:09:18 +02:00
parent 846eebc66c
commit 6f3b3b6d28
14 changed files with 59 additions and 28 deletions

View File

@ -40,6 +40,6 @@
int int
wcscmp(const wchar_t *s1, const wchar_t * s2) wcscmp(const wchar_t *s1, const wchar_t * s2)
{ {
/* ZZZ unimplemented */ for (; *s1==*s2 && *s1 && *s2; s1++, s2++);
return(0); return *s1 - *s2;
} }

View File

@ -40,6 +40,7 @@
wchar_t * wchar_t *
wcscpy(wchar_t *dest, const wchar_t *src) wcscpy(wchar_t *dest, const wchar_t *src)
{ {
/* ZZZ unimplemented */ wchar_t *a = dest;
return(NULL); while ((*dest++ = *src++));
return a;
} }

View File

@ -37,9 +37,12 @@
/****************************************************************************/ /****************************************************************************/
/* Implementation based on musl */
size_t size_t
wcslen(const wchar_t *s) wcslen(const wchar_t *s)
{ {
/* ZZZ unimplemented */ const wchar_t *a;
return(0); for (a=s; *s; s++);
return s-a;
} }

View File

@ -37,9 +37,14 @@
/****************************************************************************/ /****************************************************************************/
/* Implementation based on musl */
wchar_t * wchar_t *
wcsncat(wchar_t *dest, const wchar_t *src, size_t n) wcsncat(wchar_t *dest, const wchar_t *src, size_t n)
{ {
/* ZZZ unimplemented */ wchar_t *a = dest;
return(NULL); dest += wcslen(dest);
while (n && *src) n--, *dest++ = *src++;
*dest++ = 0;
return a;
} }

View File

@ -40,6 +40,6 @@
int int
wctob(wint_t c) wctob(wint_t c)
{ {
/* ZZZ unimplemented */ if (c < 128U) return c;
return(0); return EOF;
} }

View File

@ -37,9 +37,11 @@
/****************************************************************************/ /****************************************************************************/
/* Implementation based on musl */
wchar_t * wchar_t *
wmemchr(const wchar_t *ptr, wchar_t val, size_t len) wmemchr(const wchar_t *ptr, wchar_t val, size_t len)
{ {
/* ZZZ unimplemented */ for (; len && *ptr != val; len--, ptr++);
return(NULL); return len ? (wchar_t *)ptr : 0;
} }

View File

@ -37,9 +37,11 @@
/****************************************************************************/ /****************************************************************************/
/* Implementation based on musl */
int int
wmemcmp(const wchar_t *ptr1, const wchar_t *ptr2, size_t len) wmemcmp(const wchar_t *ptr1, const wchar_t *ptr2, size_t len)
{ {
/* ZZZ unimplemented */ for (; len && *ptr1==*ptr2; len--, ptr1++, ptr2++);
return(0); return len ? *ptr1-*ptr2 : 0;
} }

View File

@ -37,9 +37,12 @@
/****************************************************************************/ /****************************************************************************/
/* Implementation based on musl */
wchar_t * wchar_t *
wmemcpy(wchar_t *dest, const wchar_t *src, size_t len) wmemcpy(wchar_t *dest, const wchar_t *src, size_t len)
{ {
/* ZZZ unimplemented */ wchar_t *a = dest;
return(NULL); while (len--) *dest++ = *src++;
return a;
} }

View File

@ -37,9 +37,15 @@
/****************************************************************************/ /****************************************************************************/
/* Implementation based on musl */
wchar_t * wchar_t *
wmemmove(wchar_t *dest, const wchar_t * src, size_t len) wmemmove(wchar_t *dest, const wchar_t * src, size_t len)
{ {
/* ZZZ unimplemented */ wchar_t *d0 = dest;
return(NULL); if ((size_t)(dest-src) < len)
while (len--) dest[len] = src[len];
else
while (len--) *dest++ = *src++;
return d0;
} }

View File

@ -37,9 +37,12 @@
/****************************************************************************/ /****************************************************************************/
/* Implementation based on musl */
wchar_t * wchar_t *
wmemset(wchar_t *ptr, int val, size_t len) wmemset(wchar_t *ptr, int val, size_t len)
{ {
/* ZZZ unimplemented */ wchar_t *ret = ptr;
return(NULL); while (len--) *ptr++ = val;
return ret;
} }

View File

@ -37,9 +37,10 @@
/****************************************************************************/ /****************************************************************************/
/* Implementation based on musl */
int int
iswalnum(wint_t c) iswalnum(wint_t c)
{ {
/* ZZZ unimplemented */ return iswdigit(c) || iswalpha(c);
return(0);
} }

View File

@ -35,11 +35,12 @@
#include <wctype.h> #include <wctype.h>
#endif /* _WCTYPE_HEADERS_H */ #endif /* _WCTYPE_HEADERS_H */
#include <ctype.h>
/****************************************************************************/ /****************************************************************************/
int int
iswalpha(wint_t c) iswalpha(wint_t c)
{ {
/* ZZZ unimplemented */ return isalpha(c);
return(0);
} }

View File

@ -35,11 +35,14 @@
#include <wctype.h> #include <wctype.h>
#endif /* _WCTYPE_HEADERS_H */ #endif /* _WCTYPE_HEADERS_H */
#include <ctype.h>
/****************************************************************************/ /****************************************************************************/
/* Implementation based on musl */
int int
iswblank(wint_t c) iswblank(wint_t c)
{ {
/* ZZZ unimplemented */ return isblank(c);
return(0);
} }

View File

@ -35,11 +35,12 @@
#include <wctype.h> #include <wctype.h>
#endif /* _WCTYPE_HEADERS_H */ #endif /* _WCTYPE_HEADERS_H */
#include <ctype.h>
/****************************************************************************/ /****************************************************************************/
int int
iswdigit(wint_t c) iswdigit(wint_t c)
{ {
/* ZZZ unimplemented */ return isdigit(c);
return(0);
} }