Ruby  3.4.0dev (2024-11-05 revision e440268d51fe02b303e3817a7a733a0dac1c5091)
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 
48 VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc);
49 
67 VALUE rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc);
68 
87 VALUE rb_enc_str_new_static(const char *ptr, long len, rb_encoding *enc);
88 
106 VALUE rb_enc_interned_str(const char *ptr, long len, rb_encoding *enc);
107 
122 VALUE rb_enc_interned_str_cstr(const char *ptr, rb_encoding *enc);
123 
136 long rb_enc_strlen(const char *head, const char *tail, rb_encoding *enc);
137 
152 char *rb_enc_nth(const char *head, const char *tail, long nth, rb_encoding *enc);
153 
162 
176 VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
177 
196 VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc);
197 
224 VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *enc);
225 
235 
247 
264 VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts);
265 
275 int rb_enc_str_coderange(VALUE str);
276 
292 long rb_str_coderange_scan_restartable(const char *str, const char *end, rb_encoding *enc, int *cr);
293 
305 
319 long rb_memsearch(const void *x, long m, const void *y, long n, rb_encoding *enc);
320 
323 static inline VALUE
324 rbimpl_enc_str_new_cstr(const char *str, rb_encoding *enc)
325 {
326  long len = rbimpl_strlen(str);
327 
328  return rb_enc_str_new_static(str, len, enc);
329 }
330 
331 #define rb_enc_str_new(str, len, enc) \
332  ((RBIMPL_CONSTANT_P(str) && \
333  RBIMPL_CONSTANT_P(len) ? \
334  rb_enc_str_new_static: \
335  rb_enc_str_new) ((str), (len), (enc)))
336 
337 #define rb_enc_str_new_cstr(str, enc) \
338  ((RBIMPL_CONSTANT_P(str) ? \
339  rbimpl_enc_str_new_cstr : \
340  rb_enc_str_new_cstr) ((str), (enc)))
341 
345 
346 #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
Defines rb_encoding.
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
Encoding conversion main routine.
Definition: string.c:1270
char * rb_enc_nth(const char *head, const char *tail, long nth, rb_encoding *enc)
Queries the n-th character.
Definition: string.c:2921
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
Definition: string.c:880
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
Encodes the passed code point into a series of bytes.
Definition: numeric.c:3803
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:1135
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:1154
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:12506
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:2251
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:3597
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:1082
VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
Identical to rb_str_new(), except it additionally takes an encoding.
Definition: string.c:1042
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:1375
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:1276
int rb_enc_str_asciionly_p(VALUE str)
Queries if the passed string is "ASCII only".
Definition: string.c:899
VALUE rb_obj_encoding(VALUE obj)
Identical to rb_enc_get_index(), except the return type.
Definition: encoding.c:1148
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:12528
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:764
Public APIs related to rb_cString.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
Definition: io.h:2
int len
Length of the buffer.
Definition: io.h:8
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition: defines.h:88
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40