Skip to content

Commit

Permalink
handy.h: Collapse some macros
Browse files Browse the repository at this point in the history
These 3 sets of macros can be collapsed trivially into 3 macros.
  • Loading branch information
khwilliamson committed May 9, 2021
1 parent 290ddbe commit 2e70d52
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions handy.h
Expand Up @@ -1961,24 +1961,23 @@ END_EXTERN_C
* conform to the Unicode standard. */

/* This does not handle the anomalies in UTF-8 Turkic locales. */
#define generic_toLOWER_LC_(c, function) \
((! FITS_IN_8_BITS(c)) \
# define toLOWER_LC(c) ((! FITS_IN_8_BITS(c)) \
? (c) \
: ((IN_UTF8_CTYPE_LOCALE) \
? PL_latin1_lc[ (U8) (c) ] \
: (U8) function((U8) (c))))
: (U8) tolower((U8) (c))))

/* In this macro, note that the result can be larger than a byte in a UTF-8
* locale. It returns a single value, so can't adequately return the upper
* case of LATIN SMALL LETTER SHARP S in a UTF-8 locale (which should be a
* string of two values "SS"); instead it asserts against that under
* DEBUGGING, and otherwise returns its input. It does not handle the
* anomalies in UTF-8 Turkic locales. */
#define generic_toUPPER_LC_(c, function) \
# define toUPPER_LC(c) \
((! FITS_IN_8_BITS(c)) \
? (c) \
: ((! IN_UTF8_CTYPE_LOCALE) \
? (U8) function((U8) (c)) \
? (U8) toupper((U8) (c)) \
: (UNLIKELY(((U8)(c)) == MICRO_SIGN) \
? GREEK_CAPITAL_LETTER_MU \
: ((UNLIKELY(((U8) (c)) == LATIN_SMALL_LETTER_Y_WITH_DIAERESIS) \
Expand All @@ -1993,16 +1992,12 @@ END_EXTERN_C
* two values "ss"); instead it asserts against that under DEBUGGING, and
* otherwise returns its input. It does not handle the anomalies in UTF-8
* Turkic locales */
#define generic_toFOLD_LC_(c, function) \
# define toFOLD_LC(c) \
((UNLIKELY((c) == MICRO_SIGN) && IN_UTF8_CTYPE_LOCALE) \
? GREEK_SMALL_LETTER_MU \
: (__ASSERT_( ! IN_UTF8_CTYPE_LOCALE \
|| LIKELY((c) != LATIN_SMALL_LETTER_SHARP_S)) \
generic_toLOWER_LC_(c, function)))

# define toLOWER_LC(c) generic_toLOWER_LC_((c), tolower)
# define toUPPER_LC(c) generic_toUPPER_LC_((c), toupper)
# define toFOLD_LC(c) generic_toFOLD_LC_((c), tolower)
toLOWER_LC(c)))
#endif

#define isIDCONT(c) isWORDCHAR(c)
Expand Down

0 comments on commit 2e70d52

Please sign in to comment.