diff options
| author | Jakob Kaivo <jkk@ung.org> | 2019-02-08 18:42:39 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2019-02-08 18:42:39 -0500 |
| commit | 7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch) | |
| tree | 092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src/wctype | |
| parent | 6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff) | |
merge sources into single tree
Diffstat (limited to 'src/wctype')
| -rw-r--r-- | src/wctype/WEOF.c | 6 | ||||
| -rw-r--r-- | src/wctype/iswalnum.c | 28 | ||||
| -rw-r--r-- | src/wctype/iswalpha.c | 28 | ||||
| -rw-r--r-- | src/wctype/iswblank.c | 27 | ||||
| -rw-r--r-- | src/wctype/iswcntrl.c | 28 | ||||
| -rw-r--r-- | src/wctype/iswctype.c | 32 | ||||
| -rw-r--r-- | src/wctype/iswdigit.c | 28 | ||||
| -rw-r--r-- | src/wctype/iswgraph.c | 28 | ||||
| -rw-r--r-- | src/wctype/iswlower.c | 28 | ||||
| -rw-r--r-- | src/wctype/iswprint.c | 28 | ||||
| -rw-r--r-- | src/wctype/iswpunct.c | 28 | ||||
| -rw-r--r-- | src/wctype/iswspace.c | 28 | ||||
| -rw-r--r-- | src/wctype/iswupper.c | 29 | ||||
| -rw-r--r-- | src/wctype/iswxdigit.c | 28 | ||||
| -rw-r--r-- | src/wctype/towctrans.c | 30 | ||||
| -rw-r--r-- | src/wctype/towlower.c | 33 | ||||
| -rw-r--r-- | src/wctype/towupper.c | 32 | ||||
| -rw-r--r-- | src/wctype/wctrans.c | 38 | ||||
| -rw-r--r-- | src/wctype/wctrans_t.c | 6 | ||||
| -rw-r--r-- | src/wctype/wctype.c | 57 | ||||
| -rw-r--r-- | src/wctype/wctype_t.c | 6 | ||||
| -rw-r--r-- | src/wctype/wint_t.c | 6 |
22 files changed, 582 insertions, 0 deletions
diff --git a/src/wctype/WEOF.c b/src/wctype/WEOF.c new file mode 100644 index 00000000..021fed95 --- /dev/null +++ b/src/wctype/WEOF.c @@ -0,0 +1,6 @@ +#include <wctype.h> +#define WEOF ((wint_t)(-1)) + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswalnum.c b/src/wctype/iswalnum.c new file mode 100644 index 00000000..dafc242e --- /dev/null +++ b/src/wctype/iswalnum.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "wchar.h" + +/** test whether a wide character is alphanumeric **/ +int iswalnum(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + return iswalpha(wc) || iswdigit(wc); +} + +/*** +The fn(iswalnum) function tests whether arg(wc) is a wide character in the class +cclass(alpha) or cclass(digit) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is an alphanumeric character */ +/* RETURN(0): arg(wc) is not an alphanumeric character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswalpha.c b/src/wctype/iswalpha.c new file mode 100644 index 00000000..6fcc275f --- /dev/null +++ b/src/wctype/iswalpha.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is alphabetic **/ +int iswalpha(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t alpha = wctype("alpha"); + return iswctype(wc, alpha); +} + +/*** +The fn(iswalpha) function tests whether arg(wc) is a wide character in the class +cclass(alpha) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is an alphabetic character */ +/* RETURN(0): arg(wc) is not an alphabetic character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswblank.c b/src/wctype/iswblank.c new file mode 100644 index 00000000..b6a44d3c --- /dev/null +++ b/src/wctype/iswblank.c @@ -0,0 +1,27 @@ +#include <wctype.h> +#include "nonstd/assert.h" + +/** test whether a wide character is blank **/ +int iswblank(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t blank = wctype("blank"); + return iswctype(wc, blank); +} + +/*** +The fn(iswblank) functions tests whether a wide character is a of the character +class cclass(blank) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a blank character */ +/* RETURN(0): arg(wc) is not a blank character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199901) +*/ diff --git a/src/wctype/iswcntrl.c b/src/wctype/iswcntrl.c new file mode 100644 index 00000000..7859148a --- /dev/null +++ b/src/wctype/iswcntrl.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is a control character */ +int iswcntrl(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t cntrl = wctype("cntrl"); + return iswctype(wc, cntrl); +} + +/*** +The fn(iswcntrl) function tests whether arg(wc) is a wide character in the class +cclass(cntrl) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a control character */ +/* RETURN(0): arg(wc) is not a control character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswctype.c b/src/wctype/iswctype.c new file mode 100644 index 00000000..fd24051a --- /dev/null +++ b/src/wctype/iswctype.c @@ -0,0 +1,32 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is part of a character class **/ +int iswctype(wint_t wc, wctype_t desc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + ASSERT_REPRESENTABLE(desc, 1, __libc.wctype.nwctype, "wctype_t", 0); + + /* TODO: actual work */ + (void)wc; (void)desc; + + return 0; +} + +/*** +The fn(iswctype) function tests whether arg(wc) is a wide character in the +character class represented by arg(desc), which must have been previously +returned by fn(wctype), in the current locale. +***/ + +/* RETURN(0): arg(wc) is not in the character class represented by arg(desc) */ +/* RETURN(NZ): arg(wc) is in the character class represented by arg(desc) */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswdigit.c b/src/wctype/iswdigit.c new file mode 100644 index 00000000..1ccdf84d --- /dev/null +++ b/src/wctype/iswdigit.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is a digit **/ +int iswdigit(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t digit = wctype("digit"); + return iswctype(wc, digit); +} + +/*** +The fn(iswdigit) function tests whether arg(wc) is a wide character in the class +cclass(digit) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a digit */ +/* RETURN(0): arg(wc) is not a digit */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswgraph.c b/src/wctype/iswgraph.c new file mode 100644 index 00000000..f20ad02c --- /dev/null +++ b/src/wctype/iswgraph.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is graphic **/ +int iswgraph(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t graph = wctype("graph"); + return iswctype(wc, graph); +} + +/*** +The fn(iswgraph) function tests whether arg(wc) is a wide character in the class +cclass(graph) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a graphic character */ +/* RETURN(0): arg(wc) is not a graphic character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswlower.c b/src/wctype/iswlower.c new file mode 100644 index 00000000..739c36e8 --- /dev/null +++ b/src/wctype/iswlower.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a character is a lowercase letter **/ +int iswlower(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t lower = wctype("lower"); + return iswctype(wc, lower); +} + +/*** +The fn(iswlower) function tests whether arg(wc) is a wide character in the class +cclass(lower) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a lowercase letter */ +/* RETURN(0): arg(wc) is not a lowercase letter */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswprint.c b/src/wctype/iswprint.c new file mode 100644 index 00000000..11bf9033 --- /dev/null +++ b/src/wctype/iswprint.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is printable **/ +int iswprint(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t print = wctype("print"); + return iswctype(wc, print); +} + +/*** +The fn(iswprint) function tests whether arg(wc) is a character in the class +cclass(print) in the current locale. +***/ + +/* RETURN(NZ): arg(c) is a printable character */ +/* RETURN(0): arg(c) is not a printable character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswpunct.c b/src/wctype/iswpunct.c new file mode 100644 index 00000000..5ffdbe85 --- /dev/null +++ b/src/wctype/iswpunct.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is punctuation **/ +int iswpunct(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t punct = wctype("punct"); + return iswctype(wc, punct); +} + +/*** +The fn(iswpunct) function tests whether arg(wc) is a character in the class +cclass(punct) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a punctuation character */ +/* RETURN(0): arg(wc) is not a punctuation character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswspace.c b/src/wctype/iswspace.c new file mode 100644 index 00000000..60bf723a --- /dev/null +++ b/src/wctype/iswspace.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is white-space **/ +int iswspace(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t space = wctype("space"); + return iswctype(wc, space); +} + +/*** +The fn(iswspace) function tests whether arg(wc) is a wide character in the class +cclass(space) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a white-space character */ +/* RETURN(0): arg(wc) is not a white-space character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswupper.c b/src/wctype/iswupper.c new file mode 100644 index 00000000..27fe2359 --- /dev/null +++ b/src/wctype/iswupper.c @@ -0,0 +1,29 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is an uppercase letter **/ +int iswupper(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t upper = wctype("upper"); + return iswctype(wc, upper); +} + +/*** +The fn(iswupper) function tests whether arg(wc) is a wide character in the class +cclass(upper) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is an uppercase letter */ +/* RETURN(0): arg(wc) is not an uppercase letter */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + + +/* +STDC(199409) +*/ diff --git a/src/wctype/iswxdigit.c b/src/wctype/iswxdigit.c new file mode 100644 index 00000000..b544b285 --- /dev/null +++ b/src/wctype/iswxdigit.c @@ -0,0 +1,28 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** test whether a wide character is a hexadecimal digit **/ +int iswxdigit(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + wctype_t xdigit = wctype("xdigit"); + return iswctype(wc, xdigit); +} + +/*** +The fn(iswxdigit) function tests whether arg(wc) is a wide character in the +class cclass(xdigit) in the current locale. +***/ + +/* RETURN(NZ): arg(wc) is a hexadecimal digit */ +/* RETURN(0): arg(wc) is not a hexadecimal digit */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/towctrans.c b/src/wctype/towctrans.c new file mode 100644 index 00000000..9ea0c8a6 --- /dev/null +++ b/src/wctype/towctrans.c @@ -0,0 +1,30 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +wint_t towctrans(wint_t wc, wctrans_t desc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + ASSERT_REPRESENTABLE(desc, 1, __libc.wctype.nwctrans, "wctrans_t", 0); + + /* TODO: actual work */ + (void)wc; (void)desc; + + return 0; +} + +/*** +The fn(towctrans) function translates the wide character arg(wc) according to +mapping described by arg(desc), which must come from a previous call to +fn(wctrans), in the current locale. +***/ + +/* RETURN: the translated wide character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/towlower.c b/src/wctype/towlower.c new file mode 100644 index 00000000..8e5254d8 --- /dev/null +++ b/src/wctype/towlower.c @@ -0,0 +1,33 @@ +#include <wctype.h> +#include "wchar.h" +#include "stdlib.h" +#include "nonstd/assert.h" + +/** convert a wide uppercase letter to lowercase **/ +wint_t towlower(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + if (!iswupper(wc)) { + return wc; + } + + wctrans_t trans = wctrans("tolower"); + return towctrans(wc, trans); +} + +/*** +The fn(towlower) function converts a wide uppercase letter to its equivalent +lowercase letter in the current locale. +***/ + +/* RETURN(arg(c)): arg(wc) was not a wide uppercase letter or it has no equivalent lowercase letter */ +/* RETURN: arg(wc) converted to lowercase */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/towupper.c b/src/wctype/towupper.c new file mode 100644 index 00000000..1310e109 --- /dev/null +++ b/src/wctype/towupper.c @@ -0,0 +1,32 @@ +#include <wctype.h> +#include "wchar.h" +#include "nonstd/assert.h" + +/** convert a wide lowercase letter to uppercase **/ +wint_t towupper(wint_t wc) +{ + ASSERT_REPRESENTABLE(wc, WCHAR_MIN, WCHAR_MAX, "wchar_t", WEOF); + + if (!iswlower(wc)) { + return wc; + } + + wctrans_t trans = wctrans("toupper"); + return towctrans(wc, trans); +} + +/*** +The fn(towupper) function converts a wide lowercase letter to its equivalent +uppercase letter in the current locale. +***/ + +/* RETURN(arg(c)): arg(wc) was not a wide lowercase letter or it has no equivalent upercase letter */ +/* RETURN: arg(c) converted to uppercase */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/wctrans.c b/src/wctype/wctrans.c new file mode 100644 index 00000000..54a6e211 --- /dev/null +++ b/src/wctype/wctrans.c @@ -0,0 +1,38 @@ +#include <wctype.h> +#include "string.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" + +/** lookup character translation **/ +wctrans_t wctrans(const char * property) +{ + ASSERT_NONNULL(property); + + if (!strcmp(property, "tolower")) { + return LOWER; + } else if (!strcmp(property, "toupper")) { + return UPPER; + } + + return 0; +} + +/*** +The fn(wctrans) function looks up the wide character translation mapping +specified by the string arg(property), to be used as the arg(desc) parameter +to fn(towctrans). + +At least the following mappings are supported: ctrans(tolower) and +ctrans(toupper). +***/ + +/* RETURN(0): arg(property) is not a recognized translation */ +/* RETURN(NZ): a mapping identifier to be used as the arg(desc) parameter to fn(towctrans) */ + +/* UNSPECIFED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/wctrans_t.c b/src/wctype/wctrans_t.c new file mode 100644 index 00000000..f11d5863 --- /dev/null +++ b/src/wctype/wctrans_t.c @@ -0,0 +1,6 @@ +#include <wctype.h> +typedef int wctrans_t; + +/* +STDC(199409) +*/ diff --git a/src/wctype/wctype.c b/src/wctype/wctype.c new file mode 100644 index 00000000..1b27af1d --- /dev/null +++ b/src/wctype/wctype.c @@ -0,0 +1,57 @@ +#include <wctype.h> +#include "string.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" + +/** lookup character class **/ +wctype_t wctype(const char * property) +{ + ASSERT_NONNULL(property); + + if (!strcmp(property, "alnum")) { + return ALPHA | DIGIT; + } else if (!strcmp(property, "alpha")) { + return ALPHA; + } else if (!strcmp(property, "cntrl")) { + return CNTRL; + } else if (!strcmp(property, "digit")) { + return DIGIT; + } else if (!strcmp(property, "graph")) { + return GRAPH; + } else if (!strcmp(property, "lower")) { + return LOWER; + } else if (!strcmp(property, "print")) { + return PRINT; + } else if (!strcmp(property, "punct")) { + return PUNCT; + } else if (!strcmp(property, "space")) { + return SPACE; + } else if (!strcmp(property, "upper")) { + return UPPER; + } else if (!strcmp(property, "xdigit")) { + return XDIGIT; + } + + return 0; +} + +/*** +The fn(wctype) function looks up the character class specified by the string +arg(property). If arg(property) is a recognized character class, a value is +returned that can be used as the arg(desc) parameter to fn(iswctype). + +At least the following character classes are recognized: cclass(alnum), +cclass(alpha), cclass(cntrl), cclass(digit), cclass(graph), cclass(lower), +cclass(print), cclass(punct), cclass(space), cclass(upper), and cclass(xdigit). +***/ + +/* RETURN(0): the requested character class is not recognized */ +/* RETURN(NZ): a value usable as the arg(desc) parameter to fn(iswctype) */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199409) +*/ diff --git a/src/wctype/wctype_t.c b/src/wctype/wctype_t.c new file mode 100644 index 00000000..6406fc3c --- /dev/null +++ b/src/wctype/wctype_t.c @@ -0,0 +1,6 @@ +#incude <wctype.h> +typedef int wctype_t; + +/* +STDC(199409) +*/ diff --git a/src/wctype/wint_t.c b/src/wctype/wint_t.c new file mode 100644 index 00000000..ba069f94 --- /dev/null +++ b/src/wctype/wint_t.c @@ -0,0 +1,6 @@ +#include <wctype.h> +typedef int wint_t; + +/* +STDC(199409) +*/ |
