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/ctype | |
parent | 6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff) |
merge sources into single tree
Diffstat (limited to 'src/ctype')
-rw-r--r-- | src/ctype/isalnum.c | 23 | ||||
-rw-r--r-- | src/ctype/isalpha.c | 26 | ||||
-rw-r--r-- | src/ctype/isblank.c | 39 | ||||
-rw-r--r-- | src/ctype/iscntrl.c | 29 | ||||
-rw-r--r-- | src/ctype/isdigit.c | 26 | ||||
-rw-r--r-- | src/ctype/isgraph.c | 30 | ||||
-rw-r--r-- | src/ctype/islower.c | 30 | ||||
-rw-r--r-- | src/ctype/isprint.c | 30 | ||||
-rw-r--r-- | src/ctype/ispunct.c | 30 | ||||
-rw-r--r-- | src/ctype/isspace.c | 31 | ||||
-rw-r--r-- | src/ctype/isupper.c | 31 | ||||
-rw-r--r-- | src/ctype/isxdigit.c | 29 | ||||
-rw-r--r-- | src/ctype/tolower.c | 29 | ||||
-rw-r--r-- | src/ctype/toupper.c | 27 |
14 files changed, 410 insertions, 0 deletions
diff --git a/src/ctype/isalnum.c b/src/ctype/isalnum.c new file mode 100644 index 00000000..507655ae --- /dev/null +++ b/src/ctype/isalnum.c @@ -0,0 +1,23 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" + +/** test whether a character is alphanumeric **/ +int isalnum(int c) +{ + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is an alpanumeric character); + RETURN(0, ARGUMENT(c) is not an alphanumeric character); + */ + return isalpha(c) || isdigit(c); +} + +/*** +tests whether ARGUMENT(c) is a character in the class +CHARACTER_CLASS(alpha) or CHARACTER_CLASS(digit) in the current locale. +***/ +/* +LC_CTYPE +STDC(1) +*/ diff --git a/src/ctype/isalpha.c b/src/ctype/isalpha.c new file mode 100644 index 00000000..2b893425 --- /dev/null +++ b/src/ctype/isalpha.c @@ -0,0 +1,26 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" + +/** test whether a character is alphabetic **/ +int isalpha(int c) +{ + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is an alphabetic character) + RETURN(0, ARGUMENT(c) is not an alphabetic character) + */ + return islower(c) || isupper(c); +} + +/*** +tests whether ARGUMENT(c) is a character in the class +CHARACTER_CLASS(alpha) in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for characters for which FUNCTION(isupper) or FUNCTION(islower) is true') +OTHER_LOCALES(`THIS is true for a set of characters for which none of FUNCTION(iscntrl), FUNCTION(isdigit), FUNCTION(ispunct), or FUNCTION(isspace) is true') +STDC(1) +*/ diff --git a/src/ctype/isblank.c b/src/ctype/isblank.c new file mode 100644 index 00000000..1a597f82 --- /dev/null +++ b/src/ctype/isblank.c @@ -0,0 +1,39 @@ +#include <ctype.h> +#include "limits.h" +#include "locale.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" +#include "nonstd/assert.h" + +/** test whether a character is blank **/ +int isblank(int c) +{ + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, "unsigned char", EOF); + + unsigned int *map = __libc(CTYPE); + + return map[c] & BLANK; +} + +/*** +The fn(isblank) functions tests whether a character is a of the character +class cclass(blank) in the current locale. + +In the locale(C) and locale(POSIX) locales, only the standard blank characters +space (char( )) horizontal tab (char(\t)) are blank. + +In other locales, fn(isblank) will return true for the standard blank characters +as well as other characters for which fn(isspace) is true and the character is +used to separate words on a line a text. +***/ + +/* RETURN(NZ): arg(c) is a blank character */ +/* RETURN(0): arg(c) is not a blank character */ + +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* +STDC(199901) +*/ diff --git a/src/ctype/iscntrl.c b/src/ctype/iscntrl.c new file mode 100644 index 00000000..31804123 --- /dev/null +++ b/src/ctype/iscntrl.c @@ -0,0 +1,29 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is a control character */ +int iscntrl(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a control character); + RETURN(0, ARGUMENT(c) is not a control character); + */ + + return map[c] == 0 || (map[c] == SPACE && c != ' '); +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(cntrl) in the +current locale. +***/ + +/* +LC_CTYPE +STDC(1) +*/ diff --git a/src/ctype/isdigit.c b/src/ctype/isdigit.c new file mode 100644 index 00000000..7a19fe19 --- /dev/null +++ b/src/ctype/isdigit.c @@ -0,0 +1,26 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" + +/** test whether a character is a digit **/ +int isdigit(int c) +{ + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a digit); + RETURN(0, ARGUMENT(c) is not a digit); + */ + + return isxdigit(c) && !isalpha(c); +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(digit) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for characters CHAR(0), CHAR(1), CHAR(2), CHAR(3), CHAR(4), CHAR(5), CHAR(6), CHAR(7), CHAR(8), and CHAR(9)') +STDC(1) +*/ diff --git a/src/ctype/isgraph.c b/src/ctype/isgraph.c new file mode 100644 index 00000000..8ad3be0b --- /dev/null +++ b/src/ctype/isgraph.c @@ -0,0 +1,30 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is graphic **/ +int isgraph(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a graphic character); + RETURN(0, ARGUMENT(c) is not a graphic character); + */ + + return map[c] & ~SPACE; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(graph) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for all printable characters other than SPACE()') +STDC(1) +*/ diff --git a/src/ctype/islower.c b/src/ctype/islower.c new file mode 100644 index 00000000..082697dd --- /dev/null +++ b/src/ctype/islower.c @@ -0,0 +1,30 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/internal.h" +#include "nonstd/ctype.h" + +/** test whether a character is a lowercase letter **/ +int islower(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a lowercase letter); + RETURN(0, ARGUMENT(c) is not a lowercase letter); + */ + return map[c] & LOWER; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(lower) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for the characters CHAR(a), CHAR(b), CHAR(c), CHAR(d), CHAR(e), CHAR(f), CHAR(g), CHAR(h), CHAR(i), CHAR(j), CHAR(k), CHAR(l), CHAR(m), CHAR(n), CHAR(o), CHAR(p), CHAR(q), CHAR(s), CHAR(t), CHAR(u), CHAR(w), CHAR(x), CHAR(y), and CHAR(z)') +OTHER_LOCALES(`THIS() is true for a set of characters for which none of FUNCTION(iscntrl), FUNCTION(isdigit), FUNCTION(ispunct), or FUNCTION(isspace) is true') +STDC(1) +*/ diff --git a/src/ctype/isprint.c b/src/ctype/isprint.c new file mode 100644 index 00000000..58120351 --- /dev/null +++ b/src/ctype/isprint.c @@ -0,0 +1,30 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is printable **/ +int isprint(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a printable character); + RETURN(0, ARGUMENT(c) is not a printable character); + */ + + return map[c] & ~SPACE || c == ' '; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(print) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for any printing character including SPACE()') +STDC(1) +*/ diff --git a/src/ctype/ispunct.c b/src/ctype/ispunct.c new file mode 100644 index 00000000..bad66523 --- /dev/null +++ b/src/ctype/ispunct.c @@ -0,0 +1,30 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is punctuation **/ +int ispunct(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a punctuation character); + RETURN(0, ARGUMENT(c) is not a punctuation character); + */ + + return map[c] & PUNCT; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(punct) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for printing characters for which neither FUNCTION(isspace) nor FUNCTION(isalnum) is true') +STDC(1) +*/ diff --git a/src/ctype/isspace.c b/src/ctype/isspace.c new file mode 100644 index 00000000..a83cb584 --- /dev/null +++ b/src/ctype/isspace.c @@ -0,0 +1,31 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is white-space **/ +int isspace(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a white-space character); + RETURN(0, ARGUMENT(c) is not a white-space character); + */ + + return map[c] & SPACE; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(space) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for the standard white-space characters: SPACE, form feed (CHAR(\f)), new-line (CHAR(\n)), carriage return (CHAR(\r)), horizontal tab (CHAR(\t)), and vertical tab (CHAR(\v))') +OTHER_LOCALES(`THIS() is true for the standard white-space characters and a set of characters for which FUNCTION(isalnum) is false') +STDC(1) +*/ diff --git a/src/ctype/isupper.c b/src/ctype/isupper.c new file mode 100644 index 00000000..84247c28 --- /dev/null +++ b/src/ctype/isupper.c @@ -0,0 +1,31 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is an uppercase letter **/ +int isupper(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is an uppercase letter); + RETURN(0, ARGUMENT(c) is not an uppercase letter); + */ + + return map[c] & UPPER; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(upper) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for the characters CHAR(A), CHAR(B), CHAR(C), CHAR(D), CHAR(E), CHAR(F), CHAR(G), CHAR(H), CHAR(I), CHAR(J), CHAR(K), CHAR(L), CHAR(M), CHAR(N), CHAR(O), CHAR(P), CHAR(Q), CHAR(S), CHAR(T), CHAR(U), CHAR(W), CHAR(X), CHAR(Y), and CHAR(Z)') +OTHER_LOCALES(`THIS() is true for a set of characters for which none of FUNCTION(iscntrl), FUNCTION(isdigit), FUNCTION(ispunct), or FUNCTION(isspace) is true') +STDC(1) +*/ diff --git a/src/ctype/isxdigit.c b/src/ctype/isxdigit.c new file mode 100644 index 00000000..37857d92 --- /dev/null +++ b/src/ctype/isxdigit.c @@ -0,0 +1,29 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** test whether a character is a hexadecimal digit **/ +int isxdigit(int c) +{ + unsigned int *map = __libc(CTYPE); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN(NONZERO, ARGUMENT(c) is a hexadecimal digit); + RETURN(0, ARGUMENT(c) is not a hexadecimal digit); + */ + return map[c] & XDIGIT; +} + +/*** +tests whether ARGUMENT(c) is a character in the class CHARACTER_CLASS(xdigit) +in the current locale. +***/ + +/* +LC_CTYPE +C_LOCALE(`THIS() is true for the characters CHAR(0), CHAR(1), CHAR(2), CHAR(3), CHAR(4), CHAR(5), CHAR(6), CHAR(7), CHAR(8), CHAR(9), CHAR(a), CHAR(b), CHAR(c), CHAR(d), CHAR(e), CHAR(f), CHAR(A), CHAR(B), CHAR(C), CHAR(D), CHAR(E), and CHAR(F)') +STDC(1) +*/ diff --git a/src/ctype/tolower.c b/src/ctype/tolower.c new file mode 100644 index 00000000..b684eb7a --- /dev/null +++ b/src/ctype/tolower.c @@ -0,0 +1,29 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/ctype.h" +#include "nonstd/internal.h" + +/** convert an uppercase letter to lowercase **/ +int tolower(int c) +{ + unsigned char *map = __libc(TOLOWER); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN_SUCCESS(ARGUMENT(c) converted to lowercase); + RETURN_FAILURE(ARGUMENT(c), ARGUMENT(c) was not an uppercase letter or it has no equivalent lowercase letter); + */ + + return map[c]; +} + +/*** +converts an uppercase letter to its equivalent lowercase letter in the current +locale. +***/ + +/* +LC_CTYPE +STDC(1) +*/ diff --git a/src/ctype/toupper.c b/src/ctype/toupper.c new file mode 100644 index 00000000..f4611bc7 --- /dev/null +++ b/src/ctype/toupper.c @@ -0,0 +1,27 @@ +#include <ctype.h> +#include "limits.h" +#include "nonstd/assert.h" +#include "nonstd/internal.h" + +/** convert a lowercase letter to uppercase **/ +int toupper(int c) +{ + unsigned char *map = __libc(TOUPPER); + + ASSERT_REPRESENTABLE(c, 0, UCHAR_MAX, unsigned char, EOF); + /* + RETURN_SUCCESS(ARGUMENT(c) converted to uppercase); + RETURN_FAILURE(ARGUMENT(c), ARGUMENT(c) was not a lowercase letter or it has no equivalent upercase letter); + */ + return map[c]; +} + +/*** +converts a lowercase letter to its equivalent uppercase letter in the current +locale. +***/ + +/* +LC_CTYPE +STDC(1) +*/ |