summaryrefslogtreecommitdiff
path: root/include/ruby/internal/encoding/encoding.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/ruby/internal/encoding/encoding.h')
-rw-r--r--include/ruby/internal/encoding/encoding.h68
1 files changed, 27 insertions, 41 deletions
diff --git a/include/ruby/internal/encoding/encoding.h b/include/ruby/internal/encoding/encoding.h
index b4274b7f55..a58f9f2b15 100644
--- a/include/ruby/internal/encoding/encoding.h
+++ b/include/ruby/internal/encoding/encoding.h
@@ -28,6 +28,7 @@
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/attr/returns_nonnull.h"
#include "ruby/internal/dllexport.h"
+#include "ruby/internal/encoding/coderange.h"
#include "ruby/internal/value.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/fl_type.h"
@@ -65,21 +66,21 @@ enum ruby_encoding_consts {
#define ENCODING_INLINE_MAX RUBY_ENCODING_INLINE_MAX /**< @old{RUBY_ENCODING_INLINE_MAX} */
#define ENCODING_SHIFT RUBY_ENCODING_SHIFT /**< @old{RUBY_ENCODING_SHIFT} */
-#define ENCODING_MASK RUBY_ENCODING_MASK /**< @old{RUBY_ENCODING_SHIFT} */
+#define ENCODING_MASK RUBY_ENCODING_MASK /**< @old{RUBY_ENCODING_MASK} */
/**
* Destructively assigns the passed encoding to the passed object. The object
* must be capable of having inline encoding. Using this macro needs deep
* understanding of bit level object binary layout.
*
- * @param[out] obj Target object to modify.
- * @param[in] i Encoding in encindex format.
- * @post `obj`'s encoding is `i`.
+ * @param[out] obj Target object to modify.
+ * @param[in] ecindex Encoding in encindex format.
+ * @post `obj`'s encoding is `encindex`.
*/
static inline void
RB_ENCODING_SET_INLINED(VALUE obj, int encindex)
{
- VALUE f = /* upcast */ encindex;
+ VALUE f = /* upcast */ RBIMPL_CAST((VALUE)encindex);
f <<= RUBY_ENCODING_SHIFT;
RB_FL_UNSET_RAW(obj, RUBY_ENCODING_MASK);
@@ -139,23 +140,6 @@ RBIMPL_ATTR_NOALIAS()
int rb_char_to_option_kcode(int c, int *option, int *kcode);
/**
- * Creates a new encoding, using the passed one as a template.
- *
- * @param[in] name Name of the creating encoding.
- * @param[in] src Template.
- * @exception rb_eArgError Duplicated or malformed `name`.
- * @return Replicated new encoding's index.
- * @post Encoding named `name` is created as a copy of `src`, whose index
- * is the return value.
- *
- * @internal
- *
- * `name` can be `NULL`, but that just raises an exception. OTOH it seems no
- * sanity check is done against `src`...?
- */
-int rb_enc_replicate(const char *name, rb_encoding *src);
-
-/**
* Creates a new "dummy" encoding. Roughly speaking, an encoding is dummy when
* it is stateful. Notable example of dummy encoding are those defined in
* ISO/IEC 2022
@@ -375,8 +359,8 @@ rb_encoding *rb_enc_check(VALUE str1,VALUE str2);
VALUE rb_enc_associate_index(VALUE obj, int encindex);
/**
- * Identical to rb_enc_associate(), except it takes an encoding itself instead
- * of its index.
+ * Identical to rb_enc_associate_index(), except it takes an encoding itself
+ * instead of its index.
*
* @param[out] obj Object in question.
* @param[in] enc An encoding.
@@ -430,7 +414,7 @@ rb_encoding *rb_enc_find(const char *name);
* @return Its name.
*/
static inline const char *
-rb_enc_name(const rb_encoding *enc)
+rb_enc_name(rb_encoding *enc)
{
return enc->name;
}
@@ -445,7 +429,7 @@ rb_enc_name(const rb_encoding *enc)
* @return Its least possible number of bytes except 0.
*/
static inline int
-rb_enc_mbminlen(const rb_encoding *enc)
+rb_enc_mbminlen(rb_encoding *enc)
{
return enc->min_enc_len;
}
@@ -460,7 +444,7 @@ rb_enc_mbminlen(const rb_encoding *enc)
* @return Its maximum possible number of bytes of a character.
*/
static inline int
-rb_enc_mbmaxlen(const rb_encoding *enc)
+rb_enc_mbmaxlen(rb_encoding *enc)
{
return enc->max_enc_len;
}
@@ -604,7 +588,7 @@ rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc)
* @return Code point of the character pointed by `p`.
*/
static inline OnigCodePoint
-rb_enc_mbc_to_codepoint(const char *p, const char *e, const rb_encoding *enc)
+rb_enc_mbc_to_codepoint(const char *p, const char *e, rb_encoding *enc)
{
const OnigUChar *up = RBIMPL_CAST((const OnigUChar *)p);
const OnigUChar *ue = RBIMPL_CAST((const OnigUChar *)e);
@@ -626,13 +610,13 @@ int rb_enc_codelen(int code, rb_encoding *enc);
/**
* Identical to rb_enc_codelen(), except it returns 0 for invalid code points.
*
- * @param[in] code Code point in question.
- * @param[in] enc Encoding to convert the code into a byte sequence.
- * @retval 0 `code` is invalid.
- * @return otherwise Number of bytes used for `enc` to encode `code`.
+ * @param[in] c Code point in question.
+ * @param[in] enc Encoding to convert `c` into a byte sequence.
+ * @retval 0 `c` is invalid.
+ * @return otherwise Number of bytes needed for `enc` to encode `c`.
*/
static inline int
-rb_enc_code_to_mbclen(int c, const rb_encoding *enc)
+rb_enc_code_to_mbclen(int c, rb_encoding *enc)
{
OnigCodePoint uc = RBIMPL_CAST((OnigCodePoint)c);
@@ -643,10 +627,12 @@ rb_enc_code_to_mbclen(int c, const rb_encoding *enc)
* Identical to rb_enc_uint_chr(), except it writes back to the passed buffer
* instead of allocating one.
*
- * @param[in] c Code point.
- * @param[out] buf Return buffer.
- * @param[in] enc Target encoding scheme.
- * @post `c` is encoded according to `enc`, then written to `buf`.
+ * @param[in] c Code point.
+ * @param[out] buf Return buffer.
+ * @param[in] enc Target encoding scheme.
+ * @retval <= 0 `c` is invalid in `enc`.
+ * @return otherwise Number of bytes written to `buf`.
+ * @post `c` is encoded according to `enc`, then written to `buf`.
*
* @internal
*
@@ -654,7 +640,7 @@ rb_enc_code_to_mbclen(int c, const rb_encoding *enc)
* being any stricter than this. :FIXME:
*/
static inline int
-rb_enc_mbcput(unsigned int c, void *buf, const rb_encoding *enc)
+rb_enc_mbcput(unsigned int c, void *buf, rb_encoding *enc)
{
OnigCodePoint uc = RBIMPL_CAST((OnigCodePoint)c);
OnigUChar *ubuf = RBIMPL_CAST((OnigUChar *)buf);
@@ -673,7 +659,7 @@ rb_enc_mbcput(unsigned int c, void *buf, const rb_encoding *enc)
* @retval otherwise Pointer to the head of the previous character.
*/
static inline char *
-rb_enc_prev_char(const char *s, const char *p, const char *e, const rb_encoding *enc)
+rb_enc_prev_char(const char *s, const char *p, const char *e, rb_encoding *enc)
{
const OnigUChar *us = RBIMPL_CAST((const OnigUChar *)s);
const OnigUChar *up = RBIMPL_CAST((const OnigUChar *)p);
@@ -694,7 +680,7 @@ rb_enc_prev_char(const char *s, const char *p, const char *e, const rb_encoding
* @return Pointer to the head of the character that contains `p`.
*/
static inline char *
-rb_enc_left_char_head(const char *s, const char *p, const char *e, const rb_encoding *enc)
+rb_enc_left_char_head(const char *s, const char *p, const char *e, rb_encoding *enc)
{
const OnigUChar *us = RBIMPL_CAST((const OnigUChar *)s);
const OnigUChar *up = RBIMPL_CAST((const OnigUChar *)p);
@@ -737,7 +723,7 @@ rb_enc_right_char_head(const char *s, const char *p, const char *e, rb_encoding
* @retval otherwise Pointer to `n` character before `p`.
*/
static inline char *
-rb_enc_step_back(const char *s, const char *p, const char *e, int n, const rb_encoding *enc)
+rb_enc_step_back(const char *s, const char *p, const char *e, int n, rb_encoding *enc)
{
const OnigUChar *us = RBIMPL_CAST((const OnigUChar *)s);
const OnigUChar *up = RBIMPL_CAST((const OnigUChar *)p);