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

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

Macros | Functions | Variables
string.h File Reference

Public APIs related to rb_cString. More...

`#include "ruby/internal/config.h"`
`#include "ruby/internal/attr/nonnull.h"`
`#include "ruby/internal/attr/pure.h"`
`#include "ruby/internal/constant_p.h"`
`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/value.h"`
`#include "ruby/internal/variable.h"`
`#include "ruby/st.h"`

Go to the source code of this file.

## Macros
#define | rb_str_dup_frozen rb_str_new_frozen
#define | rb_hash_uint32(h, i) st_hash_uint32((h), (i))
#define | rb_hash_uint(h, i) st_hash_uint((h), (i))
#define | rb_hash_end(h) st_hash_end(h)
#define | rb_str_new(str, len)
#define | rb_str_new_cstr(str)
#define | rb_usascii_str_new(str, len)
#define | rb_utf8_str_new(str, len)
#define | rb_tainted_str_new_cstr(str)
#define | rb_usascii_str_new_cstr(str)
#define | rb_utf8_str_new_cstr(str)
#define | rb_external_str_new_cstr(str)
#define | rb_locale_str_new_cstr(str)
#define | rb_str_buf_new_cstr(str)
#define | rb_str_cat_cstr(buf, str)
#define | rb_exc_new_cstr(exc, str)
#define | rb_str_new2 rb_str_new_cstr
#define | rb_str_new3 rb_str_new_shared
#define | rb_str_new4 rb_str_new_frozen
#define | rb_str_new5 rb_str_new_with_class
#define | rb_tainted_str_new2 rb_tainted_str_new_cstr
#define | rb_str_buf_new2 rb_str_buf_new_cstr
#define | rb_usascii_str_new2 rb_usascii_str_new_cstr
#define | rb_str_buf_cat rb_str_cat
#define | rb_str_buf_cat2 rb_str_cat_cstr
#define | rb_str_cat2 rb_str_cat_cstr
#define | rb_strlen_lit(str) (sizeof(str "") - 1)
#define | rb_str_new_lit(str) rb_str_new_static((str), rb_strlen_lit(str))
#define | rb_usascii_str_new_lit(str) rb_usascii_str_new_static((str), rb_strlen_lit(str))
#define | rb_utf8_str_new_lit(str) rb_utf8_str_new_static((str), rb_strlen_lit(str))
#define | rb_enc_str_new_lit(str, enc) rb_enc_str_new_static((str), rb_strlen_lit(str), (enc))
#define | rb_str_new_literal(str) rb_str_new_lit(str)
#define | rb_usascii_str_new_literal(str) rb_usascii_str_new_lit(str)
#define | rb_utf8_str_new_literal(str) rb_utf8_str_new_lit(str)
#define | rb_enc_str_new_literal(str, enc) rb_enc_str_new_lit(str, enc)

## Functions
VALUE | rb_str_new (const char *, long)
VALUE | rb_str_new_cstr (const char *)
VALUE | rb_str_new_shared (VALUE)
VALUE | rb_str_new_frozen (VALUE)
VALUE | rb_str_new_with_class (VALUE, const char *, long)
VALUE | rb_tainted_str_new_cstr (const char *)
VALUE | rb_tainted_str_new (const char *, long)
VALUE | rb_external_str_new (const char *, long)
VALUE | rb_external_str_new_cstr (const char *)
VALUE | rb_locale_str_new (const char *, long)
VALUE | rb_locale_str_new_cstr (const char *)
VALUE | rb_filesystem_str_new (const char *, long)
VALUE | rb_filesystem_str_new_cstr (const char *)
VALUE | rb_str_buf_new (long)
VALUE | rb_str_buf_new_cstr (const char *)
VALUE | rb_str_buf_new2 (const char *)
VALUE | rb_str_tmp_new (long)
VALUE | rb_usascii_str_new (const char *, long)
VALUE | rb_usascii_str_new_cstr (const char *)
VALUE | rb_utf8_str_new (const char *, long)
VALUE | rb_utf8_str_new_cstr (const char *)
VALUE | rb_str_new_static (const char *ptr, long len)
| *_str_new_static functions are intended for C string literals. More...
VALUE | rb_usascii_str_new_static (const char *ptr, long len)
VALUE | rb_utf8_str_new_static (const char *ptr, long len)
VALUE | rb_str_to_interned_str (VALUE)
VALUE | rb_interned_str (const char *, long)
VALUE | rb_interned_str_cstr (const char *)
void | rb_str_free (VALUE)
void | rb_str_shared_replace (VALUE, VALUE)
VALUE | rb_str_buf_append (VALUE, VALUE)
VALUE | rb_str_buf_cat (VALUE, const char *, long)
VALUE | rb_str_buf_cat2 (VALUE, const char *)
VALUE | rb_str_buf_cat_ascii (VALUE, const char *)
VALUE | rb_obj_as_string (VALUE)
VALUE | rb_check_string_type (VALUE)
void | rb_must_asciicompat (VALUE)
VALUE | rb_str_dup (VALUE)
VALUE | rb_str_resurrect (VALUE str)
VALUE | rb_str_locktmp (VALUE)
VALUE | rb_str_unlocktmp (VALUE)
VALUE | rb_str_dup_frozen (VALUE)
VALUE | rb_str_plus (VALUE, VALUE)
VALUE | rb_str_times (VALUE, VALUE)
long | rb_str_sublen (VALUE, long)
VALUE | rb_str_substr (VALUE, long, long)
VALUE | rb_str_subseq (VALUE, long, long)
char * | rb_str_subpos (VALUE, long, long *)
void | rb_str_modify (VALUE)
void | rb_str_modify_expand (VALUE, long)
VALUE | rb_str_freeze (VALUE)
void | rb_str_set_len (VALUE, long)
VALUE | rb_str_resize (VALUE, long)
VALUE | rb_str_cat (VALUE, const char *, long)
VALUE | rb_str_cat_cstr (VALUE, const char *)
VALUE | rb_str_cat2 (VALUE, const char *)
VALUE | rb_str_append (VALUE, VALUE)
VALUE | rb_str_concat (VALUE, VALUE)
st_index_t | rb_memhash (const void *ptr, long len)
st_index_t | rb_hash_start (st_index_t)
st_index_t | rb_hash_uint32 (st_index_t, uint32_t)
st_index_t | rb_hash_uint (st_index_t, st_index_t)
st_index_t | rb_hash_end (st_index_t)
st_index_t | rb_str_hash (VALUE)
int | rb_str_hash_cmp (VALUE, VALUE)
int | rb_str_comparable (VALUE, VALUE)
int | rb_str_cmp (VALUE, VALUE)
VALUE | rb_str_equal (VALUE str1, VALUE str2)
VALUE | rb_str_drop_bytes (VALUE, long)
void | rb_str_update (VALUE, long, long, VALUE)
VALUE | rb_str_replace (VALUE, VALUE)
VALUE | rb_str_inspect (VALUE)
VALUE | rb_str_dump (VALUE)
VALUE | rb_str_split (VALUE, const char *)
VALUE | rb_str_intern (VALUE)
VALUE | rb_sym_to_s (VALUE)
long | rb_str_strlen (VALUE)
VALUE | rb_str_length (VALUE)
long | rb_str_offset (VALUE, long)
size_t | rb_str_capacity (VALUE)
VALUE | rb_str_ellipsize (VALUE, long)
| Shortens str and adds three dots, an ellipsis, if it is longer than len characters. More...
VALUE | rb_str_scrub (VALUE, VALUE)
VALUE | rb_str_succ (VALUE)

