Ruby
3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
|
Public APIs related to rb_cString. More...
#include "ruby/internal/config.h"
#include "ruby/internal/attr/deprecated.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 |
Just another name of rb_str_new_frozen. More... | |
#define | rb_hash_uint32(h, i) st_hash_uint32((h), (i)) |
Just another name of st_hash_uint32. More... | |
#define | rb_hash_uint(h, i) st_hash_uint((h), (i)) |
Just another name of st_hash_uint. More... | |
#define | rb_hash_end(h) st_hash_end(h) |
Just another name of st_hash_end. More... | |
#define | rb_str_new(str, len) |
Allocates an instance of rb_cString. More... | |
#define | rb_str_new_cstr(str) |
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string. More... | |
#define | rb_usascii_str_new(str, len) |
Identical to rb_str_new, except it generates a string of "US ASCII" encoding. More... | |
#define | rb_utf8_str_new(str, len) |
Identical to rb_str_new, except it generates a string of "UTF-8" encoding. More... | |
#define | rb_usascii_str_new_cstr(str) |
Identical to rb_str_new_cstr, except it generates a string of "US ASCII" encoding. More... | |
#define | rb_utf8_str_new_cstr(str) |
Identical to rb_str_new_cstr, except it generates a string of "UTF-8" encoding. More... | |
#define | rb_external_str_new_cstr(str) |
Identical to rb_str_new_cstr, except it generates a string of "default
external" encoding. More... | |
#define | rb_locale_str_new_cstr(str) |
Identical to rb_external_str_new_cstr, except it generates a string of "locale" encoding instead of "default external". More... | |
#define | rb_str_buf_new_cstr(str) |
Identical to rb_str_new_cstr, except done differently. More... | |
#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. More... | |
#define | rb_exc_new_cstr(exc, str) |
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string. More... | |
#define | rb_str_new2 rb_str_new_cstr |
Old name of rb_str_new_cstr. More... | |
#define | rb_str_new3 rb_str_new_shared |
Old name of rb_str_new_shared. More... | |
#define | rb_str_new4 rb_str_new_frozen |
Old name of rb_str_new_frozen. More... | |
#define | rb_str_new5 rb_str_new_with_class |
Old name of rb_str_new_with_class. More... | |
#define | rb_str_buf_new2 rb_str_buf_new_cstr |
Old name of rb_str_buf_new_cstr. More... | |
#define | rb_usascii_str_new2 rb_usascii_str_new_cstr |
Old name of rb_usascii_str_new_cstr. More... | |
#define | rb_str_buf_cat rb_str_cat |
Just another name of rb_str_cat. More... | |
#define | rb_str_buf_cat2 rb_str_cat_cstr |
Old name of rb_usascii_str_new_cstr. More... | |
#define | rb_str_cat2 rb_str_cat_cstr |
Old name of rb_str_cat_cstr. More... | |
#define | rb_strlen_lit(str) (sizeof(str "") - 1) |
Length of a string literal. More... | |
#define | rb_str_new_lit(str) rb_str_new_static((str), rb_strlen_lit(str)) |
Identical to rb_str_new_static(), except it cannot take string variables. More... | |
#define | rb_usascii_str_new_lit(str) rb_usascii_str_new_static((str), rb_strlen_lit(str)) |
Identical to rb_usascii_str_new_static(), except it cannot take string variables. More... | |
#define | rb_utf8_str_new_lit(str) rb_utf8_str_new_static((str), rb_strlen_lit(str)) |
Identical to rb_utf8_str_new_static(), except it cannot take string variables. More... | |
#define | rb_enc_str_new_lit(str, enc) rb_enc_str_new_static((str), rb_strlen_lit(str), (enc)) |
Identical to rb_enc_str_new_static(), except it cannot take string variables. More... | |
#define | rb_str_new_literal(str) rb_str_new_lit(str) |
Just another name of rb_str_new_lit. More... | |
#define | rb_usascii_str_new_literal(str) rb_usascii_str_new_lit(str) |
Just another name of rb_usascii_str_new_lit. More... | |
#define | rb_utf8_str_new_literal(str) rb_utf8_str_new_lit(str) |
Just another name of rb_utf8_str_new_lit. More... | |
#define | rb_enc_str_new_literal(str, enc) rb_enc_str_new_lit(str, enc) |
Just another name of rb_enc_str_new_lit. More... | |
Functions | |
VALUE | rb_str_new (const char *ptr, long len) |
Allocates an instance of rb_cString. More... | |
VALUE | rb_str_new_cstr (const char *ptr) |
Identical to rb_str_new(), except it assumes the passed pointer is a pointer to a C string. More... | |
VALUE | rb_str_new_shared (VALUE str) |
Identical to rb_str_new_cstr(), except it takes a Ruby's string instead of C's. More... | |
VALUE | rb_str_new_frozen (VALUE str) |
Creates a frozen copy of the string, if necessary. More... | |
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. More... | |
VALUE | rb_external_str_new (const char *ptr, long len) |
Identical to rb_str_new(), except it generates a string of "default
external" encoding. More... | |
VALUE | rb_external_str_new_cstr (const char *ptr) |
Identical to rb_external_str_new(), except it assumes the passed pointer is a pointer to a C string. More... | |
VALUE | rb_locale_str_new (const char *ptr, long len) |
Identical to rb_str_new(), except it generates a string of "locale" encoding. More... | |
VALUE | rb_locale_str_new_cstr (const char *ptr) |
Identical to rb_locale_str_new(), except it assumes the passed pointer is a pointer to a C string. More... | |
VALUE | rb_filesystem_str_new (const char *ptr, long len) |
Identical to rb_str_new(), except it generates a string of "filesystem" encoding. More... | |
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. More... | |
VALUE | rb_str_buf_new (long capa) |
Allocates a "string buffer". More... | |
VALUE | rb_str_buf_new_cstr (const char *ptr) |
This is a rb_str_buf_new() + rb_str_buf_cat() combo. More... | |
VALUE | rb_str_tmp_new (long len) |
Allocates a "temporary" string. More... | |
VALUE | rb_usascii_str_new (const char *ptr, long len) |
Identical to rb_str_new(), except it generates a string of "US ASCII" encoding. More... | |
VALUE | rb_usascii_str_new_cstr (const char *ptr) |
Identical to rb_str_new_cstr(), except it generates a string of "US ASCII" encoding. More... | |
VALUE | rb_utf8_str_new (const char *ptr, long len) |
Identical to rb_str_new(), except it generates a string of "UTF-8" encoding. More... | |
VALUE | rb_utf8_str_new_cstr (const char *ptr) |
Identical to rb_str_new_cstr(), except it generates a string of "UTF-8" encoding. More... | |
VALUE | rb_str_to_interned_str (VALUE str) |
Identical to rb_interned_str(), except it takes a Ruby's string instead of C's. More... | |
VALUE | rb_interned_str (const char *ptr, long len) |
Identical to rb_str_new(), except it returns an infamous "f"string. More... | |
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. More... | |
void | rb_str_free (VALUE str) |
Destroys the given string for no reason. More... | |
void | rb_str_shared_replace (VALUE dst, VALUE src) |
Replaces the contents of the former with the latter. More... | |
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. More... | |
VALUE | rb_str_buf_cat (VALUE, const char *, long) |
Just another name of rb_str_cat. More... | |
VALUE | rb_str_buf_cat2 (VALUE, const char *) |
Just another name of rb_str_cat_cstr. More... | |
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 ASCII string. More... | |
VALUE | rb_obj_as_string (VALUE obj) |
Try converting an object to its stringised representation using its to_s method, if any. More... | |
VALUE | rb_check_string_type (VALUE obj) |
Try converting an object to its stringised representation using its to_str method, if any. More... | |
void | rb_must_asciicompat (VALUE obj) |
Asserts that the given string's encoding is (Ruby's definition of) ASCII compatible. More... | |
VALUE | rb_str_dup (VALUE str) |
Duplicates a string. More... | |
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 to rb_str_dup(), except it always creates an instance of rb_cString regardless of the given object's class. More... | |
VALUE | rb_str_locktmp (VALUE str) |
Obtains a "temporary lock" of the string. More... | |
VALUE | rb_str_unlocktmp (VALUE str) |
Releases a lock formerly obtained by rb_str_locktmp(). More... | |
VALUE | rb_str_dup_frozen (VALUE) |
Just another name of rb_str_new_frozen. More... | |
VALUE | rb_str_plus (VALUE lhs, VALUE rhs) |
Generates a new string, concatenating the former to the latter. More... | |
VALUE | rb_str_times (VALUE str, VALUE num) |
Repetition of a string. More... | |
long | rb_str_sublen (VALUE str, long pos) |
Byte offset to character offset conversion. More... | |
VALUE | rb_str_substr (VALUE str, long beg, long len) |
This is the implementation of two-argumented String#slice . More... | |
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 offsets. More... | |
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. More... | |
void | rb_str_modify (VALUE str) |
Declares that the string is about to be modified. More... | |
void | rb_str_modify_expand (VALUE str, long capa) |
Identical to rb_str_modify(), except it additionally expands the capacity of the receiver. More... | |
VALUE | rb_str_freeze (VALUE str) |
This is the implementation of String#freeze . More... | |
void | rb_str_set_len (VALUE str, long len) |
Overwrites the length of the string. More... | |
VALUE | rb_str_resize (VALUE str, long len) |
Overwrites the length of the string. More... | |
VALUE | rb_str_cat (VALUE dst, const char *src, long srclen) |
Destructively appends the passed contents to the string. More... | |
VALUE | rb_str_cat_cstr (VALUE dst, const char *src) |
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string. More... | |
VALUE | rb_str_cat2 (VALUE, const char *) |
Just another name of rb_str_cat_cstr. More... | |
VALUE | rb_str_append (VALUE dst, VALUE src) |
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating. More... | |
VALUE | rb_str_concat (VALUE dst, VALUE src) |
Identical to rb_str_append(), except it also accepts an integer as a codepoint. More... | |
st_index_t | rb_memhash (const void *ptr, long len) |
This is a universal hash function. More... | |
st_index_t | rb_hash_start (st_index_t i) |
Starts a series of hashing. More... | |
st_index_t | rb_str_hash (VALUE str) |
Calculates a hash value of a string. More... | |
int | rb_str_hash_cmp (VALUE str1, VALUE str2) |
Compares two strings. More... | |
int | rb_str_comparable (VALUE str1, VALUE str2) |
Checks if two strings are comparable each other or not. More... | |
int | rb_str_cmp (VALUE lhs, VALUE rhs) |
Compares two strings, as in strcmp(3) . More... | |
VALUE | rb_str_equal (VALUE str1, VALUE str2) |
Equality of two strings. More... | |
VALUE | rb_str_drop_bytes (VALUE str, long len) |
Shrinks the given string for the given number of bytes. More... | |
void | rb_str_update (VALUE dst, long beg, long len, VALUE src) |
Replaces some (or all) of the contents of the given string. More... | |
VALUE | rb_str_replace (VALUE dst, VALUE src) |
Replaces the contents of the former object with the stringised contents of the latter. More... | |
VALUE | rb_str_inspect (VALUE str) |
Generates a "readable" version of the receiver. More... | |
VALUE | rb_str_dump (VALUE str) |
"Inverse" of rb_eval_string(). More... | |
VALUE | rb_str_split (VALUE str, const char *delim) |
Divides the given string based on the given delimiter. More... | |
VALUE | rb_str_intern (VALUE str) |
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString. More... | |
VALUE | rb_sym_to_s (VALUE sym) |
This is an rb_sym2str() + rb_str_dup() combo. More... | |
long | rb_str_strlen (VALUE str) |
Counts the number of characters (not bytes) that are stored inside of the given string. More... | |
VALUE | rb_str_length (VALUE) |
Identical to rb_str_strlen(), except it returns the value in rb_cInteger. More... | |
long | rb_str_offset (VALUE str, long pos) |
"Inverse" of rb_str_sublen(). More... | |
size_t | rb_str_capacity (VALUE str) |
Queries the capacity of the given string. More... | |
VALUE | rb_str_ellipsize (VALUE str, long len) |
Shortens str and adds three dots, an ellipsis, if it is longer than len characters. More... | |
VALUE | rb_str_scrub (VALUE str, VALUE repl) |
"Cleanses" the string. More... | |
VALUE | rb_str_succ (VALUE orig) |
Searches for the "successor" of a string. More... | |
Special strings that are backended by C string literals. | |
*_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. | |
VALUE | rb_str_new_static (const char *ptr, long len) |
Identical to rb_str_new(), except it takes a C string literal. More... | |
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 "binary". More... | |
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". More... | |
Variables | |
rb_gvar_setter_t | rb_str_setter |
This is a rb_gvar_setter_t that refutes non-string assignments. More... | |
Public APIs related to rb_cString.
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 string.h.
#define rb_enc_str_new_lit | ( | str, | |
enc | |||
) | rb_enc_str_new_static((str), rb_strlen_lit(str), (enc)) |
Identical to rb_enc_str_new_static(), except it cannot take string variables.
[in] | str | A C string literal. |
[in] | enc | A pointer to an encoding. |
str
must not be a variable. #define rb_enc_str_new_literal | ( | str, | |
enc | |||
) | rb_enc_str_new_lit(str, enc) |
Just another name of rb_enc_str_new_lit.
#define rb_exc_new_cstr | ( | exc, | |
str | |||
) |
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
[out] | exc | A subclass of rb_eException. |
[in] | str | Message to raise. |
exc
whose message is str
. str
must not be a null pointer. #define rb_external_str_new_cstr | ( | str | ) |
Identical to rb_str_new_cstr, except it generates a string of "default external" encoding.
[in] | str | A C string. |
rb_eNoMemError | Failed to allocate memory. |
valid_encoding?
of the result object. str
must not be a null pointer. #define rb_hash_end | ( | h | ) | st_hash_end(h) |
#define rb_hash_uint | ( | h, | |
i | |||
) | st_hash_uint((h), (i)) |
#define rb_hash_uint32 | ( | h, | |
i | |||
) | st_hash_uint32((h), (i)) |
#define rb_locale_str_new_cstr | ( | str | ) |
Identical to rb_external_str_new_cstr, except it generates a string of "locale" encoding instead of "default external".
[in] | str | A C string. |
rb_eNoMemError | Failed to allocate memory. |
valid_encoding?
of the result object. str
must not be a null pointer. #define rb_str_buf_cat rb_str_cat |
Just another name of rb_str_cat.
#define rb_str_buf_new_cstr | ( | str | ) |
Identical to rb_str_new_cstr, except done differently.
[in] | str | A C string. |
rb_eNoMemError | Failed to allocate memory. |
str
. str
must not be a null pointer. #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.
[out] | buf | Destination object. |
[in] | str | Contents to append. |
rb_eArgError | Result string too big. |
buf
. buf
must not be any arbitrary objects except RString. str
must not be a null pointer. buf
has the contents of str
appended. #define rb_str_dup_frozen rb_str_new_frozen |
Just another name of rb_str_new_frozen.
#define rb_str_new | ( | str, | |
len | |||
) |
Allocates an instance of rb_cString.
[in] | str | A memory region of len bytes length. |
[in] | len | Length of ptr , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
len
bytes length, of "binary" encoding, whose contents are verbatim copy of str
. len
bytes of continuous memory region shall be accessible via str
. #define rb_str_new_cstr | ( | str | ) |
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
[in] | str | A C string. |
rb_eNoMemError | Failed to allocate memory. |
str
. str
must not be a null pointer. #define rb_str_new_lit | ( | str | ) | rb_str_new_static((str), rb_strlen_lit(str)) |
Identical to rb_str_new_static(), except it cannot take string variables.
[in] | str | A C string literal. |
str
must not be a variable. #define rb_str_new_literal | ( | str | ) | rb_str_new_lit(str) |
Just another name of rb_str_new_lit.
#define rb_strlen_lit | ( | str | ) | (sizeof(str "") - 1) |
#define rb_usascii_str_new | ( | str, | |
len | |||
) |
Identical to rb_str_new, except it generates a string of "US ASCII" encoding.
This is different from rb_external_str_new(), not only for the output encoding, but also it doesn't convert the contents.
[in] | str | A memory region of len bytes length. |
[in] | len | Length of str , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
len
bytes length, of "US ASCII" encoding, whose contents are verbatim copy of str
. #define rb_usascii_str_new_cstr | ( | str | ) |
Identical to rb_str_new_cstr, except it generates a string of "US ASCII" encoding.
It can also be seen as a routine Identical to rb_usascii_str_new, except it assumes the passed pointer is a pointer to a C string.
[in] | str | A C string. |
rb_eNoMemError | Failed to allocate memory. |
str
. str
must not be a null pointer. #define rb_usascii_str_new_lit | ( | str | ) | rb_usascii_str_new_static((str), rb_strlen_lit(str)) |
Identical to rb_usascii_str_new_static(), except it cannot take string variables.
[in] | str | A C string literal. |
str
must not be a variable. #define rb_usascii_str_new_literal | ( | str | ) | rb_usascii_str_new_lit(str) |
Just another name of rb_usascii_str_new_lit.
#define rb_utf8_str_new | ( | str, | |
len | |||
) |
Identical to rb_str_new, except it generates a string of "UTF-8" encoding.
[in] | str | A memory region of len bytes length. |
[in] | len | Length of str , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
len
bytes length, of "UTF-8" encoding, whose contents are verbatim copy of str
. #define rb_utf8_str_new_cstr | ( | str | ) |
Identical to rb_str_new_cstr, except it generates a string of "UTF-8" encoding.
It can also be seen as a routine Identical to rb_utf8_str_new, except it assumes the passed pointer is a pointer to a C string.
[in] | str | A C string. |
rb_eNoMemError | Failed to allocate memory. |
str
. str
must not be a null pointer. #define rb_utf8_str_new_lit | ( | str | ) | rb_utf8_str_new_static((str), rb_strlen_lit(str)) |
Identical to rb_utf8_str_new_static(), except it cannot take string variables.
[in] | str | A C string literal. |
str
must not be a variable. #define rb_utf8_str_new_literal | ( | str | ) | rb_utf8_str_new_lit(str) |
Just another name of rb_utf8_str_new_lit.
Try converting an object to its stringised representation using its to_str
method, if any.
If there is no such thing, returns RUBY_Qnil.
[in] | obj | Arbitrary ruby object to stringise. |
rb_eTypeError | obj.to_str returned something non-String. |
RUBY_Qnil | No conversion from obj to String defined. |
obj
. Definition at line 2845 of file string.c.
Referenced by rb_ary_join(), rb_check_id(), rb_check_symbol(), rb_io_extract_encoding_option(), rb_str_format(), rb_String(), and rb_to_encoding_index().
VALUE rb_external_str_new | ( | const char * | ptr, |
long | len | ||
) |
Identical to rb_str_new(), except it generates a string of "default external" encoding.
[in] | ptr | A memory region of len bytes length. |
[in] | len | Length of ptr , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
valid_encoding?
of the result object. VALUE rb_external_str_new_cstr | ( | const char * | ptr | ) |
Identical to rb_external_str_new(), except it assumes the passed pointer is a pointer to a C string.
It can also be seen as a routine identical to rb_str_new_cstr(), except it generates a string of "default external" encoding.
[in] | ptr | A C string. |
rb_eNoMemError | Failed to allocate memory. |
valid_encoding?
of the result object. ptr
must not be a null pointer. VALUE rb_filesystem_str_new | ( | const char * | ptr, |
long | len | ||
) |
Identical to rb_str_new(), except it generates a string of "filesystem" encoding.
It can also be seen as a routine identical to rb_external_str_new(), except it generates a string of "filesystem" encoding instead of "default external" encoding.
[in] | ptr | A memory region of len bytes length. |
[in] | len | Length of ptr , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
valid_encoding?
of the result object. 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.
It can also be seen as a routine identical to rb_external_str_new_cstr(), except it generates a string of "filesystem" encoding instead of "default external".
[in] | ptr | A C string. |
rb_eNoMemError | Failed to allocate memory. |
valid_encoding?
of the result object. ptr
must not be a null pointer. st_index_t rb_hash_start | ( | st_index_t | i | ) |
Starts a series of hashing.
Suppose you have a struct:
It is not a wise idea to call rb_memhash() over it, because there could be padding bits. Instead you should explicitly iterate over each fields:
[in] | i | Initial value. |
VALUE rb_interned_str | ( | const char * | ptr, |
long | len | ||
) |
Identical to rb_str_new(), except it returns an infamous "f"string.
What is a fstring? Well it is a special subkind of strings that is immutable, deduped globally, and managed by our GC. It is much like a Symbol (in fact Symbols are dynamic these days and are backended using fstrings). This concept has been silently introduced at some point in 2.x era. Since then it gained wider acceptance in the core. Starting from 3.x extension libraries can also generate ones.
[in] | ptr | A memory region of len bytes length. |
[in] | len | Length of ptr , in bytes, not including the terminating NUL character. |
rb_eArgError | len is negative. |
len
bytes length, of "binary" encoding, whose contents are identical to that of ptr
. len
bytes of continuous memory region shall be accessible via ptr
. Definition at line 12493 of file string.c.
Referenced by rb_interned_str_cstr().
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.
It can also be seen as a routine identical to rb_str_to_interned_str(), except it takes a C's string instead of Ruby's. Or it can also be seen as a routine identical to rb_str_new_cstr(), except it returns an infamous "f"string.
[in] | ptr | A C string. |
rb_eNoMemError | Failed to allocate memory. |
ptr
. ptr
must not be a null pointer. VALUE rb_locale_str_new | ( | const char * | ptr, |
long | len | ||
) |
Identical to rb_str_new(), except it generates a string of "locale" encoding.
It can also be seen as a routine identical to rb_external_str_new(), except it generates a string of "locale" encoding instead of "default external" encoding.
[in] | ptr | A memory region of len bytes length. |
[in] | len | Length of ptr , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
valid_encoding?
of the result object. VALUE rb_locale_str_new_cstr | ( | const char * | ptr | ) |
Identical to rb_locale_str_new(), except it assumes the passed pointer is a pointer to a C string.
It can also be seen as a routine identical to rb_external_str_new_cstr(), except it generates a string of "locale" encoding instead of "default external".
[in] | ptr | A C string. |
rb_eNoMemError | Failed to allocate memory. |
valid_encoding?
of the result object. ptr
must not be a null pointer. st_index_t rb_memhash | ( | const void * | ptr, |
long | len | ||
) |
This is a universal hash function.
[in] | ptr | Target message. |
[in] | len | Length of ptr in bytes. |
void rb_must_asciicompat | ( | VALUE | obj | ) |
Asserts that the given string's encoding is (Ruby's definition of) ASCII compatible.
[in] | obj | An instance of rb_cString. |
rb_eEncCompatError | obj is ASCII incompatible. |
Definition at line 2694 of file string.c.
Referenced by rb_str_format().
Try converting an object to its stringised representation using its to_s
method, if any.
If there is no such thing, it resorts to rb_any_to_s() output.
[in] | obj | Arbitrary ruby object to stringise. |
Definition at line 1770 of file string.c.
Referenced by rb_inspect(), rb_io_puts(), rb_p(), and rb_str_format().
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
[out] | dst | Destination object. |
[in] | src | Source object. |
rb_eEncCompatError | Can't mix the encodings. |
rb_eArgError | Result string too big. |
dst
. dst
must not be any arbitrary objects except RString. dst
has the contents of src
appended, with encoding converted into dst
's one, into the end of dst
. Definition at line 3662 of file string.c.
Referenced by rb_str_concat(), and rb_str_ellipsize().
Identical to rb_str_cat_cstr(), except it takes Ruby's string instead of C's.
It can also be seen as a routine identical to rb_str_shared_replace(), except it appends instead of replaces.
[out] | dst | Destination object. |
[in] | src | Source object. |
rb_eEncCompatError | Can't mix the encodings. |
rb_eArgError | Result string too big. |
dst
. dst
has the contents of src
appended, with encoding converted into dst
's one, into the end of dst
. Definition at line 3628 of file string.c.
Referenced by rb_str_append().
Just another name of rb_str_cat.
Referenced by rb_str_buf_new_cstr(), and rb_str_cat_cstr().
Just another name of rb_str_cat_cstr.
Identical to rb_str_cat_cstr(), except it additionally assumes the source string be a NUL terminated ASCII string.
[out] | dst | Destination object. |
[in] | src | Source string. |
rb_eArgError | Result string too big. |
dst
. dst
must not be any arbitrary object except RString. src
must be a NUL terminated ASCII string. dst
has the contents of src
appended, with encoding converted into dst
's one, into the end of dst
. VALUE rb_str_buf_new | ( | long | capa | ) |
Allocates a "string buffer".
A string buffer here is an instance of rb_cString, whose capacity is bigger than the length of it. If you can say that a string grows to a specific amount of bytes, this could be effective than resizing a string over and over again and again.
[in] | capa | Designed capacity of the generating string. |
capa
. Definition at line 1627 of file string.c.
Referenced by rb_ary_join(), rb_econv_append(), rb_enc_vsprintf(), rb_reg_regsub(), rb_str_buf_new_cstr(), rb_str_conv_enc_opts(), rb_str_format(), and rb_str_inspect().
VALUE rb_str_buf_new_cstr | ( | const char * | ptr | ) |
This is a rb_str_buf_new() + rb_str_buf_cat() combo.
[in] | ptr | A C string. |
rb_eNoMemError | Failed to allocate memory. |
ptr
. ptr
must not be a null pointer. size_t rb_str_capacity | ( | VALUE | str | ) |
Queries the capacity of the given string.
[in] | str | String in question. |
Definition at line 934 of file string.c.
Referenced by rb_econv_append(), and rb_str_format().
Destructively appends the passed contents to the string.
[out] | dst | Destination object. |
[in] | src | Contents to append. |
[in] | srclen | Length of src . |
rb_eArgError | srclen is negative. |
dst
. dst
must not be any arbitrary objects except RString. dst
has the contents of ptr
appended. Definition at line 3430 of file string.c.
Referenced by rb_id_attrset(), and rb_str_ellipsize().
Just another name of rb_str_cat_cstr.
Referenced by rb_econv_open_exc(), and rb_find_file_ext().
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
[out] | dst | Destination object. |
[in] | src | Contents to append. |
rb_eArgError | Result string too big. |
rb_eArgError | src is a null pointer. |
dst
. dst
must not be any arbitrary objects except RString. src
must not be a null pointer. dst
has the contents of src
appended. Definition at line 3440 of file string.c.
Referenced by rb_ext_resolve_symbol(), and ruby_init_loadpath().
Compares two strings, as in strcmp(3)
.
This does not consider the current locale, but considers the encodings of both sides instead.
[in] | lhs | A string. |
[in] | rhs | Another string. |
-1 | lhs is "bigger than" rhs . |
1 | rhs is "bigger than" lhs . |
0 | Otherwise, e.g. not comparable. |
Checks if two strings are comparable each other or not.
Because rb_str_cmp() must return "lesser than" or "greater than" information, comparing two strings needs a stricter restriction. Both sides must be in a same set of strings which have total order. This is to check that property. Intuitive it sounds? But they can have different encodings. A character and another might or might not appear in the same order in their codepoints. It is complicated than you think.
[in] | str1 | A string. |
[in] | str2 | Another string. |
1 | They agree on a total order. |
0 | Otherwise. |
Definition at line 4062 of file string.c.
Referenced by rb_str_cmp(), and rb_str_hash_cmp().
Identical to rb_str_append(), except it also accepts an integer as a codepoint.
This resembles String#<<
.
[out] | dst | Destination object. |
[in] | src | Source object, String or Numeric. |
rb_eRangeError | Source numeric is out of range. |
rb_eEncCompatError | Source string too long. |
rb_eArgError | Result string too big. |
dst
. dst
must not be any arbitrary objects except RString. dst
has the contents of src
appended, with encoding converted into dst
's one, into the end of dst
. Shrinks the given string for the given number of bytes.
[out] | str | String to squash. |
[in] | len | Number of bytes to reduce. |
rb_eRuntimeError | str is locktmp -ed. |
rb_eFrozenError | str is frozen. |
str
. str
must not be any arbitrary objects except RString. str
is shrunken. "Inverse" of rb_eval_string().
Returns a quoted version of the string. All non-printing characters are replaced by \uNNNN
or \xHH
notation and all special characters are escaped. The result string is guaranteed to render a string of the same contents when passed to eval
and friends.
[in] | str | String to dump. |
rb_eRuntimeError | Too many escape sequences causes integer overflow on the length of the string. |
Definition at line 7299 of file string.c.
Referenced by rb_econv_prepare_options().
Duplicates a string.
[in] | str | String in question to duplicate. |
str
must be of RString. Definition at line 1911 of file string.c.
Referenced by rb_class_path(), rb_find_file_ext(), rb_id_attrset(), rb_str_conv_enc_opts(), and rb_str_intern().
Just another name of rb_str_new_frozen.
Shortens str
and adds three dots, an ellipsis, if it is longer than len
characters.
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 that of passed one. The class of returned string is equal to that of passed one.
[in] | str | The string to shorten. |
[in] | len | The maximum string length. |
rb_eIndexError | len is negative. |
str | No need to add ellipsis. |
otherwise | A new, shortened string. |
Equality of two strings.
If str2
is not a String, it resorts to str2 == str1
. Otherwise if they are not comparable, returns RUBY_Qfalse. Otherwise if they have the same contents and the length, returns RUBY_Qtrue. Otherwise, returns RUBY_Qfalse.
[in] | str1 | A string. |
[in] | str2 | Another string. |
RUBY_Qtrue | They are equal. |
RUBY_Qfalse | They are either different, or not comparable. |
void rb_str_free | ( | VALUE | str | ) |
Destroys the given string for no reason.
[out] | str | The string to be executed. |
String#clear
could be what you want. This is the implementation of String#freeze
.
[out] | str | Target string to freeze. |
Definition at line 3163 of file string.c.
Referenced by ruby_script().
st_index_t rb_str_hash | ( | VALUE | str | ) |
Calculates a hash value of a string.
This is one of the two functions that constructs struct st_hash_type.
[in] | str | An object of RString. |
str
must not be any arbitrary object except RString. Compares two strings.
This is one of the two functions that constructs struct st_hash_type.
[in] | str1 | A string. |
[in] | str2 | Another string. |
1 | They have identical contents, length, and encodings. |
0 | Otherwise. |
Generates a "readable" version of the receiver.
eval
. [in] | str | String to inspect. |
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
[in] | str | The name of the id. |
rb_eRuntimeError | Too many symbols. |
str
. str
must not be any arbitrary object except RString. Definition at line 878 of file symbol.c.
Referenced by rb_f_global_variables(), and rb_to_symbol().
Identical to rb_str_strlen(), except it returns the value in rb_cInteger.
[in] | str | Target string to query. |
Obtains a "temporary lock" of the string.
This advisory locking mechanism prevents other cooperating threads from tampering the receiver. The same thing could be done via freeze mechanism, but this one can also be unlocked using rb_str_unlocktmp().
[out] | str | String to lock. |
rb_eRuntimeError | str already locked. |
void rb_str_modify | ( | VALUE | str | ) |
Declares that the string is about to be modified.
This for instance let the string have a dedicated backend storage.
[out] | str | String about to be modified. |
rb_eRuntimeError | str is locktmp -ed. |
rb_eFrozenError | str is frozen. |
str
must not be any arbitrary objects except RString. Definition at line 2642 of file string.c.
Referenced by rb_check_frozen_inline(), and rb_str_vcatf().
void rb_str_modify_expand | ( | VALUE | str, |
long | capa | ||
) |
Identical to rb_str_modify(), except it additionally expands the capacity of the receiver.
[out] | str | Target string to modify. |
[in] | capa | Additional capacity to add. |
rb_eArgError | capa is negative. |
rb_eRuntimeError | str is locktmp -ed. |
rb_eFrozenError | str is frozen. |
str
must not be any arbitrary objects except RString. capa
bytes. Definition at line 2650 of file string.c.
Referenced by rb_econv_append().
VALUE rb_str_new | ( | const char * | ptr, |
long | len | ||
) |
Allocates an instance of rb_cString.
[in] | ptr | A memory region of len bytes length. |
[in] | len | Length of ptr , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
len
bytes length, of "binary" encoding, whose contents are verbatim copy of ptr
. len
bytes of continuous memory region shall be accessible via ptr
. Definition at line 1020 of file string.c.
Referenced by rb_ary_join(), rb_enc_str_new(), rb_exc_new(), rb_external_str_new_with_enc(), rb_io_ungetbyte(), rb_path_check(), rb_reg_quote(), rb_str_dump(), rb_str_ellipsize(), rb_str_format(), rb_str_new_cstr(), rb_str_succ(), rb_usascii_str_new(), and rb_write_error2().
VALUE rb_str_new_cstr | ( | const char * | ptr | ) |
Identical to rb_str_new(), except it assumes the passed pointer is a pointer to a C string.
[in] | ptr | A C string. |
rb_eNoMemError | Failed to allocate memory. |
rb_eArgError | ptr is a null pointer. |
ptr
. ptr
must not be a null pointer. Definition at line 1054 of file string.c.
Referenced by rb_econv_open_exc(), rb_ext_resolve_symbol(), rb_file_open(), rb_load_file(), rb_path2class(), rb_str_split(), rb_throw_obj(), rb_usascii_str_new_cstr(), and rb_utf8_str_new_cstr().
Creates a frozen copy of the string, if necessary.
This function does nothing when the passed string is already frozen. Otherwise, it allocates a copy of it, which is frozen. The passed string is untouched either ways.
[in] | str | An object of RString. |
str
must not be any arbitrary object except RString. Definition at line 1446 of file string.c.
Referenced by rb_econv_prepare_options(), rb_econv_substr_append(), rb_io_open_descriptor(), and ruby_set_script_name().
Identical to rb_str_new_cstr(), except it takes a Ruby's string instead of C's.
Implementation wise it creates a string that shares the backend memory region with the receiver. So the name. But there is no way for extension libraries to know if a string is of such variant.
[in] | str | An object of RString. |
str
must not be any arbitrary object except RString. VALUE rb_str_new_static | ( | const char * | ptr, |
long | len | ||
) |
Identical to rb_str_new(), except it takes a C string literal.
[in] | ptr | A C string literal. |
[in] | len | strlen(ptr) . |
rb_eArgError | len out of range of size_t . |
ptr
must be a C string constant. Identical to rb_str_new(), except it takes the class of the allocating object.
[in] | obj | A string-ish object. |
[in] | ptr | A memory region of len bytes length. |
[in] | len | Length of ptr , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
obj
, of len
bytes length, of "binary" encoding, whose contents are verbatim copy of ptr
. len
bytes of continuous memory region shall be accessible via ptr
. long rb_str_offset | ( | VALUE | str, |
long | pos | ||
) |
"Inverse" of rb_str_sublen().
This function scans the contents to find the byte index that matches the character index. Generally speaking this is an O(n)
operation. Could be slow.
[in] | str | The string to scan. |
[in] | pos | Offset, in characters. |
Generates a new string, concatenating the former to the latter.
It can also be seen as a routine identical to rb_str_append(), except it doesn't tamper the passed strings to create a new one instead.
[in] | lhs | Source string #1. |
[in] | rhs | Source string #2. |
rb_eEncCompatError | Can't mix the encodings. |
rb_eArgError | Result string too big. |
rhs
concatenated to lhs
. +
s in Ruby. This is one of such things. There has been a long discussion around +
s in programming languages. Replaces the contents of the former object with the stringised contents of the latter.
[out] | dst | Destination object. |
[in] | src | Source object. |
rb_eTypeError | src has no implicit conversion to String. |
rb_eRuntimeError | dst is locktmp -ed. |
rb_eFrozenError | dst is frozen. |
dst
. dst
must not be any arbitrary object except RString. dst
's former components are abandoned. It now has the identical encoding, length, and contents to src
. Overwrites the length of the string.
In contrast to rb_str_set_len(), this function can also expand a string.
[out] | str | String to shrink. |
[in] | len | New length of the string. |
rb_eArgError | len is negative. |
rb_eRuntimeError | str is locktmp -ed. |
rb_eFrozenError | str is frozen. |
str
. str
must not be any arbitrary objects except RString. str
is either expanded or shrunken to have its length be len
. Definition at line 3302 of file string.c.
Referenced by rb_find_file(), rb_find_file_ext(), rb_reg_quote(), rb_str_concat(), rb_str_format(), rb_str_freeze(), and ruby_init_loadpath().
I guess there is no use case of this function in extension libraries, but this is a routine identical to rb_str_dup(), except it always creates an instance of rb_cString regardless of the given object's class.
This makes the most sense when the passed string is formerly hidden by rb_obj_hide().
[in] | str | A string, possibly hidden. |
"Cleanses" the string.
A string has its encoding and its contents. They, in practice, do not always fit. There are strings in the wild that are "broken"; include bit patterns that are not allowed by its encoding. That can happen when a user copy&pasted something bad, network input got clobbered by a middleman, cosmic rays hit the physical memory, and many more occasions. This function takes such strings, and fills the "broken" portion with the passed replacement bit pattern.
This function also takes a ruby block. That is a neat way to do things, but can be annoying when the caller function want to use a block for another purpose.
[in] | str | Target string to scrub. |
[in] | repl | Replacement string. When it is a string, this function takes that as a replacement. When it is RUBY_Qnil, this function tries to yield a block (if any) and takes its evaluated value as a replacement. In case of RUBY_Qnil without a block, this function takes an encoding-specific default character (U+FFFD , for instance) as a last resort. |
rb_eTypeError | repl is neither string nor nil. |
rb_eArgError | repl itself is broken. |
rb_eEncCompatError | repl and str are incompatible. |
RUBY_Qnil | str is already clean. |
otherwise | A new, clean string. |
void rb_str_set_len | ( | VALUE | str, |
long | len | ||
) |
Overwrites the length of the string.
Typically this is used to shrink a string that was formerly expanded.
[out] | str | String to shrink. |
[in] | len | New length of the string. |
rb_eRuntimeError | str is locktmp -ed. |
rb_eFrozenError | str is frozen. |
str
must not be any arbitrary objects except RString. str
's length is set to len
. Definition at line 3254 of file string.c.
Referenced by rb_ary_join(), rb_econv_append(), rb_find_file_ext(), and rb_str_format().
Replaces the contents of the former with the latter.
[out] | dst | Destination object. |
[in] | src | Source object. |
dst
's former components are abandoned. It now has the identical encoding, length, and contents to src
. Divides the given string based on the given delimiter.
This is the 1-argument 0-block version of String#split
.
[in] | str | Object in question to split. |
[in] | delim | Delimiter, in C string. |
rb_eTypeError | str has no implicit conversion to String. |
rb_eArgError | delim is a null pointer. |
str
. If delim
is an empty C string (i.e. ""
), str
is split into each characters. If delim
is a C string whose sole content is a whitespace (i.e. " "
), str
is split on whitespaces, with leading and trailing whitespace and runs of contiguous whitespace characters ignored. Otherwise, str
is split according to delim
. long rb_str_strlen | ( | VALUE | str | ) |
Counts the number of characters (not bytes) that are stored inside of the given string.
This of course depends on its encoding. Also this function generally runs in O(n), because for instance you have to scan the entire string to know how many characters are there in a UTF-8 string.
[in] | str | Target string to query. |
long rb_str_sublen | ( | VALUE | str, |
long | pos | ||
) |
Byte offset to character offset conversion.
This makes sense when the receiver is in a multibyte encoding. The string's i-th character does not always sit at its i-th byte. This function scans the contents to find the character index that matches the byte index. Generally speaking this is an O(n)
operation. Could be slow.
[in] | str | The string to scan. |
[in] | pos | Offset, in bytes. |
Definition at line 2996 of file string.c.
Referenced by rb_reg_match(), and rb_reg_match2().
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.
[in] | str | The string to slice. |
[in] | beg | Requested offset of the substring. |
[in,out] | len | Requested length of the substring. |
NULL | Parameters out of range. |
otherwise | A pointer inside of str 's backend storage where the specified substring exist. |
str
must not be any arbitrary objects except RString. len
is updated to have the length of the return value. Identical to rb_str_substr(), except the numbers are interpreted as byte offsets instead of character offsets.
[in] | str | The string to slice. |
[in] | beg | Requested offset of the substring. |
[in] | len | Requested length of the substring. |
str
. str
must not be any arbitrary objects except RString. beg
and len
must not point to OOB contents. Definition at line 3046 of file string.c.
Referenced by rb_reg_match_last(), rb_reg_match_post(), rb_reg_match_pre(), rb_reg_nth_match(), rb_reg_regsub(), rb_str_ellipsize(), and ruby_init_loadpath().
This is the implementation of two-argumented String#slice
.
len
found in str
at offset beg
:str
if beg
is negative:beg
is equal to the length of str
:beg
is out of range:str
if len
is large:len
is negative:[in] | str | The string to slice. |
[in] | beg | Requested offset of the substring. |
[in] | len | Requested length of the substring. |
RUBY_Qnil | Parameters out of range. |
otherwise | A new string whose contents is the specified substring of str . |
str
must not be any arbitrary objects except RString. Searches for the "successor" of a string.
This function is complicated! This is the only function in the entire ruby API (either C or Ruby) that generates a string out of thin air. First, the successor to an empty string is a new empty string:
Otherwise the successor is calculated by "incrementing" characters. The first character to be incremented is the rightmost alphanumeric: or, if no alphanumerics, the rightmost character:
The successor to a digit is another digit, "carrying" to the next-left character for a "rollover" from 9 to 0, and prepending another digit if necessary:
The successor to a letter is another letter of the same case, carrying to the next-left character for a rollover, and prepending another same-case letter if necessary:
The successor to a non-alphanumeric character is the next character in the underlying character set's collating sequence, carrying to the next-left character for a rollover, and prepending another character if necessary:
Carrying can occur between and among mixtures of alphanumeric characters:
[in] | orig | Predecessor string. |
VALUE rb_str_tmp_new | ( | long | len | ) |
Allocates a "temporary" string.
This is a hidden empty string. Handy on occasions.
[in] | len | Designed length of the string. |
Definition at line 1655 of file string.c.
Referenced by rb_find_file(), and rb_find_file_ext().
Identical to rb_interned_str(), except it takes a Ruby's string instead of C's.
It can also be seen as a routine identical to rb_str_new_shared(), except it returns an infamous "f"string.
[in] | str | An object of RString. |
str
must not be any arbitrary object except RString. Releases a lock formerly obtained by rb_str_locktmp().
[out] | str | String to unlock. |
rb_eRuntimeError | str already unlocked. |
Replaces some (or all) of the contents of the given string.
This is the implementation of three-argumented String#[]=
.
[out] | dst | Target string to update. |
[in] | beg | Offset of the affected portion. |
[in] | len | Length of the affected portion. |
[in] | src | Object to be assigned. |
rb_eTypeError | src has no implicit conversion to String. |
rb_eIndexError | len is negative, or beg is OOB. |
rb_eRuntimeError | dst is locktmp -ed. |
rb_eFrozenError | dst is frozen. |
dst
from beg
to len
is the stringised representation of src
. If that replacement string is not the same length as the portion it is replacing, dst
will be resized accordingly. This is an rb_sym2str() + rb_str_dup() combo.
[in] | sym | A symbol to query. |
VALUE rb_usascii_str_new | ( | const char * | ptr, |
long | len | ||
) |
Identical to rb_str_new(), except it generates a string of "US ASCII" encoding.
This is different from rb_external_str_new(), not only for the output encoding, but also it doesn't convert the contents.
[in] | ptr | A memory region of len bytes length. |
[in] | len | Length of ptr , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
len
bytes length, of "US ASCII" encoding, whose contents are verbatim copy of ptr
. Definition at line 1026 of file string.c.
Referenced by rb_ary_join(), rb_fix2str(), and rb_str_ellipsize().
VALUE rb_usascii_str_new_cstr | ( | const char * | ptr | ) |
Identical to rb_str_new_cstr(), except it generates a string of "US ASCII" encoding.
It can also be seen as a routine Identical to rb_usascii_str_new(), except it assumes the passed pointer is a pointer to a C string.
[in] | ptr | A C string. |
rb_eNoMemError | Failed to allocate memory. |
rb_eArgError | ptr is a null pointer. |
ptr
. ptr
must not be a null pointer. Definition at line 1066 of file string.c.
Referenced by rb_locale_charmap().
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 "binary".
It can also be seen as a routine identical to rb_usascii_str_new(), except it takes a C string literal.
[in] | ptr | A C string literal. |
[in] | len | strlen(ptr) . |
rb_eArgError | len out of range of size_t . |
ptr
must be a C string constant. VALUE rb_utf8_str_new | ( | const char * | ptr, |
long | len | ||
) |
Identical to rb_str_new(), except it generates a string of "UTF-8" encoding.
[in] | ptr | A memory region of len bytes length. |
[in] | len | Length of ptr , in bytes, not including the terminating NUL character. |
rb_eNoMemError | Failed to allocate len+1 bytes. |
rb_eArgError | len is negative. |
len
bytes length, of "UTF-8" encoding, whose contents are verbatim copy of ptr
. VALUE rb_utf8_str_new_cstr | ( | const char * | ptr | ) |
Identical to rb_str_new_cstr(), except it generates a string of "UTF-8" encoding.
It can also be seen as a routine Identical to rb_usascii_str_new(), except it assumes the passed pointer is a pointer to a C string.
[in] | ptr | A C string. |
rb_eNoMemError | Failed to allocate memory. |
rb_eArgError | ptr is a null pointer. |
ptr
. ptr
must not be a null pointer. 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".
It can also be seen as a routine identical to rb_utf8_str_new(), except it takes a C string literal.
[in] | ptr | A C string literal. |
[in] | len | strlen(ptr) . |
rb_eArgError | len out of range of size_t . |
ptr
must be a C string constant. rb_gvar_setter_t rb_str_setter |
This is a rb_gvar_setter_t that refutes non-string assignments.
rb_eTypeError | Passed something non-string. |