Ruby: include/ruby/internal/intern/string.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

string.h
Go to the documentation of this file.
1#ifndef RBIMPL_INTERN_STRING_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_INTERN_STRING_H
23#include "ruby/internal/config.h"
24
25#ifdef STDC_HEADERS
26# include <stddef.h>
27#endif
28
29#ifdef HAVE_STRING_H
30# include <string.h>
31#endif
32
33#ifdef HAVE_STDINT_H
34# include <stdint.h>
35#endif
36
37#include "ruby/internal/attr/nonnull.h"
38#include "ruby/internal/attr/pure.h"
39#include "ruby/internal/constant_p.h"
40#include "ruby/internal/dllexport.h"
41#include "ruby/internal/value.h"
42#include "ruby/internal/variable.h" /* rb_gvar_setter_t */
43#include "ruby/st.h" /* st_index_t */
44
45 RBIMPL_SYMBOL_EXPORT_BEGIN()
46
47/* string.c */
48 VALUE rb_str_new(const char*, long);
49 VALUE rb_str_new_cstr(const char*);
50 VALUE rb_str_new_shared(VALUE);
51 VALUE rb_str_new_frozen(VALUE);
52 VALUE rb_str_new_with_class(VALUE, const char*, long);
53 VALUE rb_tainted_str_new_cstr(const char*);
54 VALUE rb_tainted_str_new(const char*, long);
55 VALUE rb_external_str_new(const char*, long);
56 VALUE rb_external_str_new_cstr(const char*);
57 VALUE rb_locale_str_new(const char*, long);
58 VALUE rb_locale_str_new_cstr(const char*);
59 VALUE rb_filesystem_str_new(const char*, long);
60 VALUE rb_filesystem_str_new_cstr(const char*);
61 VALUE rb_str_buf_new(long);
62 VALUE rb_str_buf_new_cstr(const char*);
63 VALUE rb_str_buf_new2(const char*);
64 VALUE rb_str_tmp_new(long);
65 VALUE rb_usascii_str_new(const char*, long);
66 VALUE rb_usascii_str_new_cstr(const char*);
67 VALUE rb_utf8_str_new(const char*, long);
68 VALUE rb_utf8_str_new_cstr(const char*);
74 VALUE rb_str_new_static(const char *ptr, long len);
75 VALUE rb_usascii_str_new_static(const char *ptr, long len);
76 VALUE rb_utf8_str_new_static(const char *ptr, long len);
77 VALUE rb_str_to_interned_str(VALUE);
78 VALUE rb_interned_str(const char *, long);
79 VALUE rb_interned_str_cstr(const char *);
80void rb_str_free(VALUE);
81void rb_str_shared_replace(VALUE, VALUE);
82 VALUE rb_str_buf_append(VALUE, VALUE);
83 VALUE rb_str_buf_cat(VALUE, const char*, long);
84 VALUE rb_str_buf_cat2(VALUE, const char*);
85 VALUE rb_str_buf_cat_ascii(VALUE, const char*);
86 VALUE rb_obj_as_string(VALUE);
87 VALUE rb_check_string_type(VALUE);
88void rb_must_asciicompat(VALUE);
89 VALUE rb_str_dup(VALUE);
90 VALUE rb_str_resurrect(VALUE str);
91 VALUE rb_str_locktmp(VALUE);
92 VALUE rb_str_unlocktmp(VALUE);
93 VALUE rb_str_dup_frozen(VALUE);
94#define rb_str_dup_frozen rb_str_new_frozen
95 VALUE rb_str_plus(VALUE, VALUE);
96 VALUE rb_str_times(VALUE, VALUE);
97long rb_str_sublen(VALUE, long);
98 VALUE rb_str_substr(VALUE, long, long);
99 VALUE rb_str_subseq(VALUE, long, long);
100char *rb_str_subpos(VALUE, long, long*);
101void rb_str_modify(VALUE);
102void rb_str_modify_expand(VALUE, long);
103 VALUE rb_str_freeze(VALUE);
104void rb_str_set_len(VALUE, long);
105 VALUE rb_str_resize(VALUE, long);
106 VALUE rb_str_cat(VALUE, const char*, long);
107 VALUE rb_str_cat_cstr(VALUE, const char*);
108 VALUE rb_str_cat2(VALUE, const char*);
109 VALUE rb_str_append(VALUE, VALUE);
110 VALUE rb_str_concat(VALUE, VALUE);
111 st_index_t rb_memhash(const void *ptr, long len);
112 st_index_t rb_hash_start(st_index_t);
113 st_index_t rb_hash_uint32(st_index_t, uint32_t);
114 st_index_t rb_hash_uint(st_index_t, st_index_t);
115 st_index_t rb_hash_end(st_index_t);
116#define rb_hash_uint32(h, i) st_hash_uint32((h), (i))
117#define rb_hash_uint(h, i) st_hash_uint((h), (i))
118#define rb_hash_end(h) st_hash_end(h)
119 st_index_t rb_str_hash(VALUE);
120int rb_str_hash_cmp(VALUE,VALUE);
121int rb_str_comparable(VALUE, VALUE);
122int rb_str_cmp(VALUE, VALUE);
123 VALUE rb_str_equal(VALUE str1, VALUE str2);
124 VALUE rb_str_drop_bytes(VALUE, long);
125void rb_str_update(VALUE, long, long, VALUE);
126 VALUE rb_str_replace(VALUE, VALUE);
127 VALUE rb_str_inspect(VALUE);
128 VALUE rb_str_dump(VALUE);
129 VALUE rb_str_split(VALUE, const char*);
130 rb_gvar_setter_t rb_str_setter;
131 VALUE rb_str_intern(VALUE);
132 VALUE rb_sym_to_s(VALUE);
133long rb_str_strlen(VALUE);
134 VALUE rb_str_length(VALUE);
135long rb_str_offset(VALUE, long);
136 RBIMPL_ATTR_PURE()
137size_t rb_str_capacity(VALUE);
138 VALUE rb_str_ellipsize(VALUE, long);
139 VALUE rb_str_scrub(VALUE, VALUE);
140 VALUE rb_str_succ(VALUE);
141
142 RBIMPL_ATTR_NONNULL(())
143static inline long
144rbimpl_strlen(const char *str)
145{
146 return RBIMPL_CAST((long)strlen(str));
147}
148
149static inline VALUE
150rbimpl_str_new_cstr(const char *str)
151{
152 long len = rbimpl_strlen(str);
153 return rb_str_new_static(str, len);
154}
155
156static inline VALUE
157rbimpl_tainted_str_new_cstr(const char *str)
158{
159 long len = rbimpl_strlen(str);
160 return rb_tainted_str_new(str, len);
161}
162
163static inline VALUE
164rbimpl_usascii_str_new_cstr(const char *str)
165{
166 long len = rbimpl_strlen(str);
167 return rb_usascii_str_new_static(str, len);
168}
169
170static inline VALUE
171rbimpl_utf8_str_new_cstr(const char *str)
172{
173 long len = rbimpl_strlen(str);
174 return rb_utf8_str_new_static(str, len);
175}
176
177static inline VALUE
178rbimpl_external_str_new_cstr(const char *str)
179{
180 long len = rbimpl_strlen(str);
181 return rb_external_str_new(str, len);
182}
183
184static inline VALUE
185rbimpl_locale_str_new_cstr(const char *str)
186{
187 long len = rbimpl_strlen(str);
188 return rb_locale_str_new(str, len);
189}
190
191static inline VALUE
192rbimpl_str_buf_new_cstr(const char *str)
193{
194 long len = rbimpl_strlen(str);
195 VALUE buf = rb_str_buf_new(len);
196 return rb_str_buf_cat(buf, str, len);
197}
198
199static inline VALUE
200rbimpl_str_cat_cstr(VALUE buf, const char *str)
201{
202 long len = rbimpl_strlen(str);
203 return rb_str_cat(buf, str, len);
204}
205
206static inline VALUE
207rbimpl_exc_new_cstr(VALUE exc, const char *str)
208{
209 long len = rbimpl_strlen(str);
210 return rb_exc_new(exc, str, len);
211}
212
213#define rb_str_new(str, len) \
214 ((RBIMPL_CONSTANT_P(str) && \
215 RBIMPL_CONSTANT_P(len) ? \
216 rb_str_new_static : \
217 rb_str_new) ((str), (len)))
218
219#define rb_str_new_cstr(str) \
220 ((RBIMPL_CONSTANT_P(str) ? \
221 rbimpl_str_new_cstr : \
222 rb_str_new_cstr) (str))
223
224#define rb_usascii_str_new(str, len) \
225 ((RBIMPL_CONSTANT_P(str) && \
226 RBIMPL_CONSTANT_P(len) ? \
227 rb_usascii_str_new_static : \
228 rb_usascii_str_new) ((str), (len)))
229
230#define rb_utf8_str_new(str, len) \
231 ((RBIMPL_CONSTANT_P(str) && \
232 RBIMPL_CONSTANT_P(len) ? \
233 rb_utf8_str_new_static : \
234 rb_utf8_str_new) ((str), (len)))
235
236#define rb_tainted_str_new_cstr(str) \
237 ((RBIMPL_CONSTANT_P(str) ? \
238 rbimpl_tainted_str_new_cstr : \
239 rb_tainted_str_new_cstr) (str))
240
241#define rb_usascii_str_new_cstr(str) \
242 ((RBIMPL_CONSTANT_P(str) ? \
243 rbimpl_usascii_str_new_cstr : \
244 rb_usascii_str_new_cstr) (str))
245
246#define rb_utf8_str_new_cstr(str) \
247 ((RBIMPL_CONSTANT_P(str) ? \
248 rbimpl_utf8_str_new_cstr : \
249 rb_utf8_str_new_cstr) (str))
250
251#define rb_external_str_new_cstr(str) \
252 ((RBIMPL_CONSTANT_P(str) ? \
253 rbimpl_external_str_new_cstr : \
254 rb_external_str_new_cstr) (str))
255
256#define rb_locale_str_new_cstr(str) \
257 ((RBIMPL_CONSTANT_P(str) ? \
258 rbimpl_locale_str_new_cstr : \
259 rb_locale_str_new_cstr) (str))
260
261#define rb_str_buf_new_cstr(str) \
262 ((RBIMPL_CONSTANT_P(str) ? \
263 rbimpl_str_buf_new_cstr : \
264 rb_str_buf_new_cstr) (str))
265
266#define rb_str_cat_cstr(buf, str) \
267 ((RBIMPL_CONSTANT_P(str) ? \
268 rbimpl_str_cat_cstr : \
269 rb_str_cat_cstr) ((buf), (str)))
270
271#define rb_exc_new_cstr(exc, str) \
272 ((RBIMPL_CONSTANT_P(str) ? \
273 rbimpl_exc_new_cstr : \
274 rb_exc_new_cstr) ((exc), (str)))
275
276#define rb_str_new2 rb_str_new_cstr
277#define rb_str_new3 rb_str_new_shared
278#define rb_str_new4 rb_str_new_frozen
279#define rb_str_new5 rb_str_new_with_class
280#define rb_tainted_str_new2 rb_tainted_str_new_cstr
281#define rb_str_buf_new2 rb_str_buf_new_cstr
282#define rb_usascii_str_new2 rb_usascii_str_new_cstr
283#define rb_str_buf_cat rb_str_cat
284#define rb_str_buf_cat2 rb_str_cat_cstr
285#define rb_str_cat2 rb_str_cat_cstr
286#define rb_strlen_lit(str) (sizeof(str "") - 1)
287#define rb_str_new_lit(str) rb_str_new_static((str), rb_strlen_lit(str))
288#define rb_usascii_str_new_lit(str) rb_usascii_str_new_static((str), rb_strlen_lit(str))
289#define rb_utf8_str_new_lit(str) rb_utf8_str_new_static((str), rb_strlen_lit(str))
290#define rb_enc_str_new_lit(str, enc) rb_enc_str_new_static((str), rb_strlen_lit(str), (enc))
291#define rb_str_new_literal(str) rb_str_new_lit(str)
292#define rb_usascii_str_new_literal(str) rb_usascii_str_new_lit(str)
293#define rb_utf8_str_new_literal(str) rb_utf8_str_new_lit(str)
294#define rb_enc_str_new_literal(str, enc) rb_enc_str_new_lit(str, enc)
295
296 RBIMPL_SYMBOL_EXPORT_END()
297
298#endif /* RBIMPL_INTERN_STRING_H */
constant_p.h
Defines RBIMPL_CONSTANT_P.
ptr
struct RIMemo * ptr
Definition: debug.c:88
dllexport.h
Tewaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
len
uint8_t len
Definition: escape.c:17
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_exc_new
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Definition: error.c:1094
config.h
Thin wrapper to ruby/config.h.
rb_str_unlocktmp
VALUE rb_str_unlocktmp(VALUE)
Definition: string.c:2825
rb_str_freeze
VALUE rb_str_freeze(VALUE)
Definition: string.c:2766
rb_str_resize
VALUE rb_str_resize(VALUE, long)
Definition: string.c:2859
rb_str_buf_cat2
#define rb_str_buf_cat2
Definition: string.h:284
rb_str_scrub
VALUE rb_str_scrub(VALUE, VALUE)
Definition: string.c:10580
rb_hash_uint
#define rb_hash_uint(h, i)
Definition: string.h:117
rb_str_offset
long rb_str_offset(VALUE, long)
Definition: string.c:2566
rb_must_asciicompat
void rb_must_asciicompat(VALUE)
Definition: string.c:2314
rb_utf8_str_new_cstr
#define rb_utf8_str_new_cstr(str)
Definition: string.h:246
rb_hash_end
#define rb_hash_end(h)
Definition: string.h:118
rb_hash_uint32
#define rb_hash_uint32(h, i)
Definition: string.h:116
rb_str_new_shared
VALUE rb_str_new_shared(VALUE)
Definition: string.c:1267
rb_str_shared_replace
void rb_str_shared_replace(VALUE, VALUE)
Definition: string.c:1480
rb_str_subpos
char * rb_str_subpos(VALUE, long, long *)
Definition: string.c:2647
rb_str_concat
VALUE rb_str_concat(VALUE, VALUE)
Definition: string.c:3217
rb_str_cat2
#define rb_str_cat2
Definition: string.h:285
rb_str_to_interned_str
VALUE rb_str_to_interned_str(VALUE)
Definition: string.c:11543
rb_external_str_new
VALUE rb_external_str_new(const char *, long)
Definition: string.c:1157
rb_str_update
void rb_str_update(VALUE, long, long, VALUE)
Definition: string.c:4865
rb_str_plus
VALUE rb_str_plus(VALUE, VALUE)
Definition: string.c:2044
rb_str_buf_new2
#define rb_str_buf_new2
Definition: string.h:281
rb_memhash
st_index_t rb_memhash(const void *ptr, long len)
Definition: random.c:1629
rb_str_new
#define rb_str_new(str, len)
Definition: string.h:213
rb_str_buf_cat
#define rb_str_buf_cat
Definition: string.h:283
rb_str_new_static
VALUE rb_str_new_static(const char *ptr, long len)
*_str_new_static functions are intended for C string literals.
Definition: string.c:933
rb_str_cat
VALUE rb_str_cat(VALUE, const char *, long)
Definition: string.c:2962
rb_filesystem_str_new
VALUE rb_filesystem_str_new(const char *, long)
Definition: string.c:1181
rb_locale_str_new
VALUE rb_locale_str_new(const char *, long)
Definition: string.c:1169
rb_usascii_str_new
#define rb_usascii_str_new(str, len)
Definition: string.h:224
rb_hash_start
st_index_t rb_hash_start(st_index_t)
Definition: random.c:1623
rb_str_set_len
void rb_str_set_len(VALUE, long)
Definition: string.c:2842
rb_str_replace
VALUE rb_str_replace(VALUE, VALUE)
Definition: string.c:5632
rb_str_substr
VALUE rb_str_substr(VALUE, long, long)
Definition: string.c:2734
rb_str_free
void rb_str_free(VALUE)
Definition: string.c:1433
rb_str_modify
void rb_str_modify(VALUE)
Definition: string.c:2262
rb_str_buf_new
VALUE rb_str_buf_new(long)
Definition: string.c:1398
rb_check_string_type
VALUE rb_check_string_type(VALUE)
Definition: string.c:2462
rb_str_resurrect
VALUE rb_str_resurrect(VALUE str)
Definition: string.c:1637
rb_str_inspect
VALUE rb_str_inspect(VALUE)
Definition: string.c:6199
rb_filesystem_str_new_cstr
VALUE rb_filesystem_str_new_cstr(const char *)
Definition: string.c:1187
rb_sym_to_s
VALUE rb_sym_to_s(VALUE)
Definition: string.c:11148
rb_str_buf_new_cstr
#define rb_str_buf_new_cstr(str)
Definition: string.h:261
rb_str_strlen
long rb_str_strlen(VALUE)
Definition: string.c:1976
rb_usascii_str_new_cstr
#define rb_usascii_str_new_cstr(str)
Definition: string.h:241
rb_str_setter
rb_gvar_setter_t rb_str_setter
Definition: string.h:130
rb_external_str_new_cstr
#define rb_external_str_new_cstr(str)
Definition: string.h:251
rb_tainted_str_new
VALUE rb_tainted_str_new(const char *, long)
Definition: string.c:957
rb_str_new_with_class
VALUE rb_str_new_with_class(VALUE, const char *, long)
Definition: string.c:1381
rb_str_equal
VALUE rb_str_equal(VALUE str1, VALUE str2)
Definition: string.c:3423
rb_str_split
VALUE rb_str_split(VALUE, const char *)
Definition: string.c:8412
rb_str_times
VALUE rb_str_times(VALUE, VALUE)
Definition: string.c:2114
rb_str_comparable
int rb_str_comparable(VALUE, VALUE)
Definition: string.c:3353
rb_str_tmp_new
VALUE rb_str_tmp_new(long)
Definition: string.c:1427
rb_str_ellipsize
VALUE rb_str_ellipsize(VALUE, long)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
Definition: string.c:10517
rb_str_cmp
int rb_str_cmp(VALUE, VALUE)
Definition: string.c:3378
rb_str_subseq
VALUE rb_str_subseq(VALUE, long, long)
Definition: string.c:2624
rb_str_dump
VALUE rb_str_dump(VALUE)
Definition: string.c:6311
rb_str_append
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:3118
rb_str_buf_cat_ascii
VALUE rb_str_buf_cat_ascii(VALUE, const char *)
Definition: string.c:3079
rb_str_new_frozen
VALUE rb_str_new_frozen(VALUE)
Definition: string.c:1273
rb_str_modify_expand
void rb_str_modify_expand(VALUE, long)
Definition: string.c:2270
rb_interned_str_cstr
VALUE rb_interned_str_cstr(const char *)
Definition: string.c:11556
rb_str_buf_append
VALUE rb_str_buf_append(VALUE, VALUE)
Definition: string.c:3103
rb_str_intern
VALUE rb_str_intern(VALUE)
Definition: symbol.c:840
rb_str_drop_bytes
VALUE rb_str_drop_bytes(VALUE, long)
Definition: string.c:4795
rb_locale_str_new_cstr
#define rb_locale_str_new_cstr(str)
Definition: string.h:256
rb_str_hash_cmp
int rb_str_hash_cmp(VALUE, VALUE)
Definition: string.c:3324
rb_str_dup_frozen
#define rb_str_dup_frozen
Definition: string.h:94
rb_str_locktmp
VALUE rb_str_locktmp(VALUE)
rb_obj_as_string
VALUE rb_obj_as_string(VALUE)
Definition: string.c:1529
rb_str_cat_cstr
#define rb_str_cat_cstr(buf, str)
Definition: string.h:266
rb_str_sublen
long rb_str_sublen(VALUE, long)
Definition: string.c:2613
rb_utf8_str_new_static
VALUE rb_utf8_str_new_static(const char *ptr, long len)
Definition: string.c:945
rb_utf8_str_new
#define rb_utf8_str_new(str, len)
Definition: string.h:230
rb_str_dup
VALUE rb_str_dup(VALUE)
Definition: string.c:1631
rb_str_capacity
size_t rb_str_capacity(VALUE)
Definition: string.c:773
rb_str_hash
st_index_t rb_str_hash(VALUE)
Definition: string.c:3314
rb_interned_str
VALUE rb_interned_str(const char *, long)
Definition: string.c:11549
rb_tainted_str_new_cstr
#define rb_tainted_str_new_cstr(str)
Definition: string.h:236
rb_str_length
VALUE rb_str_length(VALUE)
Definition: string.c:1995
rb_str_new_cstr
#define rb_str_new_cstr(str)
Definition: string.h:219
rb_str_succ
VALUE rb_str_succ(VALUE)
Definition: string.c:4315
rb_usascii_str_new_static
VALUE rb_usascii_str_new_static(const char *ptr, long len)
Definition: string.c:939
variable.h
C-function backended Ruby-global variables.
rb_gvar_setter_t
void rb_gvar_setter_t(VALUE val, ID id, VALUE *data)
Definition: variable.h:30
buf
voidpf void * buf
Definition: ioapi.h:138
nonnull.h
Defines RBIMPL_ATTR_NONNULL.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:29
pure.h
Defines RBIMPL_ATTR_PURE.
RBIMPL_ATTR_PURE
#define RBIMPL_ATTR_PURE()
Wraps (or simulates) __attribute__((pure))
Definition: pure.h:33
uint32_t
unsigned int uint32_t
Definition: sha2.h:101
st.h
st_index_t
st_data_t st_index_t
Definition: st.h:50
strlen
size_t strlen(const char *)
const
#define const
Definition: strftime.c:108
value.h
Defines VALUE and ID.
VALUE
unsigned long VALUE
Definition: value.h:38