summaryrefslogtreecommitdiffstats
path: root/src/include/ctype.h
diff options
context:
space:
mode:
authorMichael Brown2015-03-02 15:41:49 +0100
committerMichael Brown2015-03-02 17:35:37 +0100
commitd1f0e89e4e898c877d0f05ee0c1405b62049e795 (patch)
treef10d98d07ecd1532cf437611d88b407b1f44d062 /src/include/ctype.h
parent[libc] Rewrite unrelicensable portions of stddef.h (diff)
downloadipxe-d1f0e89e4e898c877d0f05ee0c1405b62049e795.tar.gz
ipxe-d1f0e89e4e898c877d0f05ee0c1405b62049e795.tar.xz
ipxe-d1f0e89e4e898c877d0f05ee0c1405b62049e795.zip
[libc] Rewrite unrelicensable portions of ctype.h
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ctype.h')
-rw-r--r--src/include/ctype.h118
1 files changed, 101 insertions, 17 deletions
diff --git a/src/include/ctype.h b/src/include/ctype.h
index e92ecb1c..0d79ecd1 100644
--- a/src/include/ctype.h
+++ b/src/include/ctype.h
@@ -4,30 +4,114 @@
/** @file
*
* Character types
+ *
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-#define isdigit(c) ((c) >= '0' && (c) <= '9')
-#define islower(c) ((c) >= 'a' && (c) <= 'z')
-#define isupper(c) ((c) >= 'A' && (c) <= 'Z')
-#define isxdigit(c) (isdigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f'))
-#define isprint(c) ((c) >= ' ' && (c) <= '~' )
+/**
+ * Check if character is a decimal digit
+ *
+ * @v character ASCII character
+ * @ret is_digit Character is a decimal digit
+ */
+static inline int isdigit ( int character ) {
-static inline unsigned char tolower(unsigned char c)
-{
- if (isupper(c))
- c -= 'A'-'a';
- return c;
+ return ( ( character >= '0' ) && ( character <= '9' ) );
}
-static inline unsigned char toupper(unsigned char c)
-{
- if (islower(c))
- c -= 'a'-'A';
- return c;
+/**
+ * Check if character is a hexadecimal digit
+ *
+ * @v character ASCII character
+ * @ret is_xdigit Character is a hexadecimal digit
+ */
+static inline int isxdigit ( int character ) {
+
+ return ( ( ( character >= '0' ) && ( character <= '9' ) ) ||
+ ( ( character >= 'A' ) && ( character <= 'F' ) ) ||
+ ( ( character >= 'a' ) && ( character <= 'f' ) ) );
+}
+
+/**
+ * Check if character is an upper-case letter
+ *
+ * @v character ASCII character
+ * @ret is_upper Character is an upper-case letter
+ */
+static inline int isupper ( int character ) {
+
+ return ( ( character >= 'A' ) && ( character <= 'Z' ) );
+}
+
+/**
+ * Check if character is a lower-case letter
+ *
+ * @v character ASCII character
+ * @ret is_lower Character is a lower-case letter
+ */
+static inline int islower ( int character ) {
+
+ return ( ( character >= 'a' ) && ( character <= 'z' ) );
+}
+
+/**
+ * Check if character is alphabetic
+ *
+ * @v character ASCII character
+ * @ret is_alpha Character is alphabetic
+ */
+static inline int isalpha ( int character ) {
+
+ return ( isupper ( character ) || islower ( character ) );
+}
+
+/**
+ * Check if character is alphanumeric
+ *
+ * @v character ASCII character
+ * @ret is_alnum Character is alphanumeric
+ */
+static inline int isalnum ( int character ) {
+
+ return ( isalpha ( character ) || isdigit ( character ) );
+}
+
+/**
+ * Check if character is printable
+ *
+ * @v character ASCII character
+ * @ret is_print Character is printable
+ */
+static inline int isprint ( int character ) {
+
+ return ( ( character >= ' ' ) && ( character <= '~' ) );
+}
+
+/**
+ * Convert character to lower case
+ *
+ * @v character Character
+ * @v character Lower-case character
+ */
+static inline int tolower ( int character ) {
+
+ return ( isupper ( character ) ?
+ ( character - 'A' + 'a' ) : character );
+}
+
+/**
+ * Convert character to upper case
+ *
+ * @v character Character
+ * @v character Upper-case character
+ */
+static inline int toupper ( int character ) {
+
+ return ( islower ( character ) ?
+ ( character - 'a' + 'A' ) : character );
}
-extern int isspace ( int c );
+extern int isspace ( int character );
#endif /* _CTYPE_H */