| 1 |
#ifndef RUBY_INTERNAL_ENCODING_CTYPE_H /*-*-C++-*-vi:se ft=cpp:*/ |
| 2 |
#define RUBY_INTERNAL_ENCODING_CTYPE_H |
| 3 |
/** |
| 4 |
* @file |
| 5 |
* @author Ruby developers <[email protected]> |
| 6 |
* @copyright This file is a part of the programming language Ruby. |
| 7 |
* Permission is hereby granted, to either redistribute and/or |
| 8 |
* modify this file, provided that the conditions mentioned in the |
| 9 |
* file COPYING are met. Consult the file for details. |
| 10 |
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are |
| 11 |
* implementation details. Don't take them as canon. They could |
| 12 |
* rapidly appear then vanish. The name (path) of this header file |
| 13 |
* is also an implementation detail. Do not expect it to persist |
| 14 |
* at the place it is now. Developers are free to move it anywhere |
| 15 |
* anytime at will. |
| 16 |
* @note To ruby-core: remember that this header can be possibly |
| 17 |
* recursively included from extension libraries written in C++. |
| 18 |
* Do not expect for instance `__VA_ARGS__` is always available. |
| 19 |
* We assume C99 for ruby itself but we don't assume languages of |
| 20 |
* extension libraries. They could be written in C++98. |
| 21 |
* @brief Routines to query chacater types. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "ruby/onigmo.h" |
| 25 |
#include "ruby/internal/attr/const.h" |
| 26 |
#include "ruby/internal/dllexport.h" |
| 27 |
#include "ruby/internal/encoding/encoding.h" |
| 28 |
#include "ruby/internal/value.h" |
| 29 |
|
| 30 |
RBIMPL_SYMBOL_EXPORT_BEGIN() |
| 31 |
|
| 32 |
/** |
| 33 |
* Queries if the passed pointer points to a newline character. What is a |
| 34 |
* newline and what is not depends on the passed encoding. |
| 35 |
* |
| 36 |
* @param[in] p Pointer to a possibly-middle of a character. |
| 37 |
* @param[in] end End of the string. |
| 38 |
* @param[in] enc Encoding. |
| 39 |
* @retval false It isn't. |
| 40 |
* @retval true It is. |
| 41 |
*/ |
| 42 |
static inline bool |
| 43 |
rb_enc_is_newline(const char *p, const char *e, rb_encoding *enc) |
| 44 |
{ |
| 45 |
OnigUChar *up = RBIMPL_CAST((OnigUChar *)p); |
| 46 |
OnigUChar *ue = RBIMPL_CAST((OnigUChar *)e); |
| 47 |
|
| 48 |
return ONIGENC_IS_MBC_NEWLINE(enc, up, ue); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Queries if the passed code point is of passed character type in the passed |
| 53 |
* encoding. The "character type" here is a set of macros defined in onigmo.h, |
| 54 |
* like `ONIGENC_CTYPE_PUNCT`. |
| 55 |
* |
| 56 |
* @param[in] c An `OnigCodePoint` value. |
| 57 |
* @param[in] t An `OnigCtype` value. |
| 58 |
* @param[in] enc A `rb_encoding*` value. |
| 59 |
* @retval true `c` is of `t` in `enc`. |
| 60 |
* @retval false Otherwise. |
| 61 |
*/ |
| 62 |
static inline bool |
| 63 |
rb_enc_isctype(OnigCodePoint c, OnigCtype t, rb_encoding *enc) |
| 64 |
{ |
| 65 |
return ONIGENC_IS_CODE_CTYPE(enc, c, t); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Identical to rb_isascii(), except it additionally takes an encoding. |
| 70 |
* |
| 71 |
* @param[in] c A code point. |
| 72 |
* @param[in] enc An encoding. |
| 73 |
* @retval false `c` is out of range of ASCII character set in `enc`. |
| 74 |
* @retval true Otherwise. |
| 75 |
* |
| 76 |
* @internal |
| 77 |
* |
| 78 |
* `enc` is ignored. This is at least an intentional implementation detail |
| 79 |
* (not a bug). But there could be rooms for future extensions. |
| 80 |
*/ |
| 81 |
static inline bool |
| 82 |
rb_enc_isascii(OnigCodePoint c, rb_encoding *enc) |
| 83 |
{ |
| 84 |
return ONIGENC_IS_CODE_ASCII(c); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Identical to rb_isalpha(), except it additionally takes an encoding. |
| 89 |
* |
| 90 |
* @param[in] c A code point. |
| 91 |
* @param[in] enc An encoding. |
| 92 |
* @retval true `enc` classifies `c` as "ALPHA". |
| 93 |
* @retval false Otherwise. |
| 94 |
*/ |
| 95 |
static inline bool |
| 96 |
rb_enc_isalpha(OnigCodePoint c, rb_encoding *enc) |
| 97 |
{ |
| 98 |
return ONIGENC_IS_CODE_ALPHA(enc, c); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Identical to rb_islower(), except it additionally takes an encoding. |
| 103 |
* |
| 104 |
* @param[in] c A code point. |
| 105 |
* @param[in] enc An encoding. |
| 106 |
* @retval true `enc` classifies `c` as "LOWER". |
| 107 |
* @retval false Otherwise. |
| 108 |
*/ |
| 109 |
static inline bool |
| 110 |
rb_enc_islower(OnigCodePoint c, rb_encoding *enc) |
| 111 |
{ |
| 112 |
return ONIGENC_IS_CODE_LOWER(enc, c); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Identical to rb_isupper(), except it additionally takes an encoding. |
| 117 |
* |
| 118 |
* @param[in] c A code point. |
| 119 |
* @param[in] enc An encoding. |
| 120 |
* @retval true `enc` classifies `c` as "UPPER". |
| 121 |
* @retval false Otherwise. |
| 122 |
*/ |
| 123 |
static inline bool |
| 124 |
rb_enc_isupper(OnigCodePoint c, rb_encoding *enc) |
| 125 |
{ |
| 126 |
return ONIGENC_IS_CODE_UPPER(enc, c); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Identical to rb_iscntrl(), except it additionally takes an encoding. |
| 131 |
* |
| 132 |
* @param[in] c A code point. |
| 133 |
* @param[in] enc An encoding. |
| 134 |
* @retval true `enc` classifies `c` as "CNTRL". |
| 135 |
* @retval false Otherwise. |
| 136 |
*/ |
| 137 |
static inline bool |
| 138 |
rb_enc_iscntrl(OnigCodePoint c, rb_encoding *enc) |
| 139 |
{ |
| 140 |
return ONIGENC_IS_CODE_CNTRL(enc, c); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Identical to rb_ispunct(), except it additionally takes an encoding. |
| 145 |
* |
| 146 |
* @param[in] c A code point. |
| 147 |
* @param[in] enc An encoding. |
| 148 |
* @retval true `enc` classifies `c` as "PUNCT". |
| 149 |
* @retval false Otherwise. |
| 150 |
*/ |
| 151 |
static inline bool |
| 152 |
rb_enc_ispunct(OnigCodePoint c, rb_encoding *enc) |
| 153 |
{ |
| 154 |
return ONIGENC_IS_CODE_PUNCT(enc, c); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Identical to rb_isalnum(), except it additionally takes an encoding. |
| 159 |
* |
| 160 |
* @param[in] c A code point. |
| 161 |
* @param[in] enc An encoding. |
| 162 |
* @retval true `enc` classifies `c` as "ANUM". |
| 163 |
* @retval false Otherwise. |
| 164 |
*/ |
| 165 |
static inline bool |
| 166 |
rb_enc_isalnum(OnigCodePoint c, rb_encoding *enc) |
| 167 |
{ |
| 168 |
return ONIGENC_IS_CODE_ALNUM(enc, c); |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Identical to rb_isprint(), except it additionally takes an encoding. |
| 173 |
* |
| 174 |
* @param[in] c A code point. |
| 175 |
* @param[in] enc An encoding. |
| 176 |
* @retval true `enc` classifies `c` as "PRINT". |
| 177 |
* @retval false Otherwise. |
| 178 |
*/ |
| 179 |
static inline bool |
| 180 |
rb_enc_isprint(OnigCodePoint c, rb_encoding *enc) |
| 181 |
{ |
| 182 |
return ONIGENC_IS_CODE_PRINT(enc, c); |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Identical to rb_isspace(), except it additionally takes an encoding. |
| 187 |
* |
| 188 |
* @param[in] c A code point. |
| 189 |
* @param[in] enc An encoding. |
| 190 |
* @retval true `enc` classifies `c` as "PRINT". |
| 191 |
* @retval false Otherwise. |
| 192 |
*/ |
| 193 |
static inline bool |
| 194 |
rb_enc_isspace(OnigCodePoint c, rb_encoding *enc) |
| 195 |
{ |
| 196 |
return ONIGENC_IS_CODE_SPACE(enc, c); |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Identical to rb_isdigit(), except it additionally takes an encoding. |
| 201 |
* |
| 202 |
* @param[in] c A code point. |
| 203 |
* @param[in] enc An encoding. |
| 204 |
* @retval true `enc` classifies `c` as "DIGIT". |
| 205 |
* @retval false Otherwise. |
| 206 |
*/ |
| 207 |
static inline bool |
| 208 |
rb_enc_isdigit(OnigCodePoint c, rb_encoding *enc) |
| 209 |
{ |
| 210 |
return ONIGENC_IS_CODE_DIGIT(enc, c); |
| 211 |
} |
| 212 |
|
| 213 |
RBIMPL_ATTR_CONST() |
| 214 |
/** |
| 215 |
* Identical to rb_toupper(), except it additionally takes an encoding. |
| 216 |
* |
| 217 |
* @param[in] c A code point. |
| 218 |
* @param[in] enc An encoding. |
| 219 |
* @return `c`'s (Ruby's definition of) upper case counterpart. |
| 220 |
* |
| 221 |
* @internal |
| 222 |
* |
| 223 |
* As `RBIMPL_ATTR_CONST` implies this function ignores `enc`. |
| 224 |
*/ |
| 225 |
int rb_enc_toupper(int c, rb_encoding *enc); |
| 226 |
|
| 227 |
RBIMPL_ATTR_CONST() |
| 228 |
/** |
| 229 |
* Identical to rb_tolower(), except it additionally takes an encoding. |
| 230 |
* |
| 231 |
* @param[in] c A code point. |
| 232 |
* @param[in] enc An encoding. |
| 233 |
* @return `c`'s (Ruby's definition of) lower case counterpart. |
| 234 |
* |
| 235 |
* @internal |
| 236 |
* |
| 237 |
* As `RBIMPL_ATTR_CONST` implies this function ignores `enc`. |
| 238 |
*/ |
| 239 |
int rb_enc_tolower(int c, rb_encoding *enc); |
| 240 |
|
| 241 |
RBIMPL_SYMBOL_EXPORT_END() |
| 242 |
|
| 243 |
/** @cond INTERNAL_MACRO */ |
| 244 |
#define rb_enc_is_newline rb_enc_is_newline |
| 245 |
#define rb_enc_isalnum rb_enc_isalnum |
| 246 |
#define rb_enc_isalpha rb_enc_isalpha |
| 247 |
#define rb_enc_isascii rb_enc_isascii |
| 248 |
#define rb_enc_isctype rb_enc_isctype |
| 249 |
#define rb_enc_isdigit rb_enc_isdigit |
| 250 |
#define rb_enc_islower rb_enc_islower |
| 251 |
#define rb_enc_isprint rb_enc_isprint |
| 252 |
#define rb_enc_iscntrl rb_enc_iscntrl |
| 253 |
#define rb_enc_ispunct rb_enc_ispunct |
| 254 |
#define rb_enc_isspace rb_enc_isspace |
| 255 |
#define rb_enc_isupper rb_enc_isupper |
| 256 |
/** @endcond */ |
| 257 |
|
| 258 |
#endif /* RUBY_INTERNAL_ENCODING_CTYPE_H */ |