## Variables
rb_gvar_setter_t | rb_str_setter

## Detailed Description

Public APIs related to rb_cString.

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.

Warning
  Symbols prefixed with either `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.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__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 string.h.

## Macro Definition Documentation

## ◆ rb_enc_str_new_lit

#define rb_enc_str_new_lit | ( |  | str,
|  |  | enc
| ) |  | rb_enc_str_new_static((str), rb_strlen_lit(str), (enc))

Definition at line 290 of file string.h.

## ◆ rb_enc_str_new_literal

#define rb_enc_str_new_literal | ( |  | str,
|  |  | enc
| ) |  | rb_enc_str_new_lit(str, enc)

Definition at line 294 of file string.h.

## ◆ rb_exc_new_cstr

#define rb_exc_new_cstr | ( |  | exc,
|  |  | str
| ) |  |

Value:
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_exc_new_cstr : \
rb_exc_new_cstr) ((exc), (str)))
RBIMPL_CONSTANT_P
#define RBIMPL_CONSTANT_P(expr)
Definition: constant_p.h:34
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_exc_new_cstr
#define rb_exc_new_cstr(exc, str)
Definition: string.h:271

Definition at line 271 of file string.h.

## ◆ rb_external_str_new_cstr

#define rb_external_str_new_cstr | ( |  | str | ) |

Value:
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_external_str_new_cstr : \
rb_external_str_new_cstr) (str))
rb_external_str_new_cstr
#define rb_external_str_new_cstr(str)
Definition: string.h:251

Definition at line 251 of file string.h.

## ◆ rb_hash_end

#define rb_hash_end | ( |  | h | ) | st_hash_end(h)

Definition at line 118 of file string.h.

## ◆ rb_hash_uint

#define rb_hash_uint | ( |  | h,
|  |  | i
| ) |  | st_hash_uint((h), (i))

Definition at line 117 of file string.h.

## ◆ rb_hash_uint32

#define rb_hash_uint32 | ( |  | h,
|  |  | i
| ) |  | st_hash_uint32((h), (i))

Definition at line 116 of file string.h.

## ◆ rb_locale_str_new_cstr

#define rb_locale_str_new_cstr | ( |  | str | ) |

Value:
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_locale_str_new_cstr : \
rb_locale_str_new_cstr) (str))
rb_locale_str_new_cstr
#define rb_locale_str_new_cstr(str)
Definition: string.h:256

Definition at line 256 of file string.h.

## ◆ rb_str_buf_cat

#define rb_str_buf_cat rb_str_cat

Definition at line 283 of file string.h.

## ◆ rb_str_buf_cat2

#define rb_str_buf_cat2 rb_str_cat_cstr

Definition at line 284 of file string.h.

## ◆ rb_str_buf_new2

#define rb_str_buf_new2 rb_str_buf_new_cstr

Definition at line 281 of file string.h.

## ◆ rb_str_buf_new_cstr

#define rb_str_buf_new_cstr | ( |  | str | ) |

Value:
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_str_buf_new_cstr : \
rb_str_buf_new_cstr) (str))
rb_str_buf_new_cstr
#define rb_str_buf_new_cstr(str)
Definition: string.h:261

Definition at line 261 of file string.h.

## ◆ rb_str_cat2

#define rb_str_cat2 rb_str_cat_cstr

Definition at line 285 of file string.h.

## ◆ rb_str_cat_cstr

#define rb_str_cat_cstr | ( |  | buf,
|  |  | str
| ) |  |

Value:
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_str_cat_cstr : \
rb_str_cat_cstr) ((buf), (str)))
rb_str_cat_cstr
#define rb_str_cat_cstr(buf, str)
Definition: string.h:266
buf
voidpf void * buf
Definition: ioapi.h:138

Definition at line 266 of file string.h.

## ◆ rb_str_dup_frozen

#define rb_str_dup_frozen rb_str_new_frozen

Definition at line 94 of file string.h.

## ◆ rb_str_new

#define rb_str_new | ( |  | str,
|  |  | len
| ) |  |

Value:
((RBIMPL_CONSTANT_P(str) && \
RBIMPL_CONSTANT_P(len) ? \
rb_str_new_static : \
rb_str_new) ((str), (len)))
len
uint8_t len
Definition: escape.c:17
rb_str_new
#define rb_str_new(str, len)
Definition: string.h:213
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

Definition at line 213 of file string.h.

## ◆ rb_str_new2

#define rb_str_new2 rb_str_new_cstr

Definition at line 276 of file string.h.

## ◆ rb_str_new3

#define rb_str_new3 rb_str_new_shared

Definition at line 277 of file string.h.

## ◆ rb_str_new4

#define rb_str_new4 rb_str_new_frozen

Definition at line 278 of file string.h.

## ◆ rb_str_new5

#define rb_str_new5 rb_str_new_with_class

Definition at line 279 of file string.h.

## ◆ rb_str_new_cstr

#define rb_str_new_cstr | ( |  | str | ) |

Value:
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_str_new_cstr : \
rb_str_new_cstr) (str))
rb_str_new_cstr
#define rb_str_new_cstr(str)
Definition: string.h:219

Definition at line 219 of file string.h.

## ◆ rb_str_new_lit

#define rb_str_new_lit | ( |  | str | ) | rb_str_new_static((str), rb_strlen_lit(str))

Definition at line 287 of file string.h.

## ◆ rb_str_new_literal

#define rb_str_new_literal | ( |  | str | ) | rb_str_new_lit(str)

Definition at line 291 of file string.h.

## ◆ rb_strlen_lit

#define rb_strlen_lit | ( |  | str | ) | (sizeof(str "") - 1)

Definition at line 286 of file string.h.

## ◆ rb_tainted_str_new2

#define rb_tainted_str_new2 rb_tainted_str_new_cstr

Definition at line 280 of file string.h.

## ◆ rb_tainted_str_new_cstr

#define rb_tainted_str_new_cstr | ( |  | str | ) |

Value:
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_tainted_str_new_cstr : \
rb_tainted_str_new_cstr) (str))
rb_tainted_str_new_cstr
#define rb_tainted_str_new_cstr(str)
Definition: string.h:236

Definition at line 236 of file string.h.

## ◆ rb_usascii_str_new

#define rb_usascii_str_new | ( |  | str,
|  |  | len
| ) |  |

Value:
((RBIMPL_CONSTANT_P(str) && \
RBIMPL_CONSTANT_P(len) ? \
rb_usascii_str_new_static : \
rb_usascii_str_new) ((str), (len)))
rb_usascii_str_new
#define rb_usascii_str_new(str, len)
Definition: string.h:224
rb_usascii_str_new_static
VALUE rb_usascii_str_new_static(const char *ptr, long len)
Definition: string.c:939

Definition at line 224 of file string.h.

## ◆ rb_usascii_str_new2

#define rb_usascii_str_new2 rb_usascii_str_new_cstr

Definition at line 282 of file string.h.

## ◆ rb_usascii_str_new_cstr

#define rb_usascii_str_new_cstr | ( |  | str | ) |

Value:
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_usascii_str_new_cstr : \
rb_usascii_str_new_cstr) (str))
rb_usascii_str_new_cstr
#define rb_usascii_str_new_cstr(str)
Definition: string.h:241

Definition at line 241 of file string.h.

## ◆ rb_usascii_str_new_lit

#define rb_usascii_str_new_lit | ( |  | str | ) | rb_usascii_str_new_static((str), rb_strlen_lit(str))

Definition at line 288 of file string.h.

## ◆ rb_usascii_str_new_literal

#define rb_usascii_str_new_literal | ( |  | str | ) | rb_usascii_str_new_lit(str)

Definition at line 292 of file string.h.

## ◆ rb_utf8_str_new

#define rb_utf8_str_new | ( |  | str,
|  |  | len
| ) |  |

Value:
((RBIMPL_CONSTANT_P(str) && \
RBIMPL_CONSTANT_P(len) ? \
rb_utf8_str_new_static : \
rb_utf8_str_new) ((str), (len)))
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

Definition at line 230 of file string.h.

## ◆ rb_utf8_str_new_cstr

#define rb_utf8_str_new_cstr | ( |  | str | ) |

Value:
((RBIMPL_CONSTANT_P(str) ? \
rbimpl_utf8_str_new_cstr : \
rb_utf8_str_new_cstr) (str))
rb_utf8_str_new_cstr
#define rb_utf8_str_new_cstr(str)
Definition: string.h:246

Definition at line 246 of file string.h.

## ◆ rb_utf8_str_new_lit

#define rb_utf8_str_new_lit | ( |  | str | ) | rb_utf8_str_new_static((str), rb_strlen_lit(str))

Definition at line 289 of file string.h.

## ◆ rb_utf8_str_new_literal

#define rb_utf8_str_new_literal | ( |  | str | ) | rb_utf8_str_new_lit(str)

Definition at line 293 of file string.h.

## Function Documentation

## ◆ rb_check_string_type()

VALUE rb_check_string_type | ( | VALUE | str | ) |

Definition at line 2462 of file string.c.

References rb_check_convert_type_with_id(), str, and T_STRING.

Referenced by rb_ary_join(), rb_check_id(), rb_check_sockaddr_string_type(), rb_check_symbol(), rb_fiddle_type_ensure(), rb_get_message(), rb_io_extract_encoding_option(), rb_num_get_rounding_option(), rb_str_format(), rb_str_include_range_p(), rb_String(), rb_time_zone_abbreviation(), and rb_to_encoding_index().

## ◆ rb_external_str_new()

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

Definition at line 1157 of file string.c.

References len, ptr, rb_default_external_encoding(), and rb_external_str_new_with_enc().

## ◆ rb_external_str_new_cstr()

VALUE rb_external_str_new_cstr | ( | const char * | ptr | ) |

Definition at line 1163 of file string.c.

References ptr, rb_default_external_encoding(), rb_external_str_new_with_enc(), and strlen().

## ◆ rb_filesystem_str_new()

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

Definition at line 1181 of file string.c.

References len, ptr, rb_external_str_new_with_enc(), and rb_filesystem_encoding().

## ◆ rb_filesystem_str_new_cstr()

VALUE rb_filesystem_str_new_cstr | ( | const char * | ptr | ) |

Definition at line 1187 of file string.c.

References ptr, rb_external_str_new_with_enc(), rb_filesystem_encoding(), and strlen().

Referenced by rb_parser_compile_string().

## ◆ rb_hash_end()

st_index_t rb_hash_end | ( | st_index_t |  | ) |

## ◆ rb_hash_start()

st_index_t rb_hash_start | ( | st_index_t | h | ) |

Definition at line 1623 of file random.c.

References st_hash_start.

## ◆ rb_hash_uint()

st_index_t rb_hash_uint | ( | st_index_t | ,
|  | st_index_t |
| ) |  |

## ◆ rb_hash_uint32()

st_index_t rb_hash_uint32 | ( | st_index_t | ,
|  | uint32_t |
| ) |  |

## ◆ rb_interned_str()

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

Definition at line 11549 of file string.c.

References ENCINDEX_US_ASCII, len, ptr, and TRUE.

Referenced by rb_interned_str_cstr().

## ◆ rb_interned_str_cstr()

VALUE rb_interned_str_cstr | ( | const char * | ptr | ) |

Definition at line 11556 of file string.c.

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

## ◆ rb_locale_str_new()

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

Definition at line 1169 of file string.c.

References len, ptr, rb_external_str_new_with_enc(), and rb_locale_encoding().

## ◆ rb_locale_str_new_cstr()

VALUE rb_locale_str_new_cstr | ( | const char * | ptr | ) |

Definition at line 1175 of file string.c.

References ptr, rb_external_str_new_with_enc(), rb_locale_encoding(), and strlen().

## ◆ rb_memhash()

st_index_t rb_memhash | ( | const void * | ptr,
|  | long | len
| ) |  |

Definition at line 1629 of file random.c.

References len, ptr, sip_hash13, and sip_uint64_t::u32.

Referenced by rb_big_hash(), rb_complex_hash(), rb_dbl_long_hash(), rb_rational_hash(), and rb_str_hash().

## ◆ rb_must_asciicompat()

void rb_must_asciicompat | ( | VALUE | str | ) |

Definition at line 2314 of file string.c.

References rb_eEncCompatError, rb_enc_asciicompat, rb_enc_get(), rb_enc_name, rb_raise(), and str.

Referenced by rb_num_get_rounding_option(), rb_str2big_karatsuba(), rb_str2big_normal(), rb_str2big_poweroftwo(), and rb_str_convert_to_inum().

## ◆ rb_obj_as_string()

VALUE rb_obj_as_string | ( | VALUE | obj | ) |

Definition at line 1529 of file string.c.

References rb_funcall(), rb_obj_as_string_result(), str, and T_STRING.

Referenced by rb_inspect(), rb_io_puts(), rb_p(), rb_str_format(), and rb_time_zone_abbreviation().

## ◆ rb_str_append()

VALUE rb_str_append | ( | VALUE | str,
|  | VALUE | str2
| ) |  |

Definition at line 3118 of file string.c.

References rb_str_buf_append(), str, and StringValue.

Referenced by ole_raise(), rb_keyword_error_new(), rb_load_fail(), rb_str_concat(), and rb_str_ellipsize().

## ◆ rb_str_buf_append()

VALUE rb_str_buf_append | ( | VALUE | str,
|  | VALUE | str2
| ) |  |

Definition at line 3103 of file string.c.

References ENC_CODERANGE, ENC_CODERANGE_SET, ENCODING_GET, RSTRING_LEN, RSTRING_PTR, and str.

Referenced by rb_str_append().

## ◆ rb_str_buf_cat()

VALUE rb_str_buf_cat | ( | VALUE | ,
|  | const char * | ,
|  | long |
| ) |  |

## ◆ rb_str_buf_cat2()

VALUE rb_str_buf_cat2 | ( | VALUE | ,
|  | const char * |
| ) |  |

## ◆ rb_str_buf_cat_ascii()

VALUE rb_str_buf_cat_ascii | ( | VALUE | str,
|  | const char * | ptr
| ) |  |

Definition at line 3079 of file string.c.

References ALLOCA_N, ENC_CODERANGE_7BIT, ENC_CODERANGE_VALID, ENCODING_GET, len, ptr, rb_enc_asciicompat, rb_enc_codelen(), rb_enc_from_index(), rb_enc_mbcput, rb_enc_mbmaxlen, str, and strlen().

## ◆ rb_str_buf_new()

VALUE rb_str_buf_new | ( | long | capa | ) |

Definition at line 1398 of file string.c.

References ALLOC_N, RString::capa, FL_SET, rb_cString, RSTRING, RSTRING_EMBED_LEN_MAX, str, STR_BUF_MIN_SIZE, and STR_NOEMBED.

Referenced by rb_ary_join(), rb_econv_append(), rb_enc_vsprintf(), rb_reg_regsub(), rb_str_buf_new_cstr(), rb_str_concat_literals(), rb_str_conv_enc_opts(), rb_str_escape(), rb_str_format(), and rb_str_inspect().

## ◆ rb_str_buf_new2()

VALUE rb_str_buf_new2 | ( | const char * |  | ) |

## ◆ rb_str_buf_new_cstr()

VALUE rb_str_buf_new_cstr | ( | const char * | ptr | ) |

Definition at line 1415 of file string.c.

References len, ptr, rb_str_buf_cat, rb_str_buf_new(), str, and strlen().

## ◆ rb_str_capacity()

size_t rb_str_capacity | ( | VALUE | str | ) |

Definition at line 773 of file string.c.

References str, and TERM_LEN.

Referenced by rb_econv_append(), rb_str_format(), and rb_str_vcatf().

## ◆ rb_str_cat()

VALUE rb_str_cat | ( | VALUE | str,
|  | const char * | ptr,
|  | long | len
| ) |  |

Definition at line 2962 of file string.c.

References len, ptr, rb_eArgError, rb_raise(), and str.

Referenced by rb_file_dirname(), rb_id_attrset(), rb_str_cat_conv_enc_opts(), rb_str_concat(), rb_str_ellipsize(), rb_str_initialize(), and rsock_inspect_sockaddr().

## ◆ rb_str_cat2()

VALUE rb_str_cat2 | ( | VALUE | ,
|  | const char * |
| ) |  |

## ◆ rb_str_cat_cstr()

VALUE rb_str_cat_cstr | ( | VALUE | str,
|  | const char * | ptr
| ) |  |

Definition at line 2972 of file string.c.

References ptr, rb_str_buf_cat, str, and strlen().

## ◆ rb_str_cmp()

int rb_str_cmp | ( | VALUE | str1,
|  | VALUE | str2
| ) |  |

Definition at line 3378 of file string.c.

References ENCODING_GET, lesser, memcmp(), rb_str_comparable(), and RSTRING_GETMEM.

Referenced by rb_iseq_pathobj_new(), and rb_str_upto_each().

## ◆ rb_str_comparable()

int rb_str_comparable | ( | VALUE | str1,
|  | VALUE | str2
| ) |  |

Definition at line 3353 of file string.c.

References ENC_CODERANGE_7BIT, ENCODING_GET, FALSE, rb_enc_asciicompat, rb_enc_from_index(), rb_enc_str_coderange(), RSTRING_LEN, and TRUE.

Referenced by rb_str_cmp(), and rb_str_hash_cmp().

## ◆ rb_str_concat()

VALUE rb_str_concat | ( | VALUE | str1,
|  | VALUE | str2
| ) |  |

Definition at line 3217 of file string.c.

References ALLOCA_N, ENC_CODERANGE, ENC_CODERANGE_7BIT, ENC_CODERANGE_SET, ENC_CODERANGE_VALID, ENCINDEX_ASCII, ENCINDEX_US_ASCII, FIX2LONG, FIXNUM_P, len, memcpy, ONIGERR_INVALID_CODE_POINT_VALUE, ONIGERR_TOO_BIG_WIDE_CHAR_VALUE, rb_enc_associate_index(), rb_enc_codelen(), rb_enc_mbcput, rb_enc_name, rb_enc_precise_mbclen(), rb_enc_to_index(), rb_eRangeError, RB_INTEGER_TYPE_P, rb_num_to_uint(), rb_raise(), rb_str_append(), rb_str_cat(), rb_str_resize(), RSTRING_LEN, RSTRING_PTR, and STR_ENC_GET.

Referenced by Init_String(), make_inspect(), ole_typedesc2val(), rb_iseq_disasm_insn(), and rsock_raise_socket_error().

## ◆ rb_str_drop_bytes()

VALUE rb_str_drop_bytes | ( | VALUE | str,
|  | long | len
| ) |  |

Definition at line 4795 of file string.c.

References ENC_CODERANGE_CLEAR, int(), len, memmove(), ptr, rb_str_new_frozen(), RBASIC, RSTRING, RSTRING_LEN, RSTRING_PTR, str, STR_EMBEDDABLE_P, STR_NOEMBED, STR_NOFREE, STR_SET_EMBED, STR_SET_EMBED_LEN, STR_SHARED, TERM_LEN, and xfree.

## ◆ rb_str_dump()

VALUE rb_str_dump | ( | VALUE | str | ) |

Definition at line 6311 of file string.c.

References ENC_CODERANGE_7BIT, ENC_CODERANGE_SET, IS_EVSTR, ISPRINT, len, LONG_MAX, MBCLEN_CHARFOUND_LEN, MBCLEN_CHARFOUND_P, OnigEncodingTypeST::name, rb_ascii8bit_encindex, rb_enc_asciicompat, rb_enc_associate_index(), rb_enc_from_index(), rb_enc_get_index(), rb_enc_mbc_to_codepoint, rb_enc_precise_mbclen(), rb_eRuntimeError, rb_raise(), rb_str_new, rb_strlen_lit, rb_utf8_encindex, RSTRING_LEN, RSTRING_PTR, snprintf, str, and strlen().

Referenced by Init_String(), and rb_econv_prepare_options().

## ◆ rb_str_dup()

VALUE rb_str_dup | ( | VALUE | str | ) |

Definition at line 1631 of file string.c.

References rb_obj_class(), and str.

Referenced by date__parse(), rb_class_path(), rb_find_file_ext(), rb_id_attrset(), rb_str_conv_enc_opts(), rb_str_intern(), rb_vm_set_progname(), rsock_ipaddr(), and ruby_set_script_name().

## ◆ rb_str_dup_frozen()

VALUE rb_str_dup_frozen | ( | VALUE |  | ) |

## ◆ rb_str_ellipsize()

VALUE rb_str_ellipsize | ( | VALUE | str,
|  | long | len
| ) |  |

Shortens str and adds three dots, an ellipsis, if it is longer than len characters.

Parameters

  str | the string to ellipsize.
  len | the maximum string length.

Returns
  the ellipsized string.

Precondition
  len must not be negative.

Postcondition
  the length of the returned string in characters is less than or equal to len.
  If the length of str is less than or equal len, returns str itself.
  the encoding of returned string is equal to the encoding of str.
  the class of returned string is equal to the class of str.

Note
  the length is counted in characters.

Definition at line 10517 of file string.c.

References len, Qnil, rb_eIndexError, rb_enc_asciicompat, rb_enc_associate(), rb_enc_from_encoding(), rb_enc_get(), rb_enc_mbminlen, rb_enc_nth(), rb_enc_step_back, rb_raise(), rb_str_append(), rb_str_cat(), rb_str_encode(), rb_str_new, rb_str_subseq(), rb_usascii_str_new, RSTRING_LEN, RSTRING_PTR, and str.

## ◆ rb_str_equal()

VALUE rb_str_equal | ( | VALUE | str1,
|  | VALUE | str2
| ) |  |

Definition at line 3423 of file string.c.

References Qfalse, Qtrue, rb_equal(), rb_respond_to(), and T_STRING.

Referenced by Init_String(), rb_get_expanded_load_path(), and rb_str_upto_each().

## ◆ rb_str_free()

void rb_str_free | ( | VALUE | str | ) |

Definition at line 1433 of file string.c.

References FL_TEST, NULL, RB_DEBUG_COUNTER_INC, RB_DEBUG_COUNTER_INC_IF, rb_vm_fstring_table(), RB_VM_LOCK_ENTER, RB_VM_LOCK_LEAVE, RSTRING_FSTR, ruby_sized_xfree, st_delete, str, STR_HEAP_PTR, STR_HEAP_SIZE, STR_NOFREE, and STR_SHARED.

## ◆ rb_str_freeze()

VALUE rb_str_freeze | ( | VALUE | str | ) |

Definition at line 2766 of file string.c.

References OBJ_FROZEN, rb_obj_freeze(), rb_str_resize(), RSTRING_LEN, and str.

Referenced by Init_String().

## ◆ rb_str_hash()

st_index_t rb_str_hash | ( | VALUE | str | ) |

Definition at line 3314 of file string.c.

References ENC_CODERANGE_7BIT, ENCODING_GET, rb_enc_str_coderange(), rb_memhash(), RSTRING_LEN, RSTRING_PTR, and str.

## ◆ rb_str_hash_cmp()

int rb_str_hash_cmp | ( | VALUE | str1,
|  | VALUE | str2
| ) |  |

Definition at line 3324 of file string.c.

References memcmp(), rb_str_comparable(), and RSTRING_GETMEM.

## ◆ rb_str_inspect()

VALUE rb_str_inspect | ( | VALUE | str | ) |

Definition at line 6199 of file string.c.

References CHAR_ESC_LEN, ENCODING_GET, int(), ISPRINT, MBCLEN_CHARFOUND_LEN, MBCLEN_CHARFOUND_P, NULL, rb_default_external_encoding(), rb_default_internal_encoding(), rb_enc_asciicompat, rb_enc_associate(), rb_enc_codepoint, rb_enc_from_index(), rb_enc_isascii, rb_enc_isprint, rb_enc_mbc_to_codepoint, rb_enc_mbminlen, rb_enc_precise_mbclen(), rb_enc_unicode_p(), rb_str_buf_cat_escaped_char(), rb_str_buf_new(), rb_usascii_encoding(), RSTRING_PTR, snprintf, str, str_buf_cat2, and strlen().

Referenced by Init_String(), rb_id_quote_unprintable(), and rb_str_quote_unprintable().

## ◆ rb_str_intern()

VALUE rb_str_intern | ( | VALUE | str | ) |

Definition at line 840 of file symbol.c.

References GLOBAL_SYMBOLS_ENTER, GLOBAL_SYMBOLS_LEAVE, id, ID2SYM, ID_JUNK, IDSET_ATTRSET_FOR_INTERN, OBJ_FREEZE, rb_cSymbol, rb_enc_associate(), rb_enc_get(), rb_fstring(), rb_str_dup(), rb_usascii_encoding(), str, and sym.

Referenced by Init_String(), rb_f_global_variables(), rb_sym_intern(), and rb_to_symbol().

## ◆ rb_str_length()

VALUE rb_str_length | ( | VALUE | str | ) |

Definition at line 1995 of file string.c.

References LONG2NUM, NULL, and str.

Referenced by Init_String(), and rb_reg_match_p().

## ◆ rb_str_locktmp()

VALUE rb_str_locktmp | ( | VALUE |  | ) |

Referenced by rb_str_locktmp_ensure().

## ◆ rb_str_modify()

void rb_str_modify | ( | VALUE | str | ) |

Definition at line 2262 of file string.c.

References ENC_CODERANGE_CLEAR, and str.

Referenced by rb_str_cat_conv_enc_opts(), and rb_str_vcatf().

## ◆ rb_str_modify_expand()

void rb_str_modify_expand | ( | VALUE | str,
|  | long | expand
| ) |  |

Definition at line 2270 of file string.c.

References ENC_CODERANGE_CLEAR, len, LONG_MAX, rb_eArgError, rb_raise(), RESIZE_CAPA_TERM, RSTRING_LEN, str, and TERM_LEN.

Referenced by rb_file_expand_path_internal().

## ◆ rb_str_new()

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

Definition at line 835 of file string.c.

References len, ptr, and rb_cString.

## ◆ rb_str_new_cstr()

VALUE rb_str_new_cstr | ( | const char * | ptr | ) |

Definition at line 869 of file string.c.

References ptr, rb_str_new, and strlen().

## ◆ rb_str_new_frozen()

VALUE rb_str_new_frozen | ( | VALUE | orig | ) |

Definition at line 1273 of file string.c.

References OBJ_FROZEN, and rb_obj_class().

Referenced by rb_econv_prepare_options(), rb_econv_substr_append(), rb_hash_key_str(), rb_set_class_path_string(), rb_str_drop_bytes(), and rb_str_include_range_p().

## ◆ rb_str_new_shared()

VALUE rb_str_new_shared | ( | VALUE | str | ) |

Definition at line 1267 of file string.c.

References rb_obj_class(), and str.

Referenced by rb_str_subseq().

## ◆ rb_str_new_static()

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

*_str_new_static functions are intended for C string literals.

They require memory in the range [ptr, ptr+len] to always be readable. Note that this range covers a total of len + 1 bytes.

Definition at line 933 of file string.c.

References len, ptr, and rb_cString.

## ◆ rb_str_new_with_class()

VALUE rb_str_new_with_class | ( | VALUE | obj,
|  | const char * | ptr,
|  | long | len
| ) |  |

Definition at line 1381 of file string.c.

References len, ptr, rb_obj_class(), and TERM_LEN.

## ◆ rb_str_offset()

long rb_str_offset | ( | VALUE | str,
|  | long | pos
| ) |  |

Definition at line 2566 of file string.c.

References RSTRING_PTR, str, and STR_ENC_GET.

## ◆ rb_str_plus()

VALUE rb_str_plus | ( | VALUE | str1,
|  | VALUE | str2
| ) |  |

Definition at line 2044 of file string.c.

References ENC_CODERANGE, ENC_CODERANGE_AND, ENCODING_CODERANGE_SET, LONG_MAX, memcpy, rb_cString, rb_eArgError, rb_enc_check_str(), rb_enc_mbminlen, rb_enc_to_index(), RB_GC_GUARD, rb_raise(), RSTRING_GETMEM, RSTRING_PTR, StringValue, and TERM_FILL.

Referenced by Init_String(), and rb_str_opt_plus().

## ◆ rb_str_replace()

VALUE rb_str_replace | ( | VALUE | str,
|  | VALUE | str2
| ) |  |

Definition at line 5632 of file string.c.

References str, and StringValue.

Referenced by Init_String().

## ◆ rb_str_resize()

VALUE rb_str_resize | ( | VALUE | str,
|  | long | len
| ) |  |

Definition at line 2859 of file string.c.

References RString::as, RString::capa, ENC_CODERANGE_CLEAR, len, MEMCPY, ptr, rb_eArgError, rb_raise(), RSTRING, RSTRING_LEN, ruby_xfree(), SIZED_REALLOC_N, str, STR_EMBEDDABLE_P, STR_HEAP_PTR, STR_HEAP_SIZE, STR_SET_EMBED, STR_SET_EMBED_LEN, TERM_FILL, and TERM_LEN.

Referenced by rb_default_home_dir(), rb_econv_append(), rb_enc_vsprintf(), rb_file_expand_path_internal(), rb_find_file(), rb_find_file_ext(), rb_fstring(), rb_iseq_disasm(), rb_parser_fatal(), rb_reg_quote(), rb_str_concat(), rb_str_format(), rb_str_freeze(), rb_str_vcatf(), ruby_init_loadpath(), and VpAlloc().

## ◆ rb_str_resurrect()

VALUE rb_str_resurrect | ( | VALUE | str | ) |

Definition at line 1637 of file string.c.

References rb_cString, RSTRING_LEN, RUBY_DTRACE_CREATE_HOOK, and str.

Referenced by rb_str_concat_literals().

## ◆ rb_str_scrub()

VALUE rb_str_scrub | ( | VALUE | str,
|  | VALUE | repl
| ) |  |

Parameters

  str | the string to be scrubbed
  repl | the replacement character

Returns
  If given string is invalid, returns a new string. Otherwise, returns Qnil.

Definition at line 10580 of file string.c.

References ENC_CODERANGE, str, and STR_ENC_GET.

## ◆ rb_str_set_len()

void rb_str_set_len | ( | VALUE | str,
|  | long | len
| ) |  |

Definition at line 2842 of file string.c.

References RString::capa, len, rb_bug(), rb_eRuntimeError, rb_raise(), RSTRING_PTR, str, STR_SET_LEN, TERM_FILL, and TERM_LEN.

Referenced by ole_wc2vstr(), rb_ary_join(), rb_econv_append(), rb_file_expand_path_internal(), rb_find_file_ext(), rb_str_format(), rb_warn_deprecated(), rb_warn_deprecated_to_remove(), rsock_s_recvfrom(), and rsock_s_recvfrom_nonblock().

## ◆ rb_str_shared_replace()

void rb_str_shared_replace | ( | VALUE | str,
|  | VALUE | str2
| ) |  |

Definition at line 1480 of file string.c.

References str.

## ◆ rb_str_split()

VALUE rb_str_split | ( | VALUE | str,
|  | const char * | sep0
| ) |  |

Definition at line 8412 of file string.c.

References rb_str_new_cstr, str, and StringValue.

## ◆ rb_str_strlen()

long rb_str_strlen | ( | VALUE | str | ) |

Definition at line 1976 of file string.c.

References NULL, and str.

## ◆ rb_str_sublen()

long rb_str_sublen | ( | VALUE | str,
|  | long | pos
| ) |  |

Definition at line 2613 of file string.c.

References ENC_CODERANGE, RSTRING_PTR, str, and STR_ENC_GET.

Referenced by rb_reg_match(), and rb_reg_match2().

## ◆ rb_str_subpos()

char * rb_str_subpos | ( | VALUE | str,
|  | long | beg,
|  | long * | lenp
| ) |  |

Definition at line 2647 of file string.c.

References ENC_CODERANGE, ENC_CODERANGE_VALID, len, rb_enc_mbmaxlen, rb_enc_mbminlen, rb_enc_prev_char, RB_GC_GUARD, rb_utf8_encoding(), RSTRING_LEN, RSTRING_PTR, str, and STR_ENC_GET.

Referenced by rb_reg_match_p().

## ◆ rb_str_subseq()

VALUE rb_str_subseq | ( | VALUE | str,
|  | long | beg,
|  | long | len
| ) |  |

Definition at line 2624 of file string.c.

References len, RB_GC_GUARD, rb_str_new, rb_str_new_shared(), RSTRING, RSTRING_LEN, RSTRING_PTR, SHARABLE_SUBSTRING_P, str, STR_EMBEDDABLE_P, and TERM_LEN.

Referenced by rb_path_to_class(), rb_reg_match_post(), rb_reg_match_pre(), rb_reg_nth_match(), rb_reg_regsub(), rb_str_ellipsize(), and ruby_init_loadpath().

## ◆ rb_str_substr()

VALUE rb_str_substr | ( | VALUE | str,
|  | long | beg,
|  | long | len
| ) |  |

Definition at line 2734 of file string.c.

References len, str, and TRUE.

## ◆ rb_str_succ()

VALUE rb_str_succ | ( | VALUE | orig | ) |

Definition at line 4315 of file string.c.

References rb_str_new, RSTRING_LEN, RSTRING_PTR, and str.

Referenced by Init_String().

## ◆ rb_str_times()

VALUE rb_str_times | ( | VALUE | str,
|  | VALUE | times
| ) |  |

Definition at line 2114 of file string.c.

References INT2FIX, len, LONG_MAX, memcpy, NUM2LONG, rb_cString, rb_eArgError, rb_enc_copy(), rb_raise(), RSTRING, RSTRING_LEN, RSTRING_PTR, str, STR_EMBEDDABLE_P, STR_SET_LEN, STR_SET_NOEMBED, TERM_FILL, TERM_LEN, and ZALLOC_N.

Referenced by Init_String().

## ◆ rb_str_tmp_new()

VALUE rb_str_tmp_new | ( | long | len | ) |

Definition at line 1427 of file string.c.

References len.

Referenced by rb_find_file(), rb_find_file_ext(), and VpAlloc().

## ◆ rb_str_to_interned_str()

VALUE rb_str_to_interned_str | ( | VALUE | str | ) |

Definition at line 11543 of file string.c.

References rb_fstring(), and str.

## ◆ rb_str_unlocktmp()

VALUE rb_str_unlocktmp | ( | VALUE | str | ) |

Definition at line 2825 of file string.c.

References FL_TEST, FL_UNSET, rb_eRuntimeError, rb_raise(), str, and STR_TMPLOCK.

Referenced by rb_str_locktmp_ensure().

## ◆ rb_str_update()

void rb_str_update | ( | VALUE | str,
|  | long | beg,
|  | long | len,
|  | VALUE | val
| ) |  |

Definition at line 4865 of file string.c.

References assert, re_registers::beg, ENC_CODERANGE, ENC_CODERANGE_AND, ENC_CODERANGE_BROKEN, ENC_CODERANGE_SET, len, rb_eIndexError, rb_enc_associate(), rb_enc_check(), rb_raise(), RSTRING_PTR, str, and StringValue.

## ◆ rb_sym_to_s()

VALUE rb_sym_to_s | ( | VALUE | sym | ) |

Definition at line 11148 of file string.c.

References rb_cString, rb_sym2str(), and sym.

Referenced by Init_String().

## ◆ rb_tainted_str_new()

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

Definition at line 957 of file string.c.

References len, ptr, rb_str_new, and rb_warn_deprecated_to_remove().

## ◆ rb_tainted_str_new_cstr()

VALUE rb_tainted_str_new_cstr | ( | const char * | ptr | ) |

Definition at line 964 of file string.c.

References ptr, rb_str_new_cstr, and rb_warn_deprecated_to_remove().

## ◆ rb_usascii_str_new()

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

Definition at line 841 of file string.c.

References ENC_CODERANGE_7BIT, ENCODING_CODERANGE_SET, len, ptr, rb_str_new, rb_usascii_encindex, and str.

## ◆ rb_usascii_str_new_cstr()

VALUE rb_usascii_str_new_cstr | ( | const char * | ptr | ) |

Definition at line 881 of file string.c.

References ENC_CODERANGE_7BIT, ENCODING_CODERANGE_SET, ptr, rb_str_new_cstr, rb_usascii_encindex, and str.

## ◆ rb_usascii_str_new_static()

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

Definition at line 939 of file string.c.

References ENCINDEX_US_ASCII, len, ptr, and rb_cString.

## ◆ rb_utf8_str_new()

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

Definition at line 849 of file string.c.

References len, ptr, rb_cString, rb_enc_associate_index(), rb_utf8_encindex, and str.

## ◆ rb_utf8_str_new_cstr()

VALUE rb_utf8_str_new_cstr | ( | const char * | ptr | ) |

Definition at line 889 of file string.c.

References ptr, rb_enc_associate_index(), rb_str_new_cstr, rb_utf8_encindex, and str.

## ◆ rb_utf8_str_new_static()

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

Definition at line 945 of file string.c.

References ENCINDEX_UTF_8, len, ptr, and rb_cString.

## Variable Documentation

## ◆ rb_str_setter

rb_gvar_setter_t rb_str_setter

Definition at line 130 of file string.h.