Ruby: internal/string.h File Reference

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

Macros | Functions
string.h File Reference

Internal header for String. More...

`#include "ruby/internal/config.h"`
`#include <stddef.h>`
`#include "internal/compilers.h"`
`#include "ruby/internal/stdbool.h"`
`#include "ruby/encoding.h"`
`#include "ruby/ruby.h"`

Go to the source code of this file.

## Macros
#define | STR_NOEMBED FL_USER1
#define | STR_SHARED FL_USER2 /* = ELTS_SHARED */
#define | rb_fstring_lit(str) rb_fstring_new((str), rb_strlen_lit(str))
#define | rb_fstring_literal(str) rb_fstring_lit(str)
#define | rb_fstring_enc_lit(str, enc) rb_fstring_enc_new((str), rb_strlen_lit(str), (enc))
#define | rb_fstring_enc_literal(str, enc) rb_fstring_enc_lit(str, enc)
#define | rb_fstring_cstr(str)

## Functions
VALUE | rb_fstring (VALUE)
VALUE | rb_fstring_cstr (const char *str)
VALUE | rb_fstring_enc_new (const char *ptr, long len, rb_encoding *enc)
int | rb_str_buf_cat_escaped_char (VALUE result, unsigned int c, int unicode_p)
int | rb_str_symname_p (VALUE)
VALUE | rb_str_quote_unprintable (VALUE)
char * | rb_str_fill_terminator (VALUE str, const int termlen)
void | rb_str_change_terminator_length (VALUE str, const int oldtermlen, const int termlen)
VALUE | rb_str_locktmp_ensure (VALUE str, VALUE(*func)(VALUE), VALUE arg)
VALUE | rb_str_chomp_string (VALUE str, VALUE chomp)
VALUE | rb_external_str_with_enc (VALUE str, rb_encoding *eenc)
VALUE | rb_str_cat_conv_enc_opts (VALUE newstr, long ofs, const char *ptr, long len, rb_encoding *from, int ecflags, VALUE ecopts)
VALUE | rb_enc_str_scrub (rb_encoding *enc, VALUE str, VALUE repl)
VALUE | rb_str_initialize (VALUE str, const char *ptr, long len, rb_encoding *enc)
size_t | rb_str_memsize (VALUE)
char * | rb_str_to_cstr (VALUE str)
const char * | ruby_escaped_char (int c)
void | rb_str_make_independent (VALUE str)
int | rb_enc_str_coderange_scan (VALUE str, rb_encoding *enc)
VALUE | rb_str_tmp_frozen_acquire (VALUE str)
void | rb_str_tmp_frozen_release (VALUE str, VALUE tmp)
VALUE | rb_setup_fake_str (struct RString *fake_str, const char *name, long len, rb_encoding *enc)
VALUE | rb_str_upto_each (VALUE, VALUE, int, int(*each)(VALUE, VALUE), VALUE)
VALUE | rb_str_upto_endless_each (VALUE, int(*each)(VALUE, VALUE), VALUE)
VALUE | rb_fstring_new (const char *ptr, long len)
VALUE | rb_obj_as_string_result (VALUE str, VALUE obj)
VALUE | rb_str_opt_plus (VALUE x, VALUE y)
VALUE | rb_str_concat_literals (size_t num, const VALUE *strary)
VALUE | rb_str_eql (VALUE str1, VALUE str2)
VALUE | rb_id_quote_unprintable (ID)
VALUE | rb_sym_proc_call (ID mid, int argc, const VALUE *argv, int kw_splat, VALUE passed_proc)
VALUE | rb_ec_str_resurrect (struct rb_execution_context_struct *ec, VALUE str)

## Detailed Description

Internal header for String.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Definition in file string.h.

## Macro Definition Documentation

## ◆ rb_fstring_cstr

#define rb_fstring_cstr | ( |  | str | ) |

Value:
(__builtin_constant_p(str) ? \
rb_fstring_new((str), (long)strlen(str)) : \
(rb_fstring_cstr)(str))
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_fstring_cstr
#define rb_fstring_cstr(str)
Definition: string.h:136
strlen
size_t strlen(const char *)

Definition at line 136 of file string.h.

## ◆ rb_fstring_enc_lit

#define rb_fstring_enc_lit | ( |  | str,
|  |  | enc
| ) |  | rb_fstring_enc_new((str), rb_strlen_lit(str), (enc))

Definition at line 80 of file string.h.

## ◆ rb_fstring_enc_literal

