summaryrefslogtreecommitdiff
path: root/include/ruby/internal/encoding
diff options
context:
space:
mode:
Diffstat (limited to 'include/ruby/internal/encoding')
-rw-r--r--include/ruby/internal/encoding/ctype.h101
-rw-r--r--include/ruby/internal/encoding/encoding.h31
-rw-r--r--include/ruby/internal/encoding/transcode.h18
3 files changed, 73 insertions, 77 deletions
diff --git a/include/ruby/internal/encoding/ctype.h b/include/ruby/internal/encoding/ctype.h
index 05c314aeb3..64aaf0a990 100644
--- a/include/ruby/internal/encoding/ctype.h
+++ b/include/ruby/internal/encoding/ctype.h
@@ -36,8 +36,8 @@ RBIMPL_SYMBOL_EXPORT_BEGIN()
* @param[in] p Pointer to a possibly-middle of a character.
* @param[in] end End of the string.
* @param[in] enc Encoding.
- * @retval false It isn't.
- * @retval true It is.
+ * @retval 0 It isn't.
+ * @retval otherwise It is.
*/
static inline bool
rb_enc_is_newline(const char *p, const char *e, rb_encoding *enc)
@@ -53,11 +53,11 @@ rb_enc_is_newline(const char *p, const char *e, rb_encoding *enc)
* encoding. The "character type" here is a set of macros defined in onigmo.h,
* like `ONIGENC_CTYPE_PUNCT`.
*
- * @param[in] c An `OnigCodePoint` value.
- * @param[in] t An `OnigCtype` value.
- * @param[in] enc A `rb_encoding*` value.
- * @retval true `c` is of `t` in `enc`.
- * @retval false Otherwise.
+ * @param[in] c An `OnigCodePoint` value.
+ * @param[in] t An `OnigCtype` value.
+ * @param[in] enc A `rb_encoding*` value.
+ * @retval 1 `c` is of `t` in `enc`.
+ * @retval 0 Otherwise.
*/
static inline bool
rb_enc_isctype(OnigCodePoint c, OnigCtype t, rb_encoding *enc)
@@ -68,10 +68,10 @@ rb_enc_isctype(OnigCodePoint c, OnigCtype t, rb_encoding *enc)
/**
* Identical to rb_isascii(), except it additionally takes an encoding.
*
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval false `c` is out of range of ASCII character set in `enc`.
- * @retval true Otherwise.
+ * @param[in] c A code point.
+ * @param[in] enc An encoding.
+ * @retval 0 `c` is out of range of ASCII character set in `enc`.
+ * @retval 1 Otherwise.
*
* @internal
*
@@ -87,10 +87,10 @@ rb_enc_isascii(OnigCodePoint c, rb_encoding *enc)
/**
* Identical to rb_isalpha(), except it additionally takes an encoding.
*
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval true `enc` classifies `c` as "ALPHA".
- * @retval false Otherwise.
+ * @param[in] c A code point.
+ * @param[in] enc An encoding.
+ * @retval 1 `enc` classifies `c` as "ALPHA".
+ * @retval 0 Otherwise.
*/
static inline bool
rb_enc_isalpha(OnigCodePoint c, rb_encoding *enc)
@@ -101,10 +101,10 @@ rb_enc_isalpha(OnigCodePoint c, rb_encoding *enc)
/**
* Identical to rb_islower(), except it additionally takes an encoding.
*
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval true `enc` classifies `c` as "LOWER".
- * @retval false Otherwise.
+ * @param[in] c A code point.
+ * @param[in] enc An encoding.
+ * @retval 1 `enc` classifies `c` as "LOWER".
+ * @retval 0 Otherwise.
*/
static inline bool
rb_enc_islower(OnigCodePoint c, rb_encoding *enc)
@@ -115,10 +115,10 @@ rb_enc_islower(OnigCodePoint c, rb_encoding *enc)
/**
* Identical to rb_isupper(), except it additionally takes an encoding.
*
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval true `enc` classifies `c` as "UPPER".
- * @retval false Otherwise.
+ * @param[in] c A code point.
+ * @param[in] enc An encoding.
+ * @retval 1 `enc` classifies `c` as "UPPER".
+ * @retval 0 Otherwise.
*/
static inline bool
rb_enc_isupper(OnigCodePoint c, rb_encoding *enc)
@@ -127,26 +127,12 @@ rb_enc_isupper(OnigCodePoint c, rb_encoding *enc)
}
/**
- * Identical to rb_iscntrl(), except it additionally takes an encoding.
- *
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval true `enc` classifies `c` as "CNTRL".
- * @retval false Otherwise.
- */
-static inline bool
-rb_enc_iscntrl(OnigCodePoint c, rb_encoding *enc)
-{
- return ONIGENC_IS_CODE_CNTRL(enc, c);
-}
-
-/**
* Identical to rb_ispunct(), except it additionally takes an encoding.
*
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval true `enc` classifies `c` as "PUNCT".
- * @retval false Otherwise.
+ * @param[in] c A code point.
+ * @param[in] enc An encoding.
+ * @retval 1 `enc` classifies `c` as "PUNCT".
+ * @retval 0 Otherwise.
*/
static inline bool
rb_enc_ispunct(OnigCodePoint c, rb_encoding *enc)
@@ -157,10 +143,10 @@ rb_enc_ispunct(OnigCodePoint c, rb_encoding *enc)
/**
* Identical to rb_isalnum(), except it additionally takes an encoding.
*
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval true `enc` classifies `c` as "ANUM".
- * @retval false Otherwise.
+ * @param[in] c A code point.
+ * @param[in] enc An encoding.
+ * @retval 1 `enc` classifies `c` as "ANUM".
+ * @retval 0 Otherwise.
*/
static inline bool
rb_enc_isalnum(OnigCodePoint c, rb_encoding *enc)
@@ -171,10 +157,10 @@ rb_enc_isalnum(OnigCodePoint c, rb_encoding *enc)
/**
* Identical to rb_isprint(), except it additionally takes an encoding.
*
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval true `enc` classifies `c` as "PRINT".
- * @retval false Otherwise.
+ * @param[in] c A code point.
+ * @param[in] enc An encoding.
+ * @retval 1 `enc` classifies `c` as "PRINT".
+ * @retval 0 Otherwise.
*/
static inline bool
rb_enc_isprint(OnigCodePoint c, rb_encoding *enc)
@@ -185,10 +171,10 @@ rb_enc_isprint(OnigCodePoint c, rb_encoding *enc)
/**
* Identical to rb_isspace(), except it additionally takes an encoding.
*
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval true `enc` classifies `c` as "PRINT".
- * @retval false Otherwise.
+ * @param[in] c A code point.
+ * @param[in] enc An encoding.
+ * @retval 1 `enc` classifies `c` as "PRINT".
+ * @retval 0 Otherwise.
*/
static inline bool
rb_enc_isspace(OnigCodePoint c, rb_encoding *enc)
@@ -199,10 +185,10 @@ rb_enc_isspace(OnigCodePoint c, rb_encoding *enc)
/**
* Identical to rb_isdigit(), except it additionally takes an encoding.
*
- * @param[in] c A code point.
- * @param[in] enc An encoding.
- * @retval true `enc` classifies `c` as "DIGIT".
- * @retval false Otherwise.
+ * @param[in] c A code point.
+ * @param[in] enc An encoding.
+ * @retval 1 `enc` classifies `c` as "DIGIT".
+ * @retval 0 Otherwise.
*/
static inline bool
rb_enc_isdigit(OnigCodePoint c, rb_encoding *enc)
@@ -249,7 +235,6 @@ RBIMPL_SYMBOL_EXPORT_END()
#define rb_enc_isdigit rb_enc_isdigit
#define rb_enc_islower rb_enc_islower
#define rb_enc_isprint rb_enc_isprint
-#define rb_enc_iscntrl rb_enc_iscntrl
#define rb_enc_ispunct rb_enc_ispunct
#define rb_enc_isspace rb_enc_isspace
#define rb_enc_isupper rb_enc_isupper
diff --git a/include/ruby/internal/encoding/encoding.h b/include/ruby/internal/encoding/encoding.h
index dc3e0151f0..9208d27ecf 100644
--- a/include/ruby/internal/encoding/encoding.h
+++ b/include/ruby/internal/encoding/encoding.h
@@ -139,6 +139,23 @@ 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
@@ -358,8 +375,8 @@ rb_encoding *rb_enc_check(VALUE str1,VALUE str2);
VALUE rb_enc_associate_index(VALUE obj, int encindex);
/**
- * Identical to rb_enc_associate_index(), except it takes an encoding itself
- * instead of its index.
+ * Identical to rb_enc_associate(), except it takes an encoding itself instead
+ * of its index.
*
* @param[out] obj Object in question.
* @param[in] enc An encoding.
@@ -626,12 +643,10 @@ rb_enc_code_to_mbclen(int c, 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.
- * @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`.
+ * @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`.
*
* @internal
*
diff --git a/include/ruby/internal/encoding/transcode.h b/include/ruby/internal/encoding/transcode.h
index 7f26d2eae9..60c96a41c9 100644
--- a/include/ruby/internal/encoding/transcode.h
+++ b/include/ruby/internal/encoding/transcode.h
@@ -476,16 +476,16 @@ enum ruby_econv_flag_type {
RUBY_ECONV_UNDEF_HEX_CHARREF = 0x00000030,
/** Decorators are there. */
- RUBY_ECONV_DECORATOR_MASK = 0x0001ff00,
+ RUBY_ECONV_DECORATOR_MASK = 0x0000ff00,
/** Newline converters are there. */
- RUBY_ECONV_NEWLINE_DECORATOR_MASK = 0x00007f00,
+ RUBY_ECONV_NEWLINE_DECORATOR_MASK = 0x00003f00,
/** (Unclear; seems unused). */
RUBY_ECONV_NEWLINE_DECORATOR_READ_MASK = 0x00000f00,
/** (Unclear; seems unused). */
- RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK = 0x00007000,
+ RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK = 0x00003000,
/** Universal newline mode. */
RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR = 0x00000100,
@@ -496,14 +496,11 @@ enum ruby_econv_flag_type {
/** CRLF to CR conversion shall happen. */
RUBY_ECONV_CR_NEWLINE_DECORATOR = 0x00002000,
- /** CRLF to LF conversion shall happen. */
- RUBY_ECONV_LF_NEWLINE_DECORATOR = 0x00004000,
-
/** Texts shall be XML-escaped. */
- RUBY_ECONV_XML_TEXT_DECORATOR = 0x00008000,
+ RUBY_ECONV_XML_TEXT_DECORATOR = 0x00004000,
/** Texts shall be AttrValue escaped */
- RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR = 0x00010000,
+ RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR = 0x00008000,
/** (Unclear; seems unused). */
RUBY_ECONV_STATEFUL_DECORATOR_MASK = 0x00f00000,
@@ -532,7 +529,6 @@ enum ruby_econv_flag_type {
#define ECONV_UNIVERSAL_NEWLINE_DECORATOR RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR /**< @old{RUBY_ECONV_UNIVERSAL_NEWLINE_DECORATOR} */
#define ECONV_CRLF_NEWLINE_DECORATOR RUBY_ECONV_CRLF_NEWLINE_DECORATOR /**< @old{RUBY_ECONV_CRLF_NEWLINE_DECORATOR} */
#define ECONV_CR_NEWLINE_DECORATOR RUBY_ECONV_CR_NEWLINE_DECORATOR /**< @old{RUBY_ECONV_CR_NEWLINE_DECORATOR} */
-#define ECONV_LF_NEWLINE_DECORATOR RUBY_ECONV_LF_NEWLINE_DECORATOR /**< @old{RUBY_ECONV_LF_NEWLINE_DECORATOR} */
#define ECONV_XML_TEXT_DECORATOR RUBY_ECONV_XML_TEXT_DECORATOR /**< @old{RUBY_ECONV_XML_TEXT_DECORATOR} */
#define ECONV_XML_ATTR_CONTENT_DECORATOR RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR /**< @old{RUBY_ECONV_XML_ATTR_CONTENT_DECORATOR} */
#define ECONV_STATEFUL_DECORATOR_MASK RUBY_ECONV_STATEFUL_DECORATOR_MASK /**< @old{RUBY_ECONV_STATEFUL_DECORATOR_MASK} */
@@ -547,10 +543,10 @@ enum ruby_econv_flag_type {
*/
/** Indicates the input is a part of much larger one. */
- RUBY_ECONV_PARTIAL_INPUT = 0x00020000,
+ RUBY_ECONV_PARTIAL_INPUT = 0x00010000,
/** Instructs the converter to stop after output. */
- RUBY_ECONV_AFTER_OUTPUT = 0x00040000,
+ RUBY_ECONV_AFTER_OUTPUT = 0x00020000,
#define ECONV_PARTIAL_INPUT RUBY_ECONV_PARTIAL_INPUT /**< @old{RUBY_ECONV_PARTIAL_INPUT} */
#define ECONV_AFTER_OUTPUT RUBY_ECONV_AFTER_OUTPUT /**< @old{RUBY_ECONV_AFTER_OUTPUT} */