Ruby: include/ruby/internal/ctype.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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
29#include "ruby/internal/attr/artificial.h"
30#include "ruby/internal/attr/const.h"
31#include "ruby/internal/attr/constexpr.h"
32#include "ruby/internal/dllexport.h"
33
34#ifndef ISPRINT
35# define ISASCII rb_isascii
36# define ISPRINT rb_isprint
37# define ISGRAPH rb_isgraph
38# define ISSPACE rb_isspace
39# define ISUPPER rb_isupper
40# define ISLOWER rb_islower
41# define ISALNUM rb_isalnum
42# define ISALPHA rb_isalpha
43# define ISDIGIT rb_isdigit
44# define ISXDIGIT rb_isxdigit
45# define ISBLANK rb_isblank
46# define ISCNTRL rb_iscntrl
47# define ISPUNCT rb_ispunct
48#endif
49
50#define TOUPPER rb_toupper
51#define TOLOWER rb_tolower
52#define STRCASECMP st_locale_insensitive_strcasecmp
53#define STRNCASECMP st_locale_insensitive_strncasecmp
54#define STRTOUL ruby_strtoul
55
56 RBIMPL_SYMBOL_EXPORT_BEGIN()
57/* locale insensitive functions */
58 int st_locale_insensitive_strcasecmp(const char *s1, const char *s2);
59int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n);
60unsigned long ruby_strtoul(const char *str, char **endptr, int base);
61 RBIMPL_SYMBOL_EXPORT_END()
62
63/*
64 * We are making the functions below to return `int` instead of `bool`. They
65 * have been as such since their birth at 5f237d79033b2109afb768bc889611fa9630.
66 */
67
68 RBIMPL_ATTR_CONST()
69 RBIMPL_ATTR_CONSTEXPR(CXX11)
70 RBIMPL_ATTR_ARTIFICIAL()
71static inline int
72rb_isascii(int c)
73{
74 return '\0' <= c && c <= '\x7f';
75}
76
77 RBIMPL_ATTR_CONST()
78 RBIMPL_ATTR_CONSTEXPR(CXX11)
79 RBIMPL_ATTR_ARTIFICIAL()
80static inline int
81rb_isupper(int c)
82{
83 return 'A' <= c && c <= 'Z';
84}
85
86 RBIMPL_ATTR_CONST()
87 RBIMPL_ATTR_CONSTEXPR(CXX11)
88 RBIMPL_ATTR_ARTIFICIAL()
89static inline int
90rb_islower(int c)
91{
92 return 'a' <= c && c <= 'z';
93}
94
95 RBIMPL_ATTR_CONST()
96 RBIMPL_ATTR_CONSTEXPR(CXX11)
97 RBIMPL_ATTR_ARTIFICIAL()
98static inline int
99rb_isalpha(int c)
100{
101 return rb_isupper(c) || rb_islower(c);
102}
103
104 RBIMPL_ATTR_CONST()
105 RBIMPL_ATTR_CONSTEXPR(CXX11)
106 RBIMPL_ATTR_ARTIFICIAL()
107static inline int
108rb_isdigit(int c)
109{
110 return '0' <= c && c <= '9';
111}
112
113 RBIMPL_ATTR_CONST()
114 RBIMPL_ATTR_CONSTEXPR(CXX11)
115 RBIMPL_ATTR_ARTIFICIAL()
116static inline int
117rb_isalnum(int c)
118{
119 return rb_isalpha(c) || rb_isdigit(c);
120}
121
122 RBIMPL_ATTR_CONST()
123 RBIMPL_ATTR_CONSTEXPR(CXX11)
124 RBIMPL_ATTR_ARTIFICIAL()
125static inline int
126rb_isxdigit(int c)
127{
128 return rb_isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f');
129}
130
131 RBIMPL_ATTR_CONST()
132 RBIMPL_ATTR_CONSTEXPR(CXX11)
133 RBIMPL_ATTR_ARTIFICIAL()
134static inline int
135rb_isblank(int c)
136{
137 return c == ' ' || c == '\t';
138}
139
140 RBIMPL_ATTR_CONST()
141 RBIMPL_ATTR_CONSTEXPR(CXX11)
142 RBIMPL_ATTR_ARTIFICIAL()
143static inline int
144rb_isspace(int c)
145{
146 return c == ' ' || ('\t' <= c && c <= '\r');
147}
148
149 RBIMPL_ATTR_CONST()
150 RBIMPL_ATTR_CONSTEXPR(CXX11)
151 RBIMPL_ATTR_ARTIFICIAL()
152static inline int
153rb_iscntrl(int c)
154{
155 return ('\0' <= c && c < ' ') || c == '\x7f';
156}
157
158 RBIMPL_ATTR_CONST()
159 RBIMPL_ATTR_CONSTEXPR(CXX11)
160 RBIMPL_ATTR_ARTIFICIAL()
161static inline int
162rb_isprint(int c)
163{
164 return ' ' <= c && c <= '\x7e';
165}
166
167 RBIMPL_ATTR_CONST()
168 RBIMPL_ATTR_CONSTEXPR(CXX11)
169 RBIMPL_ATTR_ARTIFICIAL()
170static inline int
171rb_ispunct(int c)
172{
173 return !rb_isalnum(c);
174}
175
176 RBIMPL_ATTR_CONST()
177 RBIMPL_ATTR_CONSTEXPR(CXX11)
178 RBIMPL_ATTR_ARTIFICIAL()
179static inline int
180rb_isgraph(int c)
181{
182 return '!' <= c && c <= '\x7e';
183}
184
185 RBIMPL_ATTR_CONST()
186 RBIMPL_ATTR_CONSTEXPR(CXX11)
187 RBIMPL_ATTR_ARTIFICIAL()
188static inline int
189rb_tolower(int c)
190{
191 return rb_isupper(c) ? (c|0x20) : c;
192}
193
194 RBIMPL_ATTR_CONST()
195 RBIMPL_ATTR_CONSTEXPR(CXX11)
196 RBIMPL_ATTR_ARTIFICIAL()
197static inline int
198rb_toupper(int c)
199{
200 return rb_islower(c) ? (c&0x5f) : c;
201}
202
203#endif /* RBIMPL_CTYPE_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:43
const.h
Defines RBIMPL_ATTR_CONST.
RBIMPL_ATTR_CONST
#define RBIMPL_ATTR_CONST()
Wraps (or simulates) __attribute__((const))
Definition: const.h:36
constexpr.h
RBIMPL_ATTR_CONSTEXPR.
RBIMPL_ATTR_CONSTEXPR
#define RBIMPL_ATTR_CONSTEXPR(_)
Wraps (or simulates) C++11 constexpr.
Definition: constexpr.h:75
ctype.h
Our own, locale independent, character handling routines.
ruby_strtoul
unsigned long ruby_strtoul(const char *str, char **endptr, int base)
Definition: util.c:134
dllexport.h
Tewaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
config.h
Thin wrapper to ruby/config.h.
int
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
st_locale_insensitive_strncasecmp
#define st_locale_insensitive_strncasecmp
Definition: st.h:170
st_locale_insensitive_strcasecmp
#define st_locale_insensitive_strcasecmp
Definition: st.h:168
const
#define const
Definition: strftime.c:108