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

Ruby 3.4.4p34 (2025-05-14 revision a38531fd3f617bf734ef7d6c595325f69985ea1d)

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/attr/nonnull.h"
33#include "ruby/internal/dllexport.h"
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
105
107
108 RBIMPL_SYMBOL_EXPORT_BEGIN()
112
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
116 RBIMPL_ATTR_NONNULL(())
132int st_locale_insensitive_strcasecmp(const char *s1, const char *s2);
133
134 RBIMPL_ATTR_NONNULL(())
152int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n);
153
154 RBIMPL_ATTR_NONNULL((1))
187unsigned long ruby_strtoul(const char *str, char **endptr, int base);
188 RBIMPL_SYMBOL_EXPORT_END()
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
195 RBIMPL_ATTR_CONST()
196 RBIMPL_ATTR_CONSTEXPR(CXX11)
197 RBIMPL_ATTR_ARTIFICIAL()
208static inline int
209rb_isascii(int c)
210{
211 return '\0' <= c && c <= '\x7f';
212}
213
214 RBIMPL_ATTR_CONST()
215 RBIMPL_ATTR_CONSTEXPR(CXX11)
216 RBIMPL_ATTR_ARTIFICIAL()
231static inline int
232rb_isupper(int c)
233{
234 return 'A' <= c && c <= 'Z';
235}
236
237 RBIMPL_ATTR_CONST()
238 RBIMPL_ATTR_CONSTEXPR(CXX11)
239 RBIMPL_ATTR_ARTIFICIAL()
254static inline int
255rb_islower(int c)
256{
257 return 'a' <= c && c <= 'z';
258}
259
260 RBIMPL_ATTR_CONST()
261 RBIMPL_ATTR_CONSTEXPR(CXX11)
262 RBIMPL_ATTR_ARTIFICIAL()
278static inline int
279rb_isalpha(int c)
280{
281 return rb_isupper(c) || rb_islower(c);
282}
283
284 RBIMPL_ATTR_CONST()
285 RBIMPL_ATTR_CONSTEXPR(CXX11)
286 RBIMPL_ATTR_ARTIFICIAL()
301static inline int
302rb_isdigit(int c)
303{
304 return '0' <= c && c <= '9';
305}
306
307 RBIMPL_ATTR_CONST()
308 RBIMPL_ATTR_CONSTEXPR(CXX11)
309 RBIMPL_ATTR_ARTIFICIAL()
325static inline int
326rb_isalnum(int c)
327{
328 return rb_isalpha(c) || rb_isdigit(c);
329}
330
331 RBIMPL_ATTR_CONST()
332 RBIMPL_ATTR_CONSTEXPR(CXX11)
333 RBIMPL_ATTR_ARTIFICIAL()
348static inline int
349rb_isxdigit(int c)
350{
351 return rb_isdigit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f');
352}
353
354 RBIMPL_ATTR_CONST()
355 RBIMPL_ATTR_CONSTEXPR(CXX11)
356 RBIMPL_ATTR_ARTIFICIAL()
371static inline int
372rb_isblank(int c)
373{
374 return c == ' ' || c == '\t';
375}
376
377 RBIMPL_ATTR_CONST()
378 RBIMPL_ATTR_CONSTEXPR(CXX11)
379 RBIMPL_ATTR_ARTIFICIAL()
394static inline int
395rb_isspace(int c)
396{
397 return c == ' ' || ('\t' <= c && c <= '\r');
398}
399
400 RBIMPL_ATTR_CONST()
401 RBIMPL_ATTR_CONSTEXPR(CXX11)
402 RBIMPL_ATTR_ARTIFICIAL()
417static inline int
418rb_iscntrl(int c)
419{
420 return ('\0' <= c && c < ' ') || c == '\x7f';
421}
422
423 RBIMPL_ATTR_CONST()
424 RBIMPL_ATTR_CONSTEXPR(CXX11)
425 RBIMPL_ATTR_ARTIFICIAL()
441static inline int
442rb_isprint(int c)
443{
444 return ' ' <= c && c <= '\x7e';
445}
446
447 RBIMPL_ATTR_CONST()
448 RBIMPL_ATTR_CONSTEXPR(CXX11)
449 RBIMPL_ATTR_ARTIFICIAL()
464static inline int
465rb_ispunct(int c)
466{
467 return !rb_isalnum(c);
468}
469
470 RBIMPL_ATTR_CONST()
471 RBIMPL_ATTR_CONSTEXPR(CXX11)
472 RBIMPL_ATTR_ARTIFICIAL()
488static inline int
489rb_isgraph(int c)
490{
491 return '!' <= c && c <= '\x7e';
492}
493
494 RBIMPL_ATTR_CONST()
495 RBIMPL_ATTR_CONSTEXPR(CXX11)
496 RBIMPL_ATTR_ARTIFICIAL()
513static inline int
514rb_tolower(int c)
515{
516 return rb_isupper(c) ? (c|0x20) : c;
517}
518
519 RBIMPL_ATTR_CONST()
520 RBIMPL_ATTR_CONSTEXPR(CXX11)
521 RBIMPL_ATTR_ARTIFICIAL()
538static inline int
539rb_toupper(int c)
540{
541 return rb_islower(c) ? (c&0x5f) : c;
542}
543
545#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:74
ctype.h
Our own, locale independent, character handling routines.
rb_isdigit
static int rb_isdigit(int c)
Our own locale-insensitive version of isdigit(3).
Definition ctype.h:302
rb_isupper
static int rb_isupper(int c)
Our own locale-insensitive version of isupper(3).
Definition ctype.h:232
rb_iscntrl
static int rb_iscntrl(int c)
Our own locale-insensitive version of iscntrl(3).
Definition ctype.h:418
rb_ispunct
static int rb_ispunct(int c)
Our own locale-insensitive version of ispunct(3).
Definition ctype.h:465
rb_isalnum
static int rb_isalnum(int c)
Our own locale-insensitive version of isalnum(3).
Definition ctype.h:326
rb_isxdigit
static int rb_isxdigit(int c)
Our own locale-insensitive version of isxdigit(3).
Definition ctype.h:349
rb_isspace
static int rb_isspace(int c)
Our own locale-insensitive version of isspace(3).
Definition ctype.h:395
rb_isascii
static int rb_isascii(int c)
Our own locale-insensitive version of isascii(3).
Definition ctype.h:209
rb_toupper
static int rb_toupper(int c)
Our own locale-insensitive version of toupper(3).
Definition ctype.h:539
ruby_strtoul
unsigned long ruby_strtoul(const char *str, char **endptr, int base)
Our own locale-insensitive version of strtoul(3).
Definition util.c:138
rb_tolower
static int rb_tolower(int c)
Our own locale-insensitive version of tolower(3).
Definition ctype.h:514
rb_isgraph
static int rb_isgraph(int c)
Our own locale-insensitive version of isgraph(3).
Definition ctype.h:489
rb_isalpha
static int rb_isalpha(int c)
Our own locale-insensitive version of isalpha(3).
Definition ctype.h:279
rb_islower
static int rb_islower(int c)
Our own locale-insensitive version of islower(3).
Definition ctype.h:255
rb_isprint
static int rb_isprint(int c)
Identical to rb_isgraph(), except it also returns true for ‘’ '`.
Definition ctype.h:442
rb_isblank
static int rb_isblank(int c)
Our own locale-insensitive version of isblank(3).
Definition ctype.h:372
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
nonnull.h
Defines RBIMPL_ATTR_NONNULL.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition nonnull.h:30
inline
#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