19 #define RSTRING_EMBED_LEN_MAX \ 20 ((mrb_int)(sizeof(void*) * 3 + sizeof(void*) - 32 / CHAR_BIT - 1)) 41 #define RSTR_SET_TYPE_FLAG(s, type) (RSTR_UNSET_TYPE_FLAG(s), (s)->flags |= MRB_STR_##type) 42 #define RSTR_UNSET_TYPE_FLAG(s) ((s)->flags &= ~(MRB_STR_TYPE_MASK|MRB_STR_EMBED_LEN_MASK)) 44 #define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED) 45 #define RSTR_SET_EMBED_FLAG(s) ((s)->flags |= MRB_STR_EMBED) 46 #define RSTR_UNSET_EMBED_FLAG(s) ((s)->flags &= ~(MRB_STR_EMBED|MRB_STR_EMBED_LEN_MASK)) 47 #define RSTR_SET_EMBED_LEN(s, n) do {\ 49 (s)->flags &= ~MRB_STR_EMBED_LEN_MASK;\ 50 (s)->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\ 52 #define RSTR_SET_LEN(s, n) do {\ 53 if (RSTR_EMBED_P(s)) {\ 54 RSTR_SET_EMBED_LEN((s),(n));\ 57 (s)->as.heap.len = (mrb_int)(n);\ 60 #define RSTR_EMBED_PTR(s) (((struct RStringEmbed*)(s))->ary) 61 #define RSTR_EMBED_LEN(s)\ 62 (mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT) 63 #define RSTR_EMBEDDABLE_P(len) ((len) <= RSTRING_EMBED_LEN_MAX) 65 #define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_PTR(s) : (s)->as.heap.ptr) 66 #define RSTR_LEN(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len) 67 #define RSTR_CAPA(s) (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa) 69 #define RSTR_SHARED_P(s) ((s)->flags & MRB_STR_SHARED) 70 #define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED) 71 #define RSTR_UNSET_SHARED_FLAG(s) ((s)->flags &= ~MRB_STR_SHARED) 73 #define RSTR_FSHARED_P(s) ((s)->flags & MRB_STR_FSHARED) 74 #define RSTR_SET_FSHARED_FLAG(s) ((s)->flags |= MRB_STR_FSHARED) 75 #define RSTR_UNSET_FSHARED_FLAG(s) ((s)->flags &= ~MRB_STR_FSHARED) 77 #define RSTR_NOFREE_P(s) ((s)->flags & MRB_STR_NOFREE) 78 #define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE) 79 #define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE) 81 #ifdef MRB_UTF8_STRING 82 # define RSTR_ASCII_P(s) ((s)->flags & MRB_STR_ASCII) 83 # define RSTR_SET_ASCII_FLAG(s) ((s)->flags |= MRB_STR_ASCII) 84 # define RSTR_UNSET_ASCII_FLAG(s) ((s)->flags &= ~MRB_STR_ASCII) 85 # define RSTR_WRITE_ASCII_FLAG(s, v) (RSTR_UNSET_ASCII_FLAG(s), (s)->flags |= v) 86 # define RSTR_COPY_ASCII_FLAG(dst, src) RSTR_WRITE_ASCII_FLAG(dst, RSTR_ASCII_P(src)) 88 # define RSTR_ASCII_P(s) (void)0 89 # define RSTR_SET_ASCII_FLAG(s) (void)0 90 # define RSTR_UNSET_ASCII_FLAG(s) (void)0 91 # define RSTR_WRITE_ASCII_FLAG(s, v) (void)0 92 # define RSTR_COPY_ASCII_FLAG(dst, src) (void)0 95 #define RSTR_POOL_P(s) ((s)->flags & MRB_STR_POOL) 96 #define RSTR_SET_POOL_FLAG(s) ((s)->flags |= MRB_STR_POOL) 101 #define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s))) 102 #define RSTRING(s) mrb_str_ptr(s) 103 #define RSTRING_PTR(s) RSTR_PTR(RSTRING(s)) 104 #define RSTRING_EMBED_LEN(s) RSTR_EMBED_LEN(RSTRING(s)) 105 #define RSTRING_LEN(s) RSTR_LEN(RSTRING(s)) 106 #define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s)) 107 #define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s)) 109 #define RSTRING_CSTR(mrb,s) mrb_string_cstr(mrb, s) 111 #define MRB_STR_SHARED 1 112 #define MRB_STR_FSHARED 2 113 #define MRB_STR_NOFREE 4 114 #define MRB_STR_EMBED 8 115 #define MRB_STR_POOL 16 116 #define MRB_STR_ASCII 32 117 #define MRB_STR_EMBED_LEN_SHIFT 6 118 #define MRB_STR_EMBED_LEN_BITSIZE 5 119 #define MRB_STR_EMBED_LEN_MASK (((1 << MRB_STR_EMBED_LEN_BITSIZE) - 1) << MRB_STR_EMBED_LEN_SHIFT) 120 #define MRB_STR_TYPE_MASK (MRB_STR_POOL - 1) 133 #define mrb_str_index_lit(mrb, str, lit, off) mrb_str_index(mrb, str, lit, mrb_strlen_lit(lit), off); 421 #define mrb_str_cat_lit(mrb, str, lit) mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit)) 460 #define mrb_str_cat2(mrb, str, ptr) mrb_str_cat_cstr(mrb, str, ptr) 461 #define mrb_str_buf_cat(mrb, str, ptr, len) mrb_str_cat(mrb, str, ptr, len) 462 #define mrb_str_buf_append(mrb, str, str2) mrb_str_cat_str(mrb, str, str2) 464 mrb_bool mrb_str_beg_len(mrb_int str_len, mrb_int *begp, mrb_int *lenp);
467 #ifdef MRB_UTF8_STRING 468 mrb_int mrb_utf8_len(
const char *str, mrb_int byte_len);
mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2)
Adds str2 to the end of str1.
Definition: string.c:2827
char * mrb_str_to_cstr(mrb_state *mrb, mrb_value str)
Returns a newly allocated C string from a Ruby string.
Definition: string.c:859
mrb_value mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr)
Returns a concatenated string comprised of a Ruby string and a C string.
Definition: string.c:2812
int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2)
Returns 0 if both Ruby strings are equal.
Definition: string.c:987
mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len)
Resizes the string's length.
Definition: string.c:838
mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str)
Returns a printable version of str, surrounded by quote marks, with special characters escaped...
Definition: string.c:2847
#define MRB_BEGIN_DECL
Start declarations in C mode.
Definition: common.h:26
mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str)
Duplicates a string object.
Definition: string.c:1137
mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self)
Returns a symbol from a passed in Ruby string.
Definition: string.c:1897
mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2)
Returns true if the strings match and false if the strings don't match.
Definition: string.c:1073
mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len)
Returns a concatenated string comprised of a Ruby string and a C string.
Definition: string.c:2767
mrb_value mrb_ptr_to_str(mrb_state *mrb, void *p)
Converts pointer into a Ruby string.
Definition: string.c:1917
#define MRB_API
Declare a public MRuby API function.
Definition: common.h:73
mrb_value mrb_str_plus(mrb_state *mrb, mrb_value a, mrb_value b)
Adds two strings together.
Definition: string.c:876
const char mrb_digitmap[]
String class.
Definition: string.c:31
void mrb_str_concat(mrb_state *mrb, mrb_value self, mrb_value other)
Appends self to other.
Definition: string.c:869
#define MRB_END_DECL
End declarations in C mode.
Definition: common.h:28
mruby common platform definition"
mrb_int mrb_str_index(mrb_state *, mrb_value, const char *, mrb_int, mrb_int)
Finds the index of a substring in a string.
Definition: string.c:637
mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str)
Returns a converted string type.
Definition: string.c:1103
mrb_value mrb_ensure_string_type(mrb_state *mrb, mrb_value str)
Returns a Ruby string type.
Definition: object.c:582
mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
Returns a sub string.
Definition: string.c:1712
mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj)
Returns an object as a Ruby string.
Definition: string.c:1903
Definition: boxing_nan.h:39