Ruby
3.4.0dev (2024-11-22 revision 37a72b0150ec36b4ea27175039afc28c62207b0c)
|
Defines struct RString. More...
#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/core/rbasic.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/fl_type.h"
#include "ruby/internal/value_type.h"
#include "ruby/internal/warning_push.h"
#include "ruby/assert.h"
Go to the source code of this file.
Data Structures | |
struct | RString |
Ruby's String. More... | |
Macros | |
#define | RSTRING(obj) RBIMPL_CAST((struct RString *)(obj)) |
Convenient casting macro. More... | |
#define | Check_SafeStr(v) rb_check_safe_str(RBIMPL_CAST((VALUE)(v))) |
#define | RSTRING_GETMEM(str, ptrvar, lenvar) |
Convenient macro to obtain the contents and length at once. More... | |
Conversion of Ruby strings into C's | |
#define | StringValue(v) rb_string_value(&(v)) |
Ensures that the parameter object is a String. More... | |
#define | StringValuePtr(v) rb_string_value_ptr(&(v)) |
Identical to StringValue, except it returns a char* . More... | |
#define | StringValueCStr(v) rb_string_value_cstr(&(v)) |
Identical to StringValuePtr, except it additionally checks for the contents for viability as a C string. More... | |
#define | SafeStringValue(v) StringValue(v) |
#define | ExportStringValue(v) |
Identical to StringValue, except it additionally converts the string's encoding to default external encoding. More... | |
Functions | |
VALUE | rb_str_to_str (VALUE obj) |
Identical to rb_check_string_type(), except it raises exceptions in case of conversion failures. More... | |
VALUE | rb_string_value (volatile VALUE *ptr) |
Identical to rb_str_to_str(), except it fills the passed pointer with the converted object. More... | |
char * | rb_string_value_ptr (volatile VALUE *ptr) |
Identical to rb_str_to_str(), except it returns the converted string's backend memory region. More... | |
char * | rb_string_value_cstr (volatile VALUE *ptr) |
Identical to rb_string_value_ptr(), except it additionally checks for the contents for viability as a C string. More... | |
VALUE | rb_str_export (VALUE obj) |
Identical to rb_str_to_str(), except it additionally converts the string into default external encoding. More... | |
VALUE | rb_str_export_locale (VALUE obj) |
Identical to rb_str_export(), except it converts into the locale encoding instead. More... | |
static long | RSTRING_LEN (VALUE str) |
Queries the length of the string. More... | |
static char * | RSTRING_PTR (VALUE str) |
Queries the contents pointer of the string. More... | |
static char * | RSTRING_END (VALUE str) |
Queries the end of the contents pointer of the string. More... | |
static int | RSTRING_LENINT (VALUE str) |
Identical to RSTRING_LEN(), except it differs for the return type. More... | |
Defines struct RString.
RBIMPL
or rbimpl
are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will. __VA_ARGS__
is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98. Definition in file rstring.h.
#define Check_SafeStr | ( | v | ) | rb_check_safe_str(RBIMPL_CAST((VALUE)(v))) |
Exists here for backwards compatibility only. You can safely forget about it.
#define ExportStringValue | ( | v | ) |
Identical to StringValue, except it additionally converts the string's encoding to default external encoding.
Ruby has a concept called encodings. A string can have different encoding than the environment expects. Someone has to make sure its contents be converted to something suitable. This is that routine. Call it when necessary.
[in,out] | v | Arbitrary Ruby object. |
rb_eTypeError | No implicit conversion defined. |
v
is a String. #define RSTRING | ( | obj | ) | RBIMPL_CAST((struct RString *)(obj)) |
#define RSTRING_GETMEM | ( | str, | |
ptrvar, | |||
lenvar | |||
) |
Convenient macro to obtain the contents and length at once.
str | String in question. |
ptrvar | Variable where its contents is stored. |
lenvar | Variable where its length is stored. |
#define SafeStringValue | ( | v | ) | StringValue(v) |
Exists here for backwards compatibility only. You can safely forget about it.
#define StringValue | ( | v | ) | rb_string_value(&(v)) |
#define StringValueCStr | ( | v | ) | rb_string_value_cstr(&(v)) |
Identical to StringValuePtr, except it additionally checks for the contents for viability as a C string.
Ruby can accept wider range of contents as strings, compared to C. This function is to check that.
[in,out] | v | Arbitrary Ruby object. |
rb_eTypeError | No implicit conversion defined. |
rb_eArgError | String is not C-compatible. |
v
is a String. #define StringValuePtr | ( | v | ) | rb_string_value_ptr(&(v)) |
Identical to StringValue, except it returns a char*
.
[in,out] | v | Arbitrary Ruby object. |
rb_eTypeError | No implicit conversion defined. |
v
is a String. Identical to rb_str_to_str(), except it additionally converts the string into default external encoding.
Ruby has a concept called encodings. A string can have different encoding than the environment expects. Someone has to make sure its contents be converted to something suitable. This is that routine. Call it when necessary.
[in] | obj | Target object. |
rb_eTypeError | No implicit conversion to String. |
Identical to rb_str_export(), except it converts into the locale encoding instead.
[in] | obj | Target object. |
rb_eTypeError | No implicit conversion to String. |
Identical to rb_check_string_type(), except it raises exceptions in case of conversion failures.
[in] | obj | Target object. |
rb_eTypeError | No implicit conversion to String. |
obj.to_str
. Definition at line 1715 of file string.c.
Referenced by rb_string_value().
Identical to rb_str_to_str(), except it fills the passed pointer with the converted object.
[in,out] | ptr | Pointer to a variable of target object. |
rb_eTypeError | No implicit conversion to String. |
obj.to_str
. *ptr
is the return value. Definition at line 2715 of file string.c.
Referenced by rb_string_value_cstr(), and rb_string_value_ptr().
char* rb_string_value_cstr | ( | volatile VALUE * | ptr | ) |
Identical to rb_string_value_ptr(), except it additionally checks for the contents for viability as a C string.
Ruby can accept wider range of contents as strings, compared to C. This function is to check that.
[in,out] | ptr | Pointer to a variable of target object. |
rb_eTypeError | No implicit conversion to String. |
rb_eArgError | String is not C-compatible. |
*ptr
is the return value of obj.to_str
. char* rb_string_value_ptr | ( | volatile VALUE * | ptr | ) |
Identical to rb_str_to_str(), except it returns the converted string's backend memory region.
[in,out] | ptr | Pointer to a variable of target object. |
rb_eTypeError | No implicit conversion to String. |
*ptr
is the return value of obj.to_str
.
|
inlinestatic |
Queries the end of the contents pointer of the string.
[in] | str | String in question. |
str
must be an instance of RString. Definition at line 442 of file rstring.h.
Referenced by rb_enc_uint_chr(), rb_str_format(), rb_str_hash(), rb_str_inspect(), rb_str_offset(), rb_str_set_len(), rb_str_update(), and rb_str_vcatf().
|
inlinestatic |
Queries the length of the string.
[in] | str | String in question. |
str
must be an instance of RString. Definition at line 367 of file rstring.h.
Referenced by rb_ary_join(), rb_econv_append(), rb_econv_open_opts(), rb_econv_str_append(), rb_econv_str_convert(), rb_find_file(), rb_find_file_ext(), rb_io_puts(), rb_io_ungetc(), rb_num2char_inline(), rb_profile_frame_full_label(), rb_reg_adjust_startpos(), rb_reg_match_post(), rb_reg_prepare_re(), rb_reg_quote(), rb_reg_regcomp(), rb_reg_regsub(), rb_str_buf_append(), rb_str_comparable(), rb_str_concat(), rb_str_drop_bytes(), rb_str_dump(), rb_str_ellipsize(), rb_str_format(), rb_str_freeze(), rb_str_modify_expand(), rb_str_resize(), rb_str_resurrect(), rb_str_set_len(), rb_str_subpos(), rb_str_succ(), rb_str_times(), and RREGEXP_SRC_LEN().
|
inlinestatic |
Identical to RSTRING_LEN(), except it differs for the return type.
[in] | str | String in question. |
rb_eRangeError | Too long. |
str
must be an instance of RString.
|
inlinestatic |
Queries the contents pointer of the string.
[in] | str | String in question. |
str
must be an instance of RString. Definition at line 416 of file rstring.h.
Referenced by rb_class2name(), rb_econv_append(), rb_econv_open_opts(), rb_econv_substr_append(), rb_enc_uint_chr(), rb_enc_vsprintf(), rb_env_clear(), rb_find_file(), rb_find_file_ext(), rb_id2name(), rb_io_ungetc(), rb_num2char_inline(), rb_path_to_class(), rb_profile_frame_full_label(), rb_reg_adjust_startpos(), rb_reg_prepare_re(), rb_reg_quote(), rb_reg_regcomp(), rb_reg_regsub(), rb_sourcefile(), rb_str_buf_append(), rb_str_concat(), rb_str_drop_bytes(), rb_str_dump(), rb_str_ellipsize(), rb_str_format(), rb_str_inspect(), rb_str_offset(), rb_str_plus(), rb_str_set_len(), rb_str_sublen(), rb_str_subpos(), rb_str_succ(), rb_str_times(), rb_str_update(), rb_string_value_ptr(), RREGEXP_SRC_PTR(), and ruby_init_loadpath().