diff options
| author | Jakob Kaivo <jkk@ung.org> | 2024-06-03 13:56:25 -0400 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2024-06-03 13:56:25 -0400 |
| commit | a686d047d79bdfc37c096a4fa350c37e4ccf3cf5 (patch) | |
| tree | ca631b9095454a239211b6f676bdd3e0cb102156 /src/wctype | |
| parent | c575f269ed4a04f89d610b423cc43ce7bd6f008b (diff) | |
add LC_CTYPE epoch and use separate CT_ categories and CTM_ masks to support detecting change of LC_CTYPE between calls to wctype()/iswctype() and wctrans()/towctrans()
Diffstat (limited to 'src/wctype')
| -rw-r--r-- | src/wctype/_wctype.h | 2 | ||||
| -rw-r--r-- | src/wctype/iswctype.c | 4 | ||||
| -rw-r--r-- | src/wctype/towctrans.c | 4 | ||||
| -rw-r--r-- | src/wctype/wctrans.c | 5 | ||||
| -rw-r--r-- | src/wctype/wctrans_t.h | 2 | ||||
| -rw-r--r-- | src/wctype/wctype.c | 25 | ||||
| -rw-r--r-- | src/wctype/wctype_t.h | 2 |
7 files changed, 28 insertions, 16 deletions
diff --git a/src/wctype/_wctype.h b/src/wctype/_wctype.h index 8dfbf3cd..24b4649e 100644 --- a/src/wctype/_wctype.h +++ b/src/wctype/_wctype.h @@ -1,5 +1,7 @@ #include "ctype/_ctype.h" +#define CT_EPOCH_SHIFT (8) + /* STDC(0) */ diff --git a/src/wctype/iswctype.c b/src/wctype/iswctype.c index b1d1a3a1..ae952279 100644 --- a/src/wctype/iswctype.c +++ b/src/wctype/iswctype.c @@ -9,6 +9,10 @@ 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); + if (__get_locale()->ctype_epoch != (desc >> CT_EPOCH_SHIFT)) { + UNDEFINED("LC_CTYPE has been changed since the call to wctype()"); + } + /* TODO: actual work */ (void)wc; (void)desc; diff --git a/src/wctype/towctrans.c b/src/wctype/towctrans.c index 8e6d266c..4dccfa64 100644 --- a/src/wctype/towctrans.c +++ b/src/wctype/towctrans.c @@ -8,6 +8,10 @@ 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); + if (__get_locale()->ctype_epoch != (desc >> CT_EPOCH_SHIFT)) { + UNDEFINED("LC_CTYPE has changed since the call to wctrans()"); + } + /* TODO: actual work */ (void)wc; (void)desc; diff --git a/src/wctype/wctrans.c b/src/wctype/wctrans.c index aa47d945..7f724d27 100644 --- a/src/wctype/wctrans.c +++ b/src/wctype/wctrans.c @@ -7,11 +7,12 @@ wctrans_t wctrans(const char * property) { SIGNAL_SAFE(0); ASSERT_NONNULL(property); + wctrans_t epoch = __get_locale()->ctype_epoch << CT_EPOCH_SHIFT; if (!strcmp(property, "tolower")) { - return CT_LOWER; + return epoch | CT_LOWER; } else if (!strcmp(property, "toupper")) { - return CT_UPPER; + return epoch | CT_UPPER; } return 0; diff --git a/src/wctype/wctrans_t.h b/src/wctype/wctrans_t.h index f11d5863..0ebf8d24 100644 --- a/src/wctype/wctrans_t.h +++ b/src/wctype/wctrans_t.h @@ -1,5 +1,5 @@ #include <wctype.h> -typedef int wctrans_t; +typedef unsigned int wctrans_t; /* STDC(199409) diff --git a/src/wctype/wctype.c b/src/wctype/wctype.c index 2dd4599f..cf82c4ed 100644 --- a/src/wctype/wctype.c +++ b/src/wctype/wctype.c @@ -7,31 +7,32 @@ wctype_t wctype(const char * property) { SIGNAL_SAFE(0); ASSERT_NONNULL(property); + wctype_t epoch = ((__get_locale()->ctype_epoch) << CT_EPOCH_SHIFT); if (!strcmp(property, "alnum")) { - return CT_ALPHA | CT_DIGIT; + return epoch | CT_ALNUM; } else if (!strcmp(property, "alpha")) { - return CT_ALPHA; + return epoch | CT_ALPHA; } else if (!strcmp(property, "blank")) { - return CT_BLANK; + return epoch | CT_BLANK; } else if (!strcmp(property, "cntrl")) { - return CT_CNTRL; + return epoch | CT_CNTRL; } else if (!strcmp(property, "digit")) { - return CT_DIGIT; + return epoch | CT_DIGIT; } else if (!strcmp(property, "graph")) { - return CT_GRAPH; + return epoch | CT_GRAPH; } else if (!strcmp(property, "lower")) { - return CT_LOWER; + return epoch | CT_LOWER; } else if (!strcmp(property, "print")) { - return CT_PRINT; + return epoch | CT_PRINT; } else if (!strcmp(property, "punct")) { - return CT_PUNCT; + return epoch | CT_PUNCT; } else if (!strcmp(property, "space")) { - return CT_SPACE; + return epoch | CT_SPACE; } else if (!strcmp(property, "upper")) { - return CT_UPPER; + return epoch | CT_UPPER; } else if (!strcmp(property, "xdigit")) { - return CT_XDIGIT; + return epoch | CT_XDIGIT; } return 0; diff --git a/src/wctype/wctype_t.h b/src/wctype/wctype_t.h index f2dbd801..b1dcd910 100644 --- a/src/wctype/wctype_t.h +++ b/src/wctype/wctype_t.h @@ -1,5 +1,5 @@ #include <wctype.h> -typedef int wctype_t; +typedef unsigned int wctype_t; /* STDC(199409) |