#define rb_fstring_enc_literal | ( |  | str,
|  |  | enc
| ) |  | rb_fstring_enc_lit(str, enc)

Definition at line 81 of file string.h.

## ◆ rb_fstring_lit

#define rb_fstring_lit | ( |  | str | ) | rb_fstring_new((str), rb_strlen_lit(str))

Definition at line 78 of file string.h.

## ◆ rb_fstring_literal

#define rb_fstring_literal | ( |  | str | ) | rb_fstring_lit(str)

Definition at line 79 of file string.h.

## ◆ STR_NOEMBED

#define STR_NOEMBED FL_USER1

Definition at line 19 of file string.h.

## ◆ STR_SHARED

#define STR_SHARED FL_USER2 /* = ELTS_SHARED */

Definition at line 20 of file string.h.

## Function Documentation

## ◆ rb_ec_str_resurrect()

VALUE rb_ec_str_resurrect | ( | struct rb_execution_context_struct * | ec,
|  | VALUE | str
| ) |  |

Definition at line 1644 of file string.c.

References rb_cString, RSTRING_LEN, RUBY_DTRACE_CREATE_HOOK, and str.

## ◆ rb_enc_str_coderange_scan()

int rb_enc_str_coderange_scan | ( | VALUE | str,
|  | rb_encoding * | enc
| ) |  |

Definition at line 719 of file string.c.

References rb_enc_to_index(), and str.

## ◆ rb_enc_str_scrub()

VALUE rb_enc_str_scrub | ( | rb_encoding * | enc,
|  | VALUE | str,
|  | VALUE | repl
| ) |  |

Definition at line 10587 of file string.c.

References ENC_CODERANGE, ENC_CODERANGE_UNKNOWN, str, and STR_ENC_GET.

## ◆ rb_external_str_with_enc()

VALUE rb_external_str_with_enc | ( | VALUE | str,
|  | rb_encoding * | eenc
| ) |  |

Definition at line 1144 of file string.c.

References ENC_CODERANGE_7BIT, rb_ascii8bit_encindex, rb_default_internal_encoding(), rb_enc_associate_index(), rb_enc_str_coderange(), rb_enc_to_index(), rb_str_conv_enc(), rb_usascii_encindex, and str.

## ◆ rb_fstring()

VALUE rb_fstring | ( | VALUE | str | ) |

Definition at line 353 of file string.c.

References assert, BARE_STRING_P, FALSE, FL_TEST, FL_TEST_RAW, fstr_update_arg::fstr, OBJ_FREEZE_RAW, OBJ_FROZEN, rb_str_resize(), RSTRING_FSTR, RSTRING_LEN, str, STR_NOEMBED, STR_SHARED, STR_SHARED_ROOT, and T_STRING.

Referenced by rb_autoload_str(), rb_enc_reg_new(), rb_hash_key_str(), rb_iseq_pathobj_new(), rb_node_case_when_optimizable_literal(), rb_parser_lex_state_name(), rb_str_intern(), rb_str_to_interned_str(), and yyparse().

## ◆ rb_fstring_cstr()

VALUE rb_fstring_cstr | ( | const char * | str | ) |

Definition at line 460 of file string.c.

References ptr, rb_fstring_new(), and strlen().

## ◆ rb_fstring_enc_new()

VALUE rb_fstring_enc_new | ( | const char * | ptr,
|  | long | len,
|  | rb_encoding * | enc
| ) |  |

Definition at line 453 of file string.c.

References FALSE, len, ptr, and rb_setup_fake_str().

## ◆ rb_fstring_new()

VALUE rb_fstring_new | ( | const char * | ptr,
|  | long | len
| ) |  |

Definition at line 446 of file string.c.

References ENCINDEX_US_ASCII, FALSE, len, and ptr.

Referenced by rb_deprecate_constant(), and rb_fstring_cstr().

## ◆ rb_id_quote_unprintable()

VALUE rb_id_quote_unprintable | ( | ID | id | ) |

Definition at line 11067 of file string.c.

References rb_id2str, rb_str_inspect(), rb_str_symname_p(), and str.

## ◆ rb_obj_as_string_result()

VALUE rb_obj_as_string_result | ( | VALUE | str,
|  | VALUE | obj
| ) |  |

Definition at line 1541 of file string.c.

References rb_any_to_s(), str, and T_STRING.

Referenced by rb_obj_as_string().

## ◆ rb_setup_fake_str()

VALUE rb_setup_fake_str | ( | struct RString * | fake_str,
|  | const char * | name,
|  | long | len,
|  | rb_encoding * | enc
| ) |  |

