Ruby  3.4.0dev (2024-11-22 revision 37a72b0150ec36b4ea27175039afc28c62207b0c)
ctype.h
Go to the documentation of this file.
1 #ifndef RBIMPL_CTYPE_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_CTYPE_H
23 #include "ruby/internal/config.h"
24 
25 #ifdef STDC_HEADERS
26 # include <ctype.h>
27 #endif
28 
34 
84 #ifndef ISPRINT
85 # define ISASCII rb_isascii
86 # define ISPRINT rb_isprint
87 # define ISGRAPH rb_isgraph
88 # define ISSPACE rb_isspace
89 # define ISUPPER rb_isupper
90 # define ISLOWER rb_islower
91 # define ISALNUM rb_isalnum
92 # define ISALPHA rb_isalpha
93 # define ISDIGIT rb_isdigit
94 # define ISXDIGIT rb_isxdigit
95 # define ISBLANK rb_isblank
96 # define ISCNTRL rb_iscntrl
97 # define ISPUNCT rb_ispunct
98 #endif
99 
100 #define TOUPPER rb_toupper
101 #define TOLOWER rb_tolower
102 #define STRCASECMP st_locale_insensitive_strcasecmp
103 #define STRNCASECMP st_locale_insensitive_strncasecmp
104 #define STRTOUL ruby_strtoul
113 /* In descriptions below, `the POSIX Locale` and `the "C" locale` are tactfully
114  * used as to whether the described function mimics POSIX or C99. */
115 
132 int st_locale_insensitive_strcasecmp(const char *s1, const char *s2);
133 
152 int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n);
153 
187 unsigned long ruby_strtoul(const char *str, char **endptr, int base);
189 
190 /*
191  * We are making the functions below to return `int` instead of `bool`. They
192  * have been as such since their birth at 5f237d79033b2109afb768bc889611fa9630.
193  */
194 
208 static inline int
210 {
211  return '\0' <= c && c <= '\x7f';
212 }
213 
231 static inline int
233 {
234  return 'A' <= c && c <= 'Z';
235 }
236 
254 static inline int
256 {
257  return 'a' <= c && c <= 'z';
258 }
259 
278 static inline int
280 {
281  return rb_isupper(c) || rb_islower(c);
282 }
283 
301 static inline int
303 {
304  return '0' <= c && c <= '9';
305 }
306 
325 static inline int
327 {
328  return rb_isalpha(c) || rb_isdigit(c);
329 }
330 
348 static inline int
350 {
351  return rb_isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f');
352 }
353 
371 static inline int
373 {
374  return c == ' ' || c == '\t';
375 }
376 
394 static inline int
396 {
397  return c == ' ' || ('\t' <= c && c <= '\r');
398 }
399 
417 static inline int
419 {
420  return ('\0' <= c && c < ' ') || c == '\x7f';
421 }
422 
441 static inline int
443 {
444  return ' ' <= c && c <= '\x7e';
445 }
446 
464 static inline int
466 {
467  return !rb_isalnum(c);
468 }
469 
488 static inline int
490 {
491  return '!' <= c && c <= '\x7e';
492 }
493 
513 static inline int
515 {
516  return rb_isupper(c) ? (c|0x20) : c;
517 }
518 
538 static inline int
540 {
541  return rb_islower(c) ? (c&0x5f) : c;
542 }
543 
545 #endif /* RBIMPL_CTYPE_H */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:41
Defines RBIMPL_ATTR_CONST.
RBIMPL_ATTR_CONSTEXPR.
#define RBIMPL_ATTR_CONSTEXPR(_)
Wraps (or simulates) C++11 constexpr.
Definition: constexpr.h:74
static int rb_isdigit(int c)
Our own locale-insensitive version of isdigit(3).
Definition: ctype.h:302
static int rb_isupper(int c)
Our own locale-insensitive version of isupper(3).
Definition: ctype.h:232
static int rb_iscntrl(int c)
Our own locale-insensitive version of iscntrl(3).
Definition: ctype.h:418
int st_locale_insensitive_strcasecmp(const char *s1, const char *s2)
Our own locale-insensitive version of strcasecmp(3).
Definition: st.c:2002
static int rb_ispunct(int c)
Our own locale-insensitive version of ispunct(3).
Definition: ctype.h:465
static int rb_isalnum(int c)
Our own locale-insensitive version of isalnum(3).
Definition: ctype.h:326
static int rb_isxdigit(int c)
Our own locale-insensitive version of isxdigit(3).
Definition: ctype.h:349
static int rb_isspace(int c)
Our own locale-insensitive version of isspace(3).
Definition: ctype.h:395
static int rb_isascii(int c)
Our own locale-insensitive version of isascii(3).
Definition: ctype.h:209
static int rb_toupper(int c)
Our own locale-insensitive version of toupper(3).
Definition: ctype.h:539
unsigned long ruby_strtoul(const char *str, char **endptr, int base)
Our own locale-insensitive version of strtoul(3).
Definition: util.c:138
static int rb_tolower(int c)
Our own locale-insensitive version of tolower(3).
Definition: ctype.h:514
int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n)
Our own locale-insensitive version of strcnasecmp(3).
Definition: st.c:2026
static int rb_isgraph(int c)
Our own locale-insensitive version of isgraph(3).
Definition: ctype.h:489
static int rb_isalpha(int c)
Our own locale-insensitive version of isalpha(3).
Definition: ctype.h:279
static int rb_islower(int c)
Our own locale-insensitive version of islower(3).
Definition: ctype.h:255
static int rb_isprint(int c)
Identical to rb_isgraph(), except it also returns true for ‘’ '`.
Definition: ctype.h:442
static int rb_isblank(int c)
Our own locale-insensitive version of isblank(3).
Definition: ctype.h:372
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:65
RBIMPL_ATTR_CONST() int rb_io_oflags_fmode(int oflags)
Converts an oflags (that rb_io_modestr_oflags() returns) to a fmode (that rb_io_mode_flags() returns)...
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition: defines.h:88