| 1 |
#ifndef RUBY_INTERNAL_ENCODING_SYMBOL_H /*-*-C++-*-vi:se ft=cpp:*/ |
| 2 |
#define RUBY_INTERNAL_ENCODING_SYMBOL_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 manipulate encodings of symbols. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "ruby/internal/attr/nonnull.h" |
| 25 |
#include "ruby/internal/dllexport.h" |
| 26 |
#include "ruby/internal/encoding/encoding.h" |
| 27 |
#include "ruby/internal/value.h" |
| 28 |
|
| 29 |
RBIMPL_SYMBOL_EXPORT_BEGIN() |
| 30 |
|
| 31 |
/** |
| 32 |
* Identical to rb_intern2(), except it additionally takes an encoding. |
| 33 |
* |
| 34 |
* @param[in] name The name of the id. |
| 35 |
* @param[in] len Length of `name`. |
| 36 |
* @param[in] enc `name`'s encoding. |
| 37 |
* @exception rb_eRuntimeError Too many symbols. |
| 38 |
* @return A (possibly new) id whose value is the given name. |
| 39 |
* @note These days Ruby internally has two kinds of symbols |
| 40 |
* (static/dynamic). Symbols created using this function would |
| 41 |
* become static ones; i.e. would never be garbage collected. It |
| 42 |
* is up to you to avoid memory leaks. Think twice before using |
| 43 |
* it. |
| 44 |
*/ |
| 45 |
ID rb_intern3(const char *name, long len, rb_encoding *enc); |
| 46 |
|
| 47 |
RBIMPL_ATTR_NONNULL(()) |
| 48 |
/** |
| 49 |
* Identical to rb_symname_p(), except it additionally takes an encoding. |
| 50 |
* |
| 51 |
* @param[in] str A C string to check. |
| 52 |
* @param[in] enc `str`'s encoding. |
| 53 |
* @retval 1 It is a valid symbol name. |
| 54 |
* @retval 0 It is invalid as a symbol name. |
| 55 |
*/ |
| 56 |
int rb_enc_symname_p(const char *str, rb_encoding *enc); |
| 57 |
|
| 58 |
/** |
| 59 |
* Identical to rb_enc_symname_p(), except it additionally takes the passed |
| 60 |
* string's length. This is needed for strings containing NUL bytes, like in |
| 61 |
* case of UTF-32. |
| 62 |
* |
| 63 |
* @param[in] name A C string to check. |
| 64 |
* @param[in] len Number of bytes of `str`. |
| 65 |
* @param[in] enc `str`'s encoding. |
| 66 |
* @retval 1 It is a valid symbol name. |
| 67 |
* @retval 0 It is invalid as a symbol name. |
| 68 |
*/ |
| 69 |
int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc); |
| 70 |
|
| 71 |
/** |
| 72 |
* Identical to rb_check_id(), except it takes a pointer to a memory region |
| 73 |
* instead of Ruby's string. |
| 74 |
* |
| 75 |
* @param[in] ptr A pointer to a memory region. |
| 76 |
* @param[in] len Number of bytes of `ptr`. |
| 77 |
* @param[in] enc Encoding of `ptr`. |
| 78 |
* @exception rb_eEncodingError `ptr` contains non-ASCII according to `enc`. |
| 79 |
* @retval 0 No such id ever existed in the history. |
| 80 |
* @retval otherwise The id that represents the given name. |
| 81 |
*/ |
| 82 |
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc); |
| 83 |
|
| 84 |
/** |
| 85 |
* Identical to rb_check_id_cstr(), except for the return type. It can also be |
| 86 |
* seen as a routine identical to rb_check_symbol(), except it takes a pointer |
| 87 |
* to a memory region instead of Ruby's string. |
| 88 |
* |
| 89 |
* @param[in] ptr A pointer to a memory region. |
| 90 |
* @param[in] len Number of bytes of `ptr`. |
| 91 |
* @param[in] enc Encoding of `ptr`. |
| 92 |
* @exception rb_eEncodingError `ptr` contains non-ASCII according to `enc`. |
| 93 |
* @retval RUBY_Qnil No such id ever existed in the history. |
| 94 |
* @retval otherwise The id that represents the given name. |
| 95 |
*/ |
| 96 |
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc); |
| 97 |
|
| 98 |
RBIMPL_SYMBOL_EXPORT_END() |
| 99 |
|
| 100 |
#endif /* RUBY_INTERNAL_ENCODING_SYMBOL_H */ |