Definition at line 435 of file string.c.

References len, name, and rb_enc_to_index().

Referenced by rb_check_id_cstr(), rb_check_symbol_cstr(), rb_enc_interned_str(), rb_fstring_enc_new(), rb_intern3(), rb_sym_intern(), and ruby_require_internal().

## ◆ rb_str_buf_cat_escaped_char()

int rb_str_buf_cat_escaped_char | ( | VALUE | result,
|  | unsigned int | c,
|  | int | unicode_p
| ) |  |

Definition at line 6084 of file string.c.

References CHAR_ESC_LEN, int(), ISPRINT, rb_str_buf_cat, snprintf, and strlen().

Referenced by rb_str_escape(), and rb_str_inspect().

## ◆ rb_str_cat_conv_enc_opts()

VALUE rb_str_cat_conv_enc_opts | ( | VALUE | newstr,
|  | long | ofs,
|  | const char * | ptr,
|  | long | len,
|  | rb_encoding * | from,
|  | int | ecflags,
|  | VALUE | ecopts
| ) |  |

Definition at line 1013 of file string.c.

References len, ptr, rb_eIndexError, rb_enc_get(), rb_raise(), rb_str_cat(), rb_str_modify(), RSTRING_LEN, and STR_SET_LEN.

Referenced by rb_external_str_new_with_enc(), and rb_file_expand_path_internal().

## ◆ rb_str_change_terminator_length()

void rb_str_change_terminator_length | ( | VALUE | str,
|  | const int | oldtermlen,
|  | const int | termlen
| ) |  |

Definition at line 2378 of file string.c.

References assert, RString::capa, FL_TEST, L, len, RSTRING, RSTRING_LEN, RSTRING_PTR, str, STR_SHARED, and TERM_FILL.

Referenced by rb_enc_associate_index().

## ◆ rb_str_chomp_string()

VALUE rb_str_chomp_string | ( | VALUE | str,
|  | VALUE | chomp
| ) |  |

Definition at line 9236 of file string.c.

References ENC_CODERANGE, ENC_CODERANGE_7BIT, ENC_CODERANGE_CLEAR, len, Qnil, RSTRING_LEN, RSTRING_PTR, str, STR_SET_LEN, TERM_FILL, and TERM_LEN.

## ◆ rb_str_concat_literals()

VALUE rb_str_concat_literals | ( | size_t | num,
|  | const VALUE * | strary
| ) |  |

Definition at line 3127 of file string.c.

References ENC_CODERANGE, ENCINDEX_US_ASCII, ENCODING_GET, ENCODING_GET_INLINED, len, LIKELY, MIN_PRE_ALLOC_SIZE, NULL, num, rb_enc_copy(), rb_enc_set_index(), rb_str_buf_new(), rb_str_new, rb_str_resurrect(), RSTRING_LEN, RSTRING_PTR, str, and UNLIKELY.

## ◆ rb_str_eql()

VALUE rb_str_eql | ( | VALUE | str1,
|  | VALUE | str2
| ) |  |

Definition at line 3451 of file string.c.

References Qfalse, Qtrue, and T_STRING.

Referenced by Init_String().

## ◆ rb_str_fill_terminator()

char * rb_str_fill_terminator | ( | VALUE | str,
|  | const int | termlen
| ) |  |

Definition at line 2454 of file string.c.

References len, RSTRING_LEN, RSTRING_PTR, and str.

## ◆ rb_str_initialize()

VALUE rb_str_initialize | ( | VALUE | str,
|  | const char * | ptr,
|  | long | len,
|  | rb_encoding * | enc
| ) |  |

Definition at line 1034 of file string.c.

References len, ptr, rb_enc_associate(), rb_str_cat(), str, and STR_SET_LEN.

Referenced by rb_external_str_new_with_enc().

## ◆ rb_str_locktmp_ensure()

VALUE rb_str_locktmp_ensure | ( | VALUE | str,
|  | VALUE(*)(VALUE) | func,
|  | VALUE | arg
| ) |  |

Definition at line 2835 of file string.c.

References rb_ensure(), rb_str_locktmp(), rb_str_unlocktmp(), and str.

Referenced by rsock_s_recvfrom().

## ◆ rb_str_make_independent()

void rb_str_make_independent | ( | VALUE | str | ) |

Definition at line 220 of file string.c.

References str.

## ◆ rb_str_memsize()

size_t rb_str_memsize | ( | VALUE | str | ) |

Definition at line 1460 of file string.c.

References FL_TEST, str, STR_HEAP_SIZE, STR_NOEMBED, STR_NOFREE, and STR_SHARED.

## ◆ rb_str_opt_plus()

VALUE rb_str_opt_plus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 2075 of file string.c.

References assert, LONG_MAX, MAYBE_UNUSED, Qundef, rb_cString, rb_enc_get_index(), rb_str_plus(), RBASIC_CLASS, and RSTRING_GETMEM.

## ◆ rb_str_quote_unprintable()

VALUE rb_str_quote_unprintable | ( | VALUE | str | ) |

Definition at line 11046 of file string.c.

References len, NULL, ptr, rb_default_external_encoding(), rb_default_internal_encoding(), rb_str_inspect(), RSTRING_LEN, RSTRING_PTR, str, STR_ENC_GET, and T_STRING.

## ◆ rb_str_symname_p()

int rb_str_symname_p | ( | VALUE | sym | ) |

Definition at line 11027 of file string.c.

References FALSE, len, NULL, ptr, rb_default_external_encoding(), rb_default_internal_encoding(), rb_enc_symname2_p(), RSTRING_LEN, RSTRING_PTR, STR_ENC_GET, strlen(), sym, and TRUE.

Referenced by rb_id_quote_unprintable().

## ◆ rb_str_tmp_frozen_acquire()

VALUE rb_str_tmp_frozen_acquire | ( | VALUE | str | ) |

Definition at line 1287 of file string.c.

References FALSE, and OBJ_FROZEN_RAW.

Referenced by rb_str_format().

## ◆ rb_str_tmp_frozen_release()

void rb_str_tmp_frozen_release | ( | VALUE | str,
|  | VALUE | tmp
| ) |  |

Definition at line 1294 of file string.c.

References RString::as, assert, FL_TEST_RAW, FL_UNSET_RAW, OBJ_FROZEN_RAW, rb_gc_force_recycle(), RBASIC, RBASIC_CLASS, RSTRING, RUBY_FL_FREEZE, RString::shared, STR_BORROWED, STR_NOFREE, STR_SHARED, and STR_TMPLOCK.

Referenced by rb_str_format().

## ◆ rb_str_to_cstr()

char * rb_str_to_cstr | ( | VALUE | str | ) |

Definition at line 2432 of file string.c.

References str.

Referenced by rb_get_path_check_convert(), and rb_to_encoding_index().

## ◆ rb_str_upto_each()

VALUE rb_str_upto_each | ( | VALUE | beg,
|  | VALUE | end,
|  | int | excl,
|  | int(*)(VALUE, VALUE) | each,
|  | VALUE | arg
| ) |  |

Definition at line 4483 of file string.c.

References re_registers::beg, CONST_ID, re_registers::end, FALSE, FIX2LONG, FIXNUM_P, idLE, INT2FIX, ISDIGIT, NIL_P, numberof, Qnil, rb_cString, rb_enc_check(), rb_enc_sprintf(), rb_enc_str_new(), rb_fstring_lit, rb_funcall(), rb_funcallv, rb_str_cmp(), rb_str_equal(), rb_str_format(), rb_str_to_inum(), rb_usascii_encoding(), RSTRING_LEN, RSTRING_PTR, and StringValue.

Referenced by rb_str_include_range_p().

## ◆ rb_str_upto_endless_each()

VALUE rb_str_upto_endless_each | ( | VALUE | beg,
|  | int(*)(VALUE, VALUE) | each,
|  | VALUE | arg
| ) |  |

Definition at line 4565 of file string.c.

References re_registers::beg, CONST_ID, FALSE, FIX2LONG, FIXABLE, FIXNUM_P, INT2FIX, ISDIGIT, LONG2NUM, numberof, rb_cString, rb_enc_sprintf(), rb_fstring_lit, rb_funcallv, rb_str_format(), rb_str_to_inum(), rb_usascii_encoding(), RSTRING_LEN, RSTRING_PTR, and StringValue.

## ◆ rb_sym_proc_call()

VALUE rb_sym_proc_call | ( | ID | mid,
|  | int | argc,
|  | const VALUE * | argv,
|  | int | kw_splat,
|  | VALUE | passed_proc
| ) |  |

Definition at line 11171 of file string.c.

References argc, argv, rb_eArgError, rb_funcall_with_block_kw(), and rb_raise().

## ◆ ruby_escaped_char()

const char * ruby_escaped_char | ( | int | c | ) |

Definition at line 6117 of file string.c.

References NULL.

Referenced by rb_str_escape().