1#ifndef INTERNAL_STRING_H
2#define INTERNAL_STRING_H
11#include "ruby/internal/config.h"
13#include "internal/compilers.h"
19#define STR_SHARED FL_USER0
20#define STR_NOEMBED FL_USER1
21#define STR_CHILLED (FL_USER2 | FL_USER3)
22#define STR_CHILLED_LITERAL FL_USER2
23#define STR_CHILLED_SYMBOL_TO_S FL_USER3
25enum ruby_rstring_private_flags {
26 RSTRING_CHILLED = STR_CHILLED,
30# undef rb_fstring_cstr
34rb_str_encindex_fastpath(
int encindex)
44 case ENCINDEX_ASCII_8BIT:
46 case ENCINDEX_US_ASCII:
54rb_str_enc_fastpath(
VALUE str)
60rb_str_enc_get(
VALUE str)
69VALUE rb_fstring_cstr(
const char *str);
71int rb_str_buf_cat_escaped_char(
VALUE result,
unsigned int c,
int unicode_p);
72int rb_str_symname_p(
VALUE);
74char *rb_str_fill_terminator(
VALUE str,
const int termlen);
75void rb_str_change_terminator_length(
VALUE str,
const int oldtermlen,
const int termlen);
79VALUE rb_str_cat_conv_enc_opts(
VALUE newstr,
long ofs,
const char *ptr,
long len,
83size_t rb_str_memsize(
VALUE);
84char *rb_str_to_cstr(
VALUE str);
85const char *ruby_escaped_char(
int c);
86void rb_str_make_independent(
VALUE str);
88int rb_ascii8bit_appendable_encoding_index(
rb_encoding *enc,
unsigned int code);
92VALUE rb_str_tmp_frozen_no_embed_acquire(
VALUE str);
93void rb_str_make_embedded(
VALUE);
95size_t rb_str_size_as_embedded(
VALUE);
96bool rb_str_reembeddable_p(
VALUE);
100const char *rb_str_null_check(
VALUE);
103void rb_warn_unchilled_literal(
VALUE str);
104void rb_warn_unchilled_symbol_to_s(
VALUE str);
106static inline bool STR_EMBED_P(
VALUE str);
107static inline bool STR_SHARED_P(
VALUE str);
109static inline VALUE QUOTE_ID(
ID v);
110static inline bool is_ascii_string(
VALUE str);
111static inline bool is_broken_string(
VALUE str);
112static inline VALUE rb_str_eql_internal(
const VALUE str1,
const VALUE str2);
114RUBY_SYMBOL_EXPORT_BEGIN
117void rb_str_tmp_frozen_release(
VALUE str,
VALUE tmp);
119RUBY_SYMBOL_EXPORT_END
121VALUE rb_fstring_new(
const char *ptr,
long len);
122void rb_gc_free_fstring(
VALUE obj);
123bool rb_obj_is_fstring_table(
VALUE obj);
124void Init_fstring_table();
127VALUE rb_str_concat_literals(
size_t num,
const VALUE *strary);
129VALUE rb_id_quote_unprintable(
ID);
130VALUE rb_sym_proc_call(
ID mid,
int argc,
const VALUE *argv,
int kw_splat,
VALUE passed_proc);
136#define rb_fstring_lit(str) rb_fstring_new((str), rb_strlen_lit(str))
137#define rb_fstring_literal(str) rb_fstring_lit(str)
138#define rb_fstring_enc_lit(str, enc) rb_fstring_enc_new((str), rb_strlen_lit(str), (enc))
139#define rb_fstring_enc_literal(str, enc) rb_fstring_enc_lit(str, enc)
144 return rb_str_quote_unprintable(v);
150 return rb_id_quote_unprintable(i);
154STR_EMBED_P(
VALUE str)
160STR_SHARED_P(
VALUE str)
162 return FL_ALL_RAW(str, STR_NOEMBED | STR_SHARED);
166CHILLED_STRING_P(
VALUE obj)
172CHILLED_STRING_MUTATED(
VALUE str)
176 switch (chilled_reason) {
177 case STR_CHILLED_SYMBOL_TO_S:
178 rb_warn_unchilled_symbol_to_s(str);
180 case STR_CHILLED_LITERAL:
181 rb_warn_unchilled_literal(str);
184 rb_bug(
"RString was chilled for multiple reasons");
189is_ascii_string(
VALUE str)
195is_broken_string(
VALUE str)
201at_char_boundary(
const char *s,
const char *p,
const char *e,
rb_encoding *enc)
207at_char_right_boundary(
const char *s,
const char *p,
const char *e,
rb_encoding *enc)
218rb_str_eql_internal(
const VALUE str1,
const VALUE str2)
220 const long len = RSTRING_LEN(str1);
221 const char *ptr1, *ptr2;
223 if (
len != RSTRING_LEN(str2))
return Qfalse;
225 if ((ptr1 = RSTRING_PTR(str1)) == (ptr2 = RSTRING_PTR(str2)))
227 if (memcmp(ptr1, ptr2,
len) == 0)
232#if __has_builtin(__builtin_constant_p)
233# define rb_fstring_cstr(str) \
234 (__builtin_constant_p(str) ? \
235 rb_fstring_new((str), (long)strlen(str)) : \
236 (rb_fstring_cstr)(str))
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
static VALUE RB_FL_TEST_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_TEST().
#define ENC_CODERANGE_7BIT
Old name of RUBY_ENC_CODERANGE_7BIT.
#define FL_UNSET_RAW
Old name of RB_FL_UNSET_RAW.
#define T_STRING
Old name of RUBY_T_STRING.
#define ENCODING_GET(obj)
Old name of RB_ENCODING_GET.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define Qtrue
Old name of RUBY_Qtrue.
#define Qfalse
Old name of RUBY_Qfalse.
#define ENC_CODERANGE_BROKEN
Old name of RUBY_ENC_CODERANGE_BROKEN.
#define FL_ALL_RAW
Old name of RB_FL_ALL_RAW.
#define ENCODING_GET_INLINED(obj)
Old name of RB_ENCODING_GET_INLINED.
static char * rb_enc_left_char_head(const char *s, const char *p, const char *e, rb_encoding *enc)
Queries the left boundary of a character.
static char * rb_enc_right_char_head(const char *s, const char *p, const char *e, rb_encoding *enc)
Queries the right boundary of a character.
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
int rb_str_comparable(VALUE str1, VALUE str2)
Checks if two strings are comparable each other or not.
int len
Length of the buffer.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.