Merge "<ctype.h>: stop using `_ctype_`." into main am: e253761e14

Original change: https://android-review.googlesource.com/c/platform/bionic/+/2779335

Change-Id: I99943226277d1f4e4d17d1ad6dd0927c9f237337
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index ae885b1..c15ee56 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -73,15 +73,6 @@
 /** Internal implementation detail. Do not use. */
 extern const char* _ctype_;
 
-/** Returns true if `ch` is in `[A-Za-z0-9]`. */
-__BIONIC_CTYPE_INLINE int isalnum(int __ch) {
-  // `isalnum(c)` is `isalpha(c) || isdigit(c)`, but there's no obvious way
-  // to simplify that, and the table lookup is just slightly faster...
-  // Note that this is unsafe for inputs less than -1 (EOF) or greater than
-  // 0xff. This is true of other C libraries too.
-  return (_ctype_[__ch + 1] & (_CTYPE_U|_CTYPE_L|_CTYPE_N));
-}
-
 /** Returns true if `ch` is in `[A-Za-z]`. */
 __BIONIC_CTYPE_INLINE int isalpha(int __ch) {
   return (__ch >= 'A' && __ch <= 'Z') || (__ch >= 'a' && __ch <= 'z');
@@ -117,15 +108,6 @@
   return (__ch >= ' ' && __ch <= '~');
 }
 
-/** Returns true if `ch` is punctuation. */
-__BIONIC_CTYPE_INLINE int ispunct(int __ch) {
-  // `ispunct(c)` is `isgraph(c) && !isalnum(c)`, but there's no obvious way
-  // to simplify that, and the table lookup is just slightly faster...
-  // Note that this is unsafe for inputs less than -1 (EOF) or greater than
-  // 0xff. This is true of other C libraries too.
-  return (_ctype_[__ch + 1] & _CTYPE_P);
-}
-
 /** Returns true if `ch` is in `[ \f\n\r\t\v]`. */
 __BIONIC_CTYPE_INLINE int isspace(int __ch) {
   return __ch == ' ' || (__ch >= '\t' && __ch <= '\r');
@@ -141,6 +123,16 @@
   return (__ch >= '0' && __ch <= '9') || (__ch >= 'a' && __ch <= 'f') || (__ch >= 'A' && __ch <= 'F');
 }
 
+/** Returns true if `ch` is in `[A-Za-z0-9]`. */
+__BIONIC_CTYPE_INLINE int isalnum(int __ch) {
+  return isalpha(__ch) || isdigit(__ch);
+}
+
+/** Returns true if `ch` is punctuation. */
+__BIONIC_CTYPE_INLINE int ispunct(int __ch) {
+  return isgraph(__ch) && !isalnum(__ch);
+}
+
 /**
  * Returns the corresponding lower-case character if `ch` is upper-case, or undefined otherwise.
  *