summaryrefslogtreecommitdiff
path: root/internal/strings/ascii_ctype.h
diff options
context:
space:
mode:
authorEino-Ville Talvala <etalvala@google.com>2018-11-15 15:49:02 -0800
committerEino-Ville Talvala <etalvala@google.com>2018-11-15 16:07:24 -0800
commit09f199a694ef5b956cabc368e40ab5ca11c64044 (patch)
tree456d184a3817c8b6524a90fc2da60893a2fc1895 /internal/strings/ascii_ctype.h
parent2d25fc4f6a7e7453f877958a2f3f59b6cc588ca4 (diff)
downloaddynamic_depth-09f199a694ef5b956cabc368e40ab5ca11c64044.tar.gz
Initial commit of libdynamic_depth
Dynamic depth is a standard for embedding depth maps and other similar extensions into standard image files like JPEG. Test: m libdynamic_depth Bug: 109735087 Bug: 119211681 Change-Id: I0103b7d47e60dc8e3a3b277456903d76f727926f
Diffstat (limited to 'internal/strings/ascii_ctype.h')
-rw-r--r--internal/strings/ascii_ctype.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/internal/strings/ascii_ctype.h b/internal/strings/ascii_ctype.h
new file mode 100644
index 0000000..acc1fe5
--- /dev/null
+++ b/internal/strings/ascii_ctype.h
@@ -0,0 +1,89 @@
+// Character classification functions similar to standard <ctype.h>.
+// Some C++ implementations provide locale-sensitive implementations
+// of some <ctype.h> functions. These ascii_* functions are
+// hard-wired for ASCII. Hard-wired for ASCII is much faster.
+//
+// ascii_isalnum, ascii_isalpha, ascii_isascii, ascii_isblank,
+// ascii_iscntrl, ascii_isdigit, ascii_isgraph, ascii_islower,
+// ascii_isprint, ascii_ispunct, ascii_isspace, ascii_isupper,
+// ascii_isxdigit
+// Similar to the <ctype.h> functions with similar names.
+// Input parameter is an unsigned char. Return value is a bool.
+// If the input has a numerical value greater than 127
+// then the output is "false".
+//
+// ascii_tolower, ascii_toupper
+// Similar to the <ctype.h> functions with similar names.
+// Input parameter is an unsigned char. Return value is a char.
+// If the input is not an ascii {lower,upper}-case letter
+// (including numerical values greater than 127)
+// then the output is the same as the input.
+
+#ifndef DYNAMIC_DEPTH_INTERNAL_STRINGS_ASCII_CTYPE_H_ // NOLINT
+#define DYNAMIC_DEPTH_INTERNAL_STRINGS_ASCII_CTYPE_H_ // NOLINT
+
+namespace dynamic_depth {
+
+// Array of character information. This is an implementation detail.
+// The individual bits do not have names because the array definition is
+// already tightly coupled to these functions. Names would just make it
+// harder to read and debug.
+
+extern const unsigned char kAsciiPropertyBits[256];
+
+// Public functions.
+
+static inline bool ascii_isalpha(unsigned char c) {
+ return (kAsciiPropertyBits[c] & 0x01) != 0;
+}
+
+static inline bool ascii_isalnum(unsigned char c) {
+ return (kAsciiPropertyBits[c] & 0x04) != 0;
+}
+
+static inline bool ascii_isspace(unsigned char c) {
+ return (kAsciiPropertyBits[c] & 0x08) != 0;
+}
+
+static inline bool ascii_ispunct(unsigned char c) {
+ return (kAsciiPropertyBits[c] & 0x10) != 0;
+}
+
+static inline bool ascii_isblank(unsigned char c) {
+ return (kAsciiPropertyBits[c] & 0x20) != 0;
+}
+
+static inline bool ascii_iscntrl(unsigned char c) {
+ return (kAsciiPropertyBits[c] & 0x40) != 0;
+}
+
+static inline bool ascii_isxdigit(unsigned char c) {
+ return (kAsciiPropertyBits[c] & 0x80) != 0;
+}
+
+static inline bool ascii_isdigit(unsigned char c) {
+ return c >= '0' && c <= '9';
+}
+
+static inline bool ascii_isprint(unsigned char c) { return c >= 32 && c < 127; }
+
+static inline bool ascii_isgraph(unsigned char c) { return c > 32 && c < 127; }
+
+static inline bool ascii_isupper(unsigned char c) {
+ return c >= 'A' && c <= 'Z';
+}
+
+static inline bool ascii_islower(unsigned char c) {
+ return c >= 'a' && c <= 'z';
+}
+
+static inline bool ascii_isascii(unsigned char c) { return c < 128; }
+
+extern const char kAsciiToLower[256];
+static inline char ascii_tolower(unsigned char c) { return kAsciiToLower[c]; }
+extern const char kAsciiToUpper[256];
+static inline char ascii_toupper(unsigned char c) { return kAsciiToUpper[c]; }
+
+} // namespace dynamic_depth
+
+#endif // DYNAMIC_DEPTH_INTERNAL_STRINGS_ASCII_CTYPE_H_ // NOLINT