[tyndur-devel] [PATCH] libc: wctype_t, iswctype, btowc
hartmut at tyndur.org ·
From: Alexander Hartmut Kluth <hartmut at tyndur.org> wctype_t und Konsorten implementiert + Typ wctype_t hinzugefuegt + Funktion iswctype hinzugefuegt + Funktion btowc als Stub hinzugefuegt Signed-off-by: Alexander Hartmut Kluth <hartmut at tyndur.org> --- src/include/wctype.h | 7 +++ src/modules/include/wchar.h | 7 +++ src/modules/lib/stdlibc/wctype.c | 77 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 0 deletions(-) diff --git a/src/include/wctype.h b/src/include/wctype.h index f273a71..30e47c6 100644 --- a/src/include/wctype.h +++ b/src/include/wctype.h @@ -120,6 +120,12 @@ int iswprint(wint_t wc); int iswcntrl(wint_t wc); +int iswgraph(wint_t c); + + +int iswxdigit(wint_t c); + + /** * Breites Zeichen in einen Grossbuchstaben umwandeln, falls es sich um einen * Kleinbuchstaben handelt. Sonst wird das Zeichen unveraendert zurueckgegeben. @@ -139,5 +145,6 @@ wint_t towupper(wint_t wc); */ wint_t towlower(wint_t wc); + #endif /* ndef WCTYPE_H */ diff --git a/src/modules/include/wchar.h b/src/modules/include/wchar.h index 3870f9d..d39c632 100644 --- a/src/modules/include/wchar.h +++ b/src/modules/include/wchar.h @@ -40,6 +40,13 @@ */ typedef wchar_t wint_t; + +/** + * wctype_t ist ein Funktionspointer + */ +typedef int (*wctype_t)(wint_t); + + /** * Repraesentiert den internen Shift-Status einer Funktion, brauchen wir mit * UTF-8 nicht. diff --git a/src/modules/lib/stdlibc/wctype.c b/src/modules/lib/stdlibc/wctype.c index b3c174c..b3c689c 100644 --- a/src/modules/lib/stdlibc/wctype.c +++ b/src/modules/lib/stdlibc/wctype.c @@ -27,6 +27,81 @@ */ #include <wctype.h> +#include <string.h> + + +struct { const char* name; wctype_t func; } types[] = { + { "alnum", iswalnum }, + { "alpha", iswalpha }, + { "blank", iswblank }, + { "cntrl", iswcntrl }, + { "digit", iswdigit }, + { "graph", iswgraph }, + { "lower", iswlower }, + { "print", iswprint }, + { "punct", iswpunct }, + { "space", iswspace }, + { "upper", iswupper }, + { "xdigit", iswxdigit }, +}; + + +/** + * Erstellt ein wctype-Objekt + * + * @param type Typ des zu erstellenden Objekts + * + * @return Das Objekt, ansonsten (wctype_t)0 + */ +wctype_t wctype(const char* name) +{ + int i; + + for (i = 0; i < sizeof(types) / sizeof(types[0]); ++i) + { + if (!strcmp(name,types[i].name)) { + return types[i].func; + } + } + + return (wctype_t)0; +} + + +/** + * Prüft, ob der als Parameter übergebene Typ auch vom Typ + * wctype_t ist + * + * @param wc Ãbergebener Typ + * @param type Typklasse + * + * @return 0, wenn die Klasse nicht vorhanden ist, ansonsten den + * Funktionspointer + */ +int iswctype(wint_t wc, wctype_t type) +{ + return type(wc); +} + + +/// TODO +wint_t btowc(wint_t c) +{ + return 0; +} + + +int iswgraph(wint_t c) +{ + return 0; +} + + +int iswxdigit(wint_t c) +{ + return 0; +} + /** * Testet ob es sich bei einem breiten Zeichen um ein grosses alphabetisches @@ -170,3 +245,5 @@ wint_t towlower(wint_t wc) return iswupper(wc) ? wc + (L'a' - L'A') : wc; } + + -- 1.6.0.4