1 #ifndef RBIMPL_INTERN_STRING_H
2 #define RBIMPL_INTERN_STRING_H
23 #include "ruby/internal/config.h"
631 #define rb_str_dup_frozen rb_str_new_frozen
939 #define rb_hash_uint32(h, i) st_hash_uint32((h), (i))
942 #define rb_hash_uint(h, i) st_hash_uint((h), (i))
945 #define rb_hash_end(h) st_hash_end(h)
1349 rbimpl_strlen(const
char *str)
1351 return RBIMPL_CAST((
long)strlen(str));
1364 rbimpl_str_new_cstr(const
char *str)
1366 long len = rbimpl_strlen(str);
1380 rbimpl_usascii_str_new_cstr(const
char *str)
1382 long len = rbimpl_strlen(str);
1396 rbimpl_utf8_str_new_cstr(const
char *str)
1398 long len = rbimpl_strlen(str);
1412 rbimpl_external_str_new_cstr(const
char *str)
1414 long len = rbimpl_strlen(str);
1428 rbimpl_locale_str_new_cstr(const
char *str)
1430 long len = rbimpl_strlen(str);
1444 rbimpl_str_buf_new_cstr(const
char *str)
1446 long len = rbimpl_strlen(str);
1462 rbimpl_str_cat_cstr(
VALUE buf, const
char *str)
1464 long len = rbimpl_strlen(str);
1479 rbimpl_exc_new_cstr(
VALUE exc, const
char *str)
1481 long len = rbimpl_strlen(str);
1498 #define rb_str_new(str, len) \
1499 ((RBIMPL_CONSTANT_P(str) && \
1500 RBIMPL_CONSTANT_P(len) ? \
1501 rb_str_new_static : \
1502 rb_str_new) ((str), (len)))
1514 #define rb_str_new_cstr(str) \
1515 ((RBIMPL_CONSTANT_P(str) ? \
1516 rbimpl_str_new_cstr : \
1517 rb_str_new_cstr) (str))
1532 #define rb_usascii_str_new(str, len) \
1533 ((RBIMPL_CONSTANT_P(str) && \
1534 RBIMPL_CONSTANT_P(len) ? \
1535 rb_usascii_str_new_static : \
1536 rb_usascii_str_new) ((str), (len)))
1549 #define rb_utf8_str_new(str, len) \
1550 ((RBIMPL_CONSTANT_P(str) && \
1551 RBIMPL_CONSTANT_P(len) ? \
1552 rb_utf8_str_new_static : \
1553 rb_utf8_str_new) ((str), (len)))
1567 #define rb_usascii_str_new_cstr(str) \
1568 ((RBIMPL_CONSTANT_P(str) ? \
1569 rbimpl_usascii_str_new_cstr : \
1570 rb_usascii_str_new_cstr) (str))
1583 #define rb_utf8_str_new_cstr(str) \
1584 ((RBIMPL_CONSTANT_P(str) ? \
1585 rbimpl_utf8_str_new_cstr : \
1586 rb_utf8_str_new_cstr) (str))
1604 #define rb_external_str_new_cstr(str) \
1605 ((RBIMPL_CONSTANT_P(str) ? \
1606 rbimpl_external_str_new_cstr : \
1607 rb_external_str_new_cstr) (str))
1625 #define rb_locale_str_new_cstr(str) \
1626 ((RBIMPL_CONSTANT_P(str) ? \
1627 rbimpl_locale_str_new_cstr : \
1628 rb_locale_str_new_cstr) (str))
1639 #define rb_str_buf_new_cstr(str) \
1640 ((RBIMPL_CONSTANT_P(str) ? \
1641 rbimpl_str_buf_new_cstr : \
1642 rb_str_buf_new_cstr) (str))
1656 #define rb_str_cat_cstr(buf, str) \
1657 ((RBIMPL_CONSTANT_P(str) ? \
1658 rbimpl_str_cat_cstr : \
1659 rb_str_cat_cstr) ((buf), (str)))
1670 #define rb_exc_new_cstr(exc, str) \
1671 ((RBIMPL_CONSTANT_P(str) ? \
1672 rbimpl_exc_new_cstr : \
1673 rb_exc_new_cstr) ((exc), (str)))
1675 #define rb_str_new2 rb_str_new_cstr
1676 #define rb_str_new3 rb_str_new_shared
1677 #define rb_str_new4 rb_str_new_frozen
1678 #define rb_str_new5 rb_str_new_with_class
1679 #define rb_str_buf_new2 rb_str_buf_new_cstr
1680 #define rb_usascii_str_new2 rb_usascii_str_new_cstr
1681 #define rb_str_buf_cat rb_str_cat
1682 #define rb_str_buf_cat2 rb_str_cat_cstr
1683 #define rb_str_cat2 rb_str_cat_cstr
1692 #define rb_strlen_lit(str) (sizeof(str "") - 1)
1705 #define rb_str_new_lit(str) rb_str_new_static((str), rb_strlen_lit(str))
1719 #define rb_usascii_str_new_lit(str) rb_usascii_str_new_static((str), rb_strlen_lit(str))
1733 #define rb_utf8_str_new_lit(str) rb_utf8_str_new_static((str), rb_strlen_lit(str))
1748 #define rb_enc_str_new_lit(str, enc) rb_enc_str_new_static((str), rb_strlen_lit(str), (enc))
1750 #define rb_str_new_literal(str) rb_str_new_lit(str)
1751 #define rb_usascii_str_new_literal(str) rb_usascii_str_new_lit(str)
1752 #define rb_utf8_str_new_literal(str) rb_utf8_str_new_lit(str)
1753 #define rb_enc_str_new_literal(str, enc) rb_enc_str_new_lit(str, enc)
Defines RBIMPL_CONSTANT_P.
Defines RBIMPL_ATTR_DEPRECATED.
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
#define rb_str_buf_cat2
Old name of rb_usascii_str_new_cstr.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Creates an instance of the passed exception class.
VALUE rb_str_to_interned_str(VALUE str)
Identical to rb_interned_str(), except it takes a Ruby's string instead of C's.
void rb_str_free(VALUE str)
Destroys the given string for no reason.
VALUE rb_str_new_shared(VALUE str)
Identical to rb_str_new_cstr(), except it takes a Ruby's string instead of C's.
VALUE rb_str_plus(VALUE lhs, VALUE rhs)
Generates a new string, concatenating the former to the latter.
#define rb_utf8_str_new_cstr(str)
Identical to rb_str_new_cstr, except it generates a string of "UTF-8" encoding.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_filesystem_str_new(const char *ptr, long len)
Identical to rb_str_new(), except it generates a string of "filesystem" encoding.
VALUE rb_sym_to_s(VALUE sym)
This is an rb_sym2str() + rb_str_dup() combo.
VALUE rb_str_times(VALUE str, VALUE num)
Repetition of a string.
VALUE rb_external_str_new(const char *ptr, long len)
Identical to rb_str_new(), except it generates a string of "default external" encoding.
VALUE rb_str_tmp_new(long len)
Allocates a "temporary" string.
long rb_str_offset(VALUE str, long pos)
"Inverse" of rb_str_sublen().
VALUE rb_str_succ(VALUE orig)
Searches for the "successor" of a string.
int rb_str_hash_cmp(VALUE str1, VALUE str2)
Compares two strings.
VALUE rb_str_subseq(VALUE str, long beg, long len)
Identical to rb_str_substr(), except the numbers are interpreted as byte offsets instead of character...
VALUE rb_str_ellipsize(VALUE str, long len)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
st_index_t rb_memhash(const void *ptr, long len)
This is a universal hash function.
#define rb_str_new(str, len)
Allocates an instance of rb_cString.
void rb_str_shared_replace(VALUE dst, VALUE src)
Replaces the contents of the former with the latter.
#define rb_str_buf_cat
Just another name of rb_str_cat.
VALUE rb_str_new_static(const char *ptr, long len)
Identical to rb_str_new(), except it takes a C string literal.
#define rb_usascii_str_new(str, len)
Identical to rb_str_new, except it generates a string of "US ASCII" encoding.
size_t rb_str_capacity(VALUE str)
Queries the capacity of the given string.
VALUE rb_str_new_frozen(VALUE str)
Creates a frozen copy of the string, if necessary.
VALUE rb_str_dup(VALUE str)
Duplicates a string.
void rb_str_modify(VALUE str)
Declares that the string is about to be modified.
st_index_t rb_str_hash(VALUE str)
Calculates a hash value of a string.
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
VALUE rb_str_locktmp(VALUE str)
Obtains a "temporary lock" of the string.
long rb_str_strlen(VALUE str)
Counts the number of characters (not bytes) that are stored inside of the given string.
VALUE rb_str_resurrect(VALUE str)
I guess there is no use case of this function in extension libraries, but this is a routine identical...
#define rb_str_buf_new_cstr(str)
Identical to rb_str_new_cstr, except done differently.
#define rb_usascii_str_new_cstr(str)
Identical to rb_str_new_cstr, except it generates a string of "US ASCII" encoding.
VALUE rb_str_replace(VALUE dst, VALUE src)
Replaces the contents of the former object with the stringised contents of the latter.
char * rb_str_subpos(VALUE str, long beg, long *len)
Identical to rb_str_substr(), except it returns a C's string instead of Ruby's.
rb_gvar_setter_t rb_str_setter
This is a rb_gvar_setter_t that refutes non-string assignments.
VALUE rb_interned_str_cstr(const char *ptr)
Identical to rb_interned_str(), except it assumes the passed pointer is a pointer to a C's string.
VALUE rb_filesystem_str_new_cstr(const char *ptr)
Identical to rb_filesystem_str_new(), except it assumes the passed pointer is a pointer to a C string...
#define rb_external_str_new_cstr(str)
Identical to rb_str_new_cstr, except it generates a string of "default external" encoding.
VALUE rb_str_buf_append(VALUE dst, VALUE src)
Identical to rb_str_cat_cstr(), except it takes Ruby's string instead of C's.
long rb_str_sublen(VALUE str, long pos)
Byte offset to character offset conversion.
VALUE rb_str_equal(VALUE str1, VALUE str2)
Equality of two strings.
void rb_str_set_len(VALUE str, long len)
Overwrites the length of the string.
st_index_t rb_hash_start(st_index_t i)
Starts a series of hashing.
VALUE rb_str_inspect(VALUE str)
Generates a "readable" version of the receiver.
void rb_must_asciicompat(VALUE obj)
Asserts that the given string's encoding is (Ruby's definition of) ASCII compatible.
VALUE rb_interned_str(const char *ptr, long len)
Identical to rb_str_new(), except it returns an infamous "f"string.
int rb_str_cmp(VALUE lhs, VALUE rhs)
Compares two strings, as in strcmp(3).
VALUE rb_str_concat(VALUE dst, VALUE src)
Identical to rb_str_append(), except it also accepts an integer as a codepoint.
int rb_str_comparable(VALUE str1, VALUE str2)
Checks if two strings are comparable each other or not.
VALUE rb_str_buf_cat_ascii(VALUE dst, const char *src)
Identical to rb_str_cat_cstr(), except it additionally assumes the source string be a NUL terminated ...
VALUE rb_str_freeze(VALUE str)
This is the implementation of String#freeze.
void rb_str_update(VALUE dst, long beg, long len, VALUE src)
Replaces some (or all) of the contents of the given string.
VALUE rb_str_scrub(VALUE str, VALUE repl)
"Cleanses" the string.
#define rb_locale_str_new_cstr(str)
Identical to rb_external_str_new_cstr, except it generates a string of "locale" encoding instead of "...
VALUE rb_str_new_with_class(VALUE obj, const char *ptr, long len)
Identical to rb_str_new(), except it takes the class of the allocating object.
#define rb_str_dup_frozen
Just another name of rb_str_new_frozen.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_str_substr(VALUE str, long beg, long len)
This is the implementation of two-argumented String#slice.
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_unlocktmp(VALUE str)
Releases a lock formerly obtained by rb_str_locktmp().
VALUE rb_str_resize(VALUE str, long len)
Overwrites the length of the string.
VALUE rb_utf8_str_new_static(const char *ptr, long len)
Identical to rb_str_new_static(), except it generates a string of "UTF-8" encoding instead of "binary...
#define rb_utf8_str_new(str, len)
Identical to rb_str_new, except it generates a string of "UTF-8" encoding.
void rb_str_modify_expand(VALUE str, long capa)
Identical to rb_str_modify(), except it additionally expands the capacity of the receiver.
VALUE rb_str_dump(VALUE str)
"Inverse" of rb_eval_string().
VALUE rb_locale_str_new(const char *ptr, long len)
Identical to rb_str_new(), except it generates a string of "locale" encoding.
VALUE rb_str_buf_new(long capa)
Allocates a "string buffer".
VALUE rb_str_length(VALUE)
Identical to rb_str_strlen(), except it returns the value in rb_cInteger.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_drop_bytes(VALUE str, long len)
Shrinks the given string for the given number of bytes.
VALUE rb_str_split(VALUE str, const char *delim)
Divides the given string based on the given delimiter.
VALUE rb_usascii_str_new_static(const char *ptr, long len)
Identical to rb_str_new_static(), except it generates a string of "US ASCII" encoding instead of "bin...
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
Declares rb_define_variable().
void rb_gvar_setter_t(VALUE val, ID id, VALUE *data)
Type that represents a global variable setter function.
int capa
Designed capacity of the buffer.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
RBIMPL_ATTR_PURE() int rb_io_read_pending(rb_io_t *fptr)
Queries if the passed IO has any pending reads.
int len
Length of the buffer.
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Defines RBIMPL_ATTR_PURE.
uintptr_t VALUE
Type that represents a Ruby object.