/* We save ~500 bytes on isdigit alone.
* BTW, x86 likes (unsigned char) cast more than (unsigned). */
-#define isdigit(a) ((unsigned char)((a) - '0') <= 9)
+
+/* These work the same for ASCII and Unicode,
+ * assuming no one asks "is this a *Unicode* letter?" using isalpha(letter) */
#define isascii(a) ((unsigned char)(a) <= 0x7f)
-#define isgraph(a) ((unsigned char)(a) > ' ')
-#define isprint(a) ((unsigned char)(a) >= ' ')
+#define isdigit(a) ((unsigned char)((a) - '0') <= 9)
#define isupper(a) ((unsigned char)((a) - 'A') <= ('Z' - 'A'))
#define islower(a) ((unsigned char)((a) - 'a') <= ('z' - 'a'))
#define isalpha(a) ((unsigned char)(((a)|0x20) - 'a') <= ('z' - 'a'))
* "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13.
*/
#define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); })
-
-// Bigger code:
-//#define isalnum(a) ({ unsigned char bb__isalnum = (a) - '0'; bb__isalnum <= 9 || ((bb__isalnum - ('A' - '0')) & 0xdf) <= 25; })
+// Unsafe wrt NUL: #define ispunct(a) (strchr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a)) != NULL)
+#define ispunct(a) (strchrnul("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a))[0])
+// Bigger code: #define isalnum(a) ({ unsigned char bb__isalnum = (a) - '0'; bb__isalnum <= 9 || ((bb__isalnum - ('A' - '0')) & 0xdf) <= 25; })
#define isalnum(a) bb_ascii_isalnum(a)
static ALWAYS_INLINE int bb_ascii_isalnum(unsigned char a)
{
b = (a|0x20) - 'a';
return b <= 'f' - 'a';
}
-
-// Unsafe wrt NUL!
-//#define ispunct(a) (strchr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a)) != NULL)
-#define ispunct(a) (strchrnul("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a))[0])
-
#define toupper(a) bb_ascii_toupper(a)
static ALWAYS_INLINE unsigned char bb_ascii_toupper(unsigned char a)
{
return a;
}
+/* In ASCII and Unicode, these are likely to be very different.
+ * Let's prevent ambiguous usage from the start */
+#define isgraph(a) isgraph_is_ambiguous_dont_use(a)
+#define isprint(a) isprint_is_ambiguous_dont_use(a)
+/* NB: must not treat EOF as isgraph or isprint */
+#define isgraph_asciionly(a) ((unsigned)((a) - 0x21) <= 0x7e - 0x21)
+#define isprint_asciionly(a) ((unsigned)((a) - 0x20) <= 0x7e - 0x20)
+
POP_SAVED_FUNCTION_VISIBILITY
str += 4;
} while (*str);
- if (isprint(*p)) {
+ if (isprint_asciionly(*p)) {
*pr->cchar = 'c';
printf(pr->fmt, *p);
} else {
sprintf(buf, "%03o", (int) *p);
str = buf;
- strpr:
+ strpr:
*pr->cchar = 's';
printf(pr->fmt, str);
}
} else if (*p == 0x7f) {
*pr->cchar = 's';
printf(pr->fmt, "del");
- } else if (isprint(*p)) {
+ } else if (*p < 0x7f) { /* isprint() */
*pr->cchar = 'c';
printf(pr->fmt, *p);
} else {
break;
}
case F_P:
- printf(pr->fmt, isprint(*bp) ? *bp : '.');
+ printf(pr->fmt, isprint_asciionly(*bp) ? *bp : '.');
break;
case F_STR:
printf(pr->fmt, (char *) bp);