Ruby 4.1.0dev (2026-05-15 revision 11de89ca1a94899535875ea594962c79713615b1)
string.h
Go to the documentation of this file.
1#ifndef RUBY_INTERNAL_ENCODING_STRING_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RUBY_INTERNAL_ENCODING_STRING_H
25#include "ruby/internal/value.h"
28#include "ruby/internal/intern/string.h" /* rbimpl_strlen */
29
31
32
48VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc);
49
67VALUE rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc);
68
87VALUE rb_enc_str_new_static(const char *ptr, long len, rb_encoding *enc);
88
106VALUE rb_enc_interned_str(const char *ptr, long len, rb_encoding *enc);
107
122VALUE rb_enc_interned_str_cstr(const char *ptr, rb_encoding *enc);
123
136long rb_enc_strlen(const char *head, const char *tail, rb_encoding *enc);
137
152char *rb_enc_nth(const char *head, const char *tail, long nth, rb_encoding *enc);
153
162
176VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
177
196VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc);
197
224VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *enc);
225
235
247
264VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts);
265
272int rbimpl_enc_str_coderange_scan(VALUE str);
273
283int rb_enc_str_coderange(VALUE str);
284
294static inline int
296{
297 int cr = ENC_CODERANGE(str);
298 if (cr == ENC_CODERANGE_UNKNOWN) {
299 cr = rbimpl_enc_str_coderange_scan(str);
300 }
301 return cr;
302}
303
304#define rb_enc_str_coderange rb_enc_str_coderange_inline
305
321long rb_str_coderange_scan_restartable(const char *str, const char *end, rb_encoding *enc, int *cr);
322
334
348long rb_memsearch(const void *x, long m, const void *y, long n, rb_encoding *enc);
349
352static inline VALUE
353rbimpl_enc_str_new_cstr(const char *str, rb_encoding *enc)
354{
355 long len = rbimpl_strlen(str);
356
357 return rb_enc_str_new_static(str, len, enc);
358}
359
360#define rb_enc_str_new(str, len, enc) \
361 ((RBIMPL_CONSTANT_P(str) && \
362 RBIMPL_CONSTANT_P(len) ? \
363 rb_enc_str_new_static: \
364 rb_enc_str_new) ((str), (len), (enc)))
365
366#define rb_enc_str_new_cstr(str, enc) \
367 ((RBIMPL_CONSTANT_P(str) ? \
368 rbimpl_enc_str_new_cstr : \
369 rb_enc_str_new_cstr) ((str), (enc)))
370
374
375#endif /* RUBY_INTERNAL_ENCODING_STRING_H */
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
#define ENC_CODERANGE(obj)
Old name of RB_ENC_CODERANGE.
Definition coderange.h:184
#define ENC_CODERANGE_UNKNOWN
Old name of RUBY_ENC_CODERANGE_UNKNOWN.
Definition coderange.h:179
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition nonnull.h:30
Defines rb_encoding.
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
Encoding conversion main routine.
Definition string.c:1344
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
Encodes the passed code point into a series of bytes.
Definition numeric.c:3938
VALUE rb_enc_str_new_static(const char *ptr, long len, rb_encoding *enc)
Identical to rb_enc_str_new(), except it takes a C string literal.
Definition string.c:1209
static int rb_enc_str_coderange_inline(VALUE str)
Scans the passed string to collect its code range.
Definition string.h:295
char * rb_enc_nth(const char *head, const char *tail, long nth, rb_encoding *enc)
Queries the n-th character.
Definition string.c:3054
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
Identical to rb_str_conv_enc(), except it additionally takes IO encoder options.
Definition string.c:1228
VALUE rb_enc_interned_str(const char *ptr, long len, rb_encoding *enc)
Identical to rb_enc_str_new(), except it returns a "f"string.
Definition string.c:12762
long rb_memsearch(const void *x, long m, const void *y, long n, rb_encoding *enc)
Looks for the passed string in the passed buffer.
Definition re.c:252
long rb_enc_strlen(const char *head, const char *tail, rb_encoding *enc)
Counts the number of characters of the passed string, according to the passed encoding.
Definition string.c:2334
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
Identical to rb_str_cat(), except it additionally takes an encoding.
Definition string.c:3771
VALUE rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
Identical to rb_enc_str_new(), except it assumes the passed pointer is a pointer to a C string.
Definition string.c:1157
VALUE rb_str_export_to_enc(VALUE obj, rb_encoding *enc)
Identical to rb_str_export(), except it additionally takes an encoding.
Definition string.c:1449
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *enc)
Identical to rb_external_str_new(), except it additionally takes an encoding.
Definition string.c:1350
int rb_enc_str_asciionly_p(VALUE str)
Queries if the passed string is "ASCII only".
Definition string.c:970
VALUE rb_obj_encoding(VALUE obj)
Identical to rb_enc_get_index(), except the return type.
Definition encoding.c:1236
VALUE rb_enc_interned_str_cstr(const char *ptr, rb_encoding *enc)
Identical to rb_enc_str_new_cstr(), except it returns a "f"string.
Definition string.c:12786
long rb_str_coderange_scan_restartable(const char *str, const char *end, rb_encoding *enc, int *cr)
Scans the passed string until it finds something odd.
Definition string.c:826
Public APIs related to rb_cString.
int len
Length of the buffer.
Definition io.h:8
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40