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
22#define STR_FAKESTR FL_USER19
24enum ruby_rstring_private_flags {
25 RSTRING_CHILLED = STR_CHILLED,
29# undef rb_fstring_cstr
33rb_str_encindex_fastpath(
int encindex)
43 case ENCINDEX_ASCII_8BIT:
45 case ENCINDEX_US_ASCII:
53rb_str_enc_fastpath(
VALUE str)
58static inline rb_encoding *
59rb_str_enc_get(
VALUE str)
68VALUE rb_fstring_cstr(
const char *str);
70int rb_str_buf_cat_escaped_char(
VALUE result,
unsigned int c,
int unicode_p);
71int rb_str_symname_p(
VALUE);
73char *rb_str_fill_terminator(
VALUE str,
const int termlen);
74void rb_str_change_terminator_length(
VALUE str,
const int oldtermlen,
const int termlen);
77void rb_str_try_unlocktmp(
VALUE str,
VALUE lock);
79VALUE rb_external_str_with_enc(
VALUE str, rb_encoding *eenc);
81 rb_encoding *from,
int ecflags,
VALUE ecopts);
84size_t rb_str_memsize(
VALUE);
85char *rb_str_to_cstr(
VALUE str);
86const char *ruby_escaped_char(
int c);
87void rb_str_make_independent(
VALUE str);
88int rb_enc_str_coderange_scan(
VALUE str, rb_encoding *enc);
89int rb_ascii8bit_appendable_encoding_index(rb_encoding *enc,
unsigned int code);
93void rb_str_make_embedded(
VALUE);
94void rb_str_make_heap(
VALUE str);
96size_t rb_str_size_as_embedded(
VALUE);
97bool rb_str_reembeddable_p(
VALUE);
98bool rb_str_embedded_shared_root_p(
VALUE);
103const char *rb_str_null_check(
VALUE);
108void rb_warn_unchilled_literal(
VALUE str);
110static inline bool STR_EMBED_P(
VALUE str);
111static inline bool STR_SHARED_P(
VALUE str);
113static inline VALUE QUOTE_ID(
ID v);
114static inline bool is_ascii_string(
VALUE str);
115static inline bool is_broken_string(
VALUE str);
116static inline VALUE rb_str_eql_internal(
const VALUE str1,
const VALUE str2);
118RUBY_SYMBOL_EXPORT_BEGIN
121void rb_str_tmp_frozen_release(
VALUE str,
VALUE tmp);
123RUBY_SYMBOL_EXPORT_END
126void rb_gc_free_fstring(
VALUE obj);
127bool rb_obj_is_fstring_table(
VALUE obj);
128void Init_fstring_table();
133VALUE rb_str_concat_literals(
size_t num,
const VALUE *strary);
136VALUE rb_id_quote_unprintable(
ID);
137VALUE rb_sym_proc_call(
ID mid,
int argc,
const VALUE *argv,
int kw_splat,
VALUE passed_proc);
139VALUE rb_enc_literal_str_cr(
const char *ptr,
rb_len_t len, rb_encoding *enc,
int cr);
144#define rb_fstring_lit(str) rb_fstring_new((str), rb_strlen_lit(str))
145#define rb_fstring_literal(str) rb_fstring_lit(str)
146#define rb_fstring_enc_lit(str, enc) rb_fstring_enc_new((str), rb_strlen_lit(str), (enc))
147#define rb_fstring_enc_literal(str, enc) rb_fstring_enc_lit(str, enc)
152 return rb_str_quote_unprintable(v);
158 return rb_id_quote_unprintable(i);
162STR_EMBED_P(
VALUE str)
168STR_SHARED_P(
VALUE str)
170 return FL_ALL_RAW(str, STR_NOEMBED | STR_SHARED);
174CHILLED_STRING_P(
VALUE obj)
180CHILLED_STRING_MUTATED(
VALUE str)
184 rb_warn_unchilled_literal(str);
189is_ascii_string(
VALUE str)
195is_broken_string(
VALUE str)
200NORETURN(
void rb_str_invalid_byte_sequence(
VALUE str));
202mustnot_broken(
VALUE str)
204 if (is_broken_string(str)) rb_str_invalid_byte_sequence(str);
207NORETURN(
void rb_str_unexpect_wchar(
VALUE str));
209mustnot_wchar(
VALUE str)
211 rb_encoding *enc = rb_enc_from_index(
ENCODING_GET(str));
212 if (rb_enc_mbminlen(enc) > 1) rb_str_unexpect_wchar(str);
216at_char_boundary(
const char *s,
const char *p,
const char *e, rb_encoding *enc)
222at_char_right_boundary(
const char *s,
const char *p,
const char *e, rb_encoding *enc)
233rb_str_eql_internal(
const VALUE str1,
const VALUE str2)
236 const char *ptr1, *ptr2;
238 if (
len != RSTRING_LEN(str2))
return Qfalse;
240 if ((ptr1 = RSTRING_PTR(str1)) == (ptr2 = RSTRING_PTR(str2)))
242 if (memcmp(ptr1, ptr2,
len) == 0)
248rb_streql_cstr(
VALUE str,
const char *lit,
size_t len)
250 if ((
size_t)RSTRING_LEN(str) !=
len)
return false;
251 return memcmp(RSTRING_PTR(str), lit,
len) == 0;
253#define rb_streql_lit(str, lit) rb_streql_cstr(str, lit, rb_strlen_lit(lit))
255#if __has_builtin(__builtin_constant_p)
256# define rb_fstring_cstr(str) \
257 (__builtin_constant_p(str) ? \
258 rb_fstring_new((str), (rb_len_t)strlen(str)) : \
259 (rb_fstring_cstr)(str))
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.
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
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_str_comparable(VALUE str1, VALUE str2)
Checks if two strings are comparable each other or not.
int capa
Designed capacity of the buffer.
int len
Length of the buffer.
C99 shim for <stdbool.h>.
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
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.