w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

string.h File Reference
#include "common.h"
Include dependency graph for string.h:

Go to the source code of this file.

Classes

struct  RString
 
struct  RStringEmbed
 

Macros

#define RSTRING_EMBED_LEN_MAX    ((mrb_int)(sizeof(void*) * 3 + sizeof(void*) - 32 / CHAR_BIT - 1))
 
#define RSTR_SET_TYPE_FLAG(s, type)   (RSTR_UNSET_TYPE_FLAG(s), (s)->flags |= MRB_STR_##type)
 
#define RSTR_UNSET_TYPE_FLAG(s)   ((s)->flags &= ~(MRB_STR_TYPE_MASK|MRB_STR_EMBED_LEN_MASK))
 
#define RSTR_EMBED_P(s)   ((s)->flags & MRB_STR_EMBED)
 
#define RSTR_SET_EMBED_FLAG(s)   ((s)->flags |= MRB_STR_EMBED)
 
#define RSTR_UNSET_EMBED_FLAG(s)   ((s)->flags &= ~(MRB_STR_EMBED|MRB_STR_EMBED_LEN_MASK))
 
#define RSTR_SET_EMBED_LEN(s, n)
 
#define RSTR_SET_LEN(s, n)
 
#define RSTR_EMBED_PTR(s)   (((struct RStringEmbed*)(s))->ary)
 
#define RSTR_EMBED_LEN(s)    (mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT)
 
#define RSTR_EMBEDDABLE_P(len)   ((len) <= RSTRING_EMBED_LEN_MAX)
 
#define RSTR_PTR(s)   ((RSTR_EMBED_P(s)) ? RSTR_EMBED_PTR(s) : (s)->as.heap.ptr)
 
#define RSTR_LEN(s)   ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len)
 
#define RSTR_CAPA(s)   (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa)
 
#define RSTR_SHARED_P(s)   ((s)->flags & MRB_STR_SHARED)
 
#define RSTR_SET_SHARED_FLAG(s)   ((s)->flags |= MRB_STR_SHARED)
 
#define RSTR_UNSET_SHARED_FLAG(s)   ((s)->flags &= ~MRB_STR_SHARED)
 
#define RSTR_FSHARED_P(s)   ((s)->flags & MRB_STR_FSHARED)
 
#define RSTR_SET_FSHARED_FLAG(s)   ((s)->flags |= MRB_STR_FSHARED)
 
#define RSTR_UNSET_FSHARED_FLAG(s)   ((s)->flags &= ~MRB_STR_FSHARED)
 
#define RSTR_NOFREE_P(s)   ((s)->flags & MRB_STR_NOFREE)
 
#define RSTR_SET_NOFREE_FLAG(s)   ((s)->flags |= MRB_STR_NOFREE)
 
#define RSTR_UNSET_NOFREE_FLAG(s)   ((s)->flags &= ~MRB_STR_NOFREE)
 
#define RSTR_ASCII_P(s)   (void)0
 
#define RSTR_SET_ASCII_FLAG(s)   (void)0
 
#define RSTR_UNSET_ASCII_FLAG(s)   (void)0
 
#define RSTR_WRITE_ASCII_FLAG(s, v)   (void)0
 
#define RSTR_COPY_ASCII_FLAG(dst, src)   (void)0
 
#define mrb_str_ptr(s)   ((struct RString*)(mrb_ptr(s)))
 
#define RSTRING(s)   mrb_str_ptr(s)
 
#define RSTRING_PTR(s)   RSTR_PTR(RSTRING(s))
 
#define RSTRING_EMBED_LEN(s)   RSTR_EMBED_LEN(RSTRING(s))
 
#define RSTRING_LEN(s)   RSTR_LEN(RSTRING(s))
 
#define RSTRING_CAPA(s)   RSTR_CAPA(RSTRING(s))
 
#define RSTRING_END(s)   (RSTRING_PTR(s) + RSTRING_LEN(s))
 
#define RSTRING_CSTR(mrb, s)   mrb_string_cstr(mrb, s)
 
#define MRB_STR_SHARED   1
 
#define MRB_STR_FSHARED   2
 
#define MRB_STR_NOFREE   4
 
#define MRB_STR_EMBED   8 /* type flags up to here */
 
#define MRB_STR_ASCII   16
 
#define MRB_STR_EMBED_LEN_SHIFT   6
 
#define MRB_STR_EMBED_LEN_BIT   5
 
#define MRB_STR_EMBED_LEN_MASK   (((1 << MRB_STR_EMBED_LEN_BIT) - 1) << MRB_STR_EMBED_LEN_SHIFT)
 
#define MRB_STR_TYPE_MASK   15
 
#define mrb_str_index_lit(mrb, str, lit, off)   mrb_str_index(mrb, str, lit, mrb_strlen_lit(lit), off);
 
#define mrb_str_buf_new(mrb, capa)   mrb_str_new_capa(mrb, (capa))
 
#define mrb_str_to_str(mrb, str)   mrb_obj_as_string(mrb, str)
 
#define mrb_str_cat_lit(mrb, str, lit)   mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit))
 
#define mrb_str_cat2(mrb, str, ptr)   mrb_str_cat_cstr(mrb, str, ptr)
 
#define mrb_str_buf_cat(mrb, str, ptr, len)   mrb_str_cat(mrb, str, ptr, len)
 
#define mrb_str_buf_append(mrb, str, str2)   mrb_str_cat_str(mrb, str, str2)
 

Functions

mrb_int mrb_str_strlen (mrb_state *, struct RString *)
 
void mrb_gc_free_str (mrb_state *, struct RString *)
 
void mrb_str_modify (mrb_state *mrb, struct RString *s)
 
void mrb_str_modify_keep_ascii (mrb_state *mrb, struct RString *s)
 
mrb_int mrb_str_index (mrb_state *mrb, mrb_value str, const char *p, mrb_int len, mrb_int offset)
 
void mrb_str_concat (mrb_state *mrb, mrb_value self, mrb_value other)
 
mrb_value mrb_str_plus (mrb_state *mrb, mrb_value a, mrb_value b)
 
mrb_value mrb_ptr_to_str (mrb_state *mrb, void *p)
 
mrb_value mrb_obj_as_string (mrb_state *mrb, mrb_value obj)
 
mrb_value mrb_str_resize (mrb_state *mrb, mrb_value str, mrb_int len)
 
mrb_value mrb_str_substr (mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
 
mrb_value mrb_ensure_string_type (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_check_string_type (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_string_type (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_str_new_capa (mrb_state *mrb, size_t capa)
 
const char * mrb_string_cstr (mrb_state *mrb, mrb_value str)
 
const char * mrb_string_value_cstr (mrb_state *mrb, mrb_value *str)
 
const char * mrb_string_value_ptr (mrb_state *mrb, mrb_value str)
 
mrb_int mrb_string_value_len (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_str_dup (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_str_intern (mrb_state *mrb, mrb_value self)
 
mrb_value mrb_str_to_inum (mrb_state *mrb, mrb_value str, mrb_int base, mrb_bool badcheck)
 
mrb_value mrb_cstr_to_inum (mrb_state *mrb, const char *s, mrb_int base, mrb_bool badcheck)
 
double mrb_str_to_dbl (mrb_state *mrb, mrb_value str, mrb_bool badcheck)
 
double mrb_cstr_to_dbl (mrb_state *mrb, const char *s, mrb_bool badcheck)
 
mrb_bool mrb_str_equal (mrb_state *mrb, mrb_value str1, mrb_value str2)
 
mrb_value mrb_str_cat (mrb_state *mrb, mrb_value str, const char *ptr, size_t len)
 
mrb_value mrb_str_cat_cstr (mrb_state *mrb, mrb_value str, const char *ptr)
 
mrb_value mrb_str_cat_str (mrb_state *mrb, mrb_value str, mrb_value str2)
 
mrb_value mrb_str_append (mrb_state *mrb, mrb_value str, mrb_value str2)
 
int mrb_str_cmp (mrb_state *mrb, mrb_value str1, mrb_value str2)
 
char * mrb_str_to_cstr (mrb_state *mrb, mrb_value str)
 
uint32_t mrb_str_hash (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_str_dump (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_str_inspect (mrb_state *mrb, mrb_value str)
 
mrb_bool mrb_str_beg_len (mrb_int str_len, mrb_int *begp, mrb_int *lenp)
 
mrb_value mrb_str_byte_subseq (mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
 

Variables

const char mrb_digitmap []
 

Detailed Description

See Copyright Notice in mruby.h

Definition in file string.h.

Macro Definition Documentation

◆ MRB_STR_ASCII

#define MRB_STR_ASCII   16

Definition at line 112 of file string.h.

◆ mrb_str_buf_append

#define mrb_str_buf_append (   mrb,
  str,
  str2 
)    mrb_str_cat_str(mrb, str, str2)

Definition at line 457 of file string.h.

◆ mrb_str_buf_cat

#define mrb_str_buf_cat (   mrb,
  str,
  ptr,
  len 
)    mrb_str_cat(mrb, str, ptr, len)

Definition at line 456 of file string.h.

◆ mrb_str_buf_new

#define mrb_str_buf_new (   mrb,
  capa 
)    mrb_str_new_capa(mrb, (capa))

Definition at line 342 of file string.h.

◆ mrb_str_cat2

#define mrb_str_cat2 (   mrb,
  str,
  ptr 
)    mrb_str_cat_cstr(mrb, str, ptr)

Definition at line 455 of file string.h.

◆ mrb_str_cat_lit

#define mrb_str_cat_lit (   mrb,
  str,
  lit 
)    mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit))

Definition at line 417 of file string.h.

◆ MRB_STR_EMBED

#define MRB_STR_EMBED   8 /* type flags up to here */

Definition at line 111 of file string.h.

◆ MRB_STR_EMBED_LEN_BIT

#define MRB_STR_EMBED_LEN_BIT   5

Definition at line 114 of file string.h.

◆ MRB_STR_EMBED_LEN_MASK

#define MRB_STR_EMBED_LEN_MASK   (((1 << MRB_STR_EMBED_LEN_BIT) - 1) << MRB_STR_EMBED_LEN_SHIFT)

Definition at line 115 of file string.h.

◆ MRB_STR_EMBED_LEN_SHIFT

#define MRB_STR_EMBED_LEN_SHIFT   6

Definition at line 113 of file string.h.

◆ MRB_STR_FSHARED

#define MRB_STR_FSHARED   2

Definition at line 109 of file string.h.

◆ mrb_str_index_lit

#define mrb_str_index_lit (   mrb,
  str,
  lit,
  off 
)    mrb_str_index(mrb, str, lit, mrb_strlen_lit(lit), off);

Definition at line 128 of file string.h.

◆ MRB_STR_NOFREE

#define MRB_STR_NOFREE   4

Definition at line 110 of file string.h.

◆ mrb_str_ptr

#define mrb_str_ptr (   s)    ((struct RString*)(mrb_ptr(s)))

Returns a pointer from a Ruby string

Definition at line 98 of file string.h.

◆ MRB_STR_SHARED

#define MRB_STR_SHARED   1

Definition at line 108 of file string.h.

◆ mrb_str_to_str

#define mrb_str_to_str (   mrb,
  str 
)    mrb_obj_as_string(mrb, str)

Returns a converted string type. For type checking, non converting mrb_to_str is recommended. obsolete: use mrb_obj_as_string() instead.

Definition at line 382 of file string.h.

◆ MRB_STR_TYPE_MASK

#define MRB_STR_TYPE_MASK   15

Definition at line 116 of file string.h.

◆ RSTR_ASCII_P

#define RSTR_ASCII_P (   s)    (void)0

Definition at line 88 of file string.h.

◆ RSTR_CAPA

#define RSTR_CAPA (   s)    (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa)

Definition at line 67 of file string.h.

◆ RSTR_COPY_ASCII_FLAG

#define RSTR_COPY_ASCII_FLAG (   dst,
  src 
)    (void)0

Definition at line 92 of file string.h.

◆ RSTR_EMBED_LEN

#define RSTR_EMBED_LEN (   s)     (mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT)

Definition at line 61 of file string.h.

◆ RSTR_EMBED_P

#define RSTR_EMBED_P (   s)    ((s)->flags & MRB_STR_EMBED)

Definition at line 44 of file string.h.

◆ RSTR_EMBED_PTR

#define RSTR_EMBED_PTR (   s)    (((struct RStringEmbed*)(s))->ary)

Definition at line 60 of file string.h.

◆ RSTR_EMBEDDABLE_P

#define RSTR_EMBEDDABLE_P (   len)    ((len) <= RSTRING_EMBED_LEN_MAX)

Definition at line 63 of file string.h.

◆ RSTR_FSHARED_P

#define RSTR_FSHARED_P (   s)    ((s)->flags & MRB_STR_FSHARED)

Definition at line 73 of file string.h.

◆ RSTR_LEN

#define RSTR_LEN (   s)    ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len)

Definition at line 66 of file string.h.

◆ RSTR_NOFREE_P

#define RSTR_NOFREE_P (   s)    ((s)->flags & MRB_STR_NOFREE)

Definition at line 77 of file string.h.

◆ RSTR_PTR

#define RSTR_PTR (   s)    ((RSTR_EMBED_P(s)) ? RSTR_EMBED_PTR(s) : (s)->as.heap.ptr)

Definition at line 65 of file string.h.

◆ RSTR_SET_ASCII_FLAG

#define RSTR_SET_ASCII_FLAG (   s)    (void)0

Definition at line 89 of file string.h.

◆ RSTR_SET_EMBED_FLAG

#define RSTR_SET_EMBED_FLAG (   s)    ((s)->flags |= MRB_STR_EMBED)

Definition at line 45 of file string.h.

◆ RSTR_SET_EMBED_LEN

#define RSTR_SET_EMBED_LEN (   s,
  n 
)
Value:
do {\
size_t tmp_n = (n);\
(s)->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\
} while (0)
#define n
Definition: t4ht.c:1290
#define s
Definition: afcover.h:80
#define flags
#define MRB_STR_EMBED_LEN_MASK
Definition: string.h:115
#define MRB_STR_EMBED_LEN_SHIFT
Definition: string.h:113

Definition at line 47 of file string.h.

◆ RSTR_SET_FSHARED_FLAG

#define RSTR_SET_FSHARED_FLAG (   s)    ((s)->flags |= MRB_STR_FSHARED)

Definition at line 74 of file string.h.

◆ RSTR_SET_LEN

#define RSTR_SET_LEN (   s,
  n 
)
Value:
do {\
if (RSTR_EMBED_P(s)) {\
RSTR_SET_EMBED_LEN((s),(n));\
}\
else {\
(s)->as.heap.len = (mrb_ssize)(n);\
}\
} while (0)
char * as
Definition: fixwrites.c:8
#define RSTR_EMBED_P(s)
Definition: string.h:44
mrb_int mrb_ssize
Definition: value.h:175

Definition at line 52 of file string.h.

◆ RSTR_SET_NOFREE_FLAG

#define RSTR_SET_NOFREE_FLAG (   s)    ((s)->flags |= MRB_STR_NOFREE)

Definition at line 78 of file string.h.

◆ RSTR_SET_SHARED_FLAG

#define RSTR_SET_SHARED_FLAG (   s)    ((s)->flags |= MRB_STR_SHARED)

Definition at line 70 of file string.h.

◆ RSTR_SET_TYPE_FLAG

#define RSTR_SET_TYPE_FLAG (   s,
  type 
)    (RSTR_UNSET_TYPE_FLAG(s), (s)->flags |= MRB_STR_##type)

Definition at line 41 of file string.h.

◆ RSTR_SHARED_P

#define RSTR_SHARED_P (   s)    ((s)->flags & MRB_STR_SHARED)

Definition at line 69 of file string.h.

◆ RSTR_UNSET_ASCII_FLAG

#define RSTR_UNSET_ASCII_FLAG (   s)    (void)0

Definition at line 90 of file string.h.

◆ RSTR_UNSET_EMBED_FLAG

#define RSTR_UNSET_EMBED_FLAG (   s)    ((s)->flags &= ~(MRB_STR_EMBED|MRB_STR_EMBED_LEN_MASK))

Definition at line 46 of file string.h.

◆ RSTR_UNSET_FSHARED_FLAG

#define RSTR_UNSET_FSHARED_FLAG (   s)    ((s)->flags &= ~MRB_STR_FSHARED)

Definition at line 75 of file string.h.

◆ RSTR_UNSET_NOFREE_FLAG

#define RSTR_UNSET_NOFREE_FLAG (   s)    ((s)->flags &= ~MRB_STR_NOFREE)

Definition at line 79 of file string.h.

◆ RSTR_UNSET_SHARED_FLAG

#define RSTR_UNSET_SHARED_FLAG (   s)    ((s)->flags &= ~MRB_STR_SHARED)

Definition at line 71 of file string.h.

◆ RSTR_UNSET_TYPE_FLAG

#define RSTR_UNSET_TYPE_FLAG (   s)    ((s)->flags &= ~(MRB_STR_TYPE_MASK|MRB_STR_EMBED_LEN_MASK))

Definition at line 42 of file string.h.

◆ RSTR_WRITE_ASCII_FLAG

#define RSTR_WRITE_ASCII_FLAG (   s,
  v 
)    (void)0

Definition at line 91 of file string.h.

◆ RSTRING

#define RSTRING (   s)    mrb_str_ptr(s)

Definition at line 99 of file string.h.

◆ RSTRING_CAPA

#define RSTRING_CAPA (   s)    RSTR_CAPA(RSTRING(s))

Definition at line 103 of file string.h.

◆ RSTRING_CSTR

#define RSTRING_CSTR (   mrb,
  s 
)    mrb_string_cstr(mrb, s)

Definition at line 106 of file string.h.

◆ RSTRING_EMBED_LEN

#define RSTRING_EMBED_LEN (   s)    RSTR_EMBED_LEN(RSTRING(s))

Definition at line 101 of file string.h.

◆ RSTRING_EMBED_LEN_MAX

#define RSTRING_EMBED_LEN_MAX    ((mrb_int)(sizeof(void*) * 3 + sizeof(void*) - 32 / CHAR_BIT - 1))

Definition at line 19 of file string.h.

◆ RSTRING_END

#define RSTRING_END (   s)    (RSTRING_PTR(s) + RSTRING_LEN(s))

Definition at line 104 of file string.h.

◆ RSTRING_LEN

#define RSTRING_LEN (   s)    RSTR_LEN(RSTRING(s))

Definition at line 102 of file string.h.

◆ RSTRING_PTR

#define RSTRING_PTR (   s)    RSTR_PTR(RSTRING(s))

Definition at line 100 of file string.h.

Function Documentation

◆ mrb_check_string_type()

mrb_value mrb_check_string_type ( mrb_state mrb,
mrb_value  str 
)

Definition at line 616 of file object.c.

References mrb_nil_value(), mrb_string_p, and str.

Referenced by join_ary(), mrb_convert_to_integer(), and mrb_str_format().

◆ mrb_cstr_to_dbl()

double mrb_cstr_to_dbl ( mrb_state mrb,
const char *  s,
mrb_bool  badcheck 
)

Definition at line 2556 of file string.c.

References mrb_str_len_to_dbl(), s, and strlen().

◆ mrb_cstr_to_inum()

mrb_value mrb_cstr_to_inum ( mrb_state mrb,
const char *  s,
mrb_int  base,
mrb_bool  badcheck 
)

Definition at line 2384 of file string.c.

References base, mrb_str_len_to_inum(), str, and strlen().

◆ mrb_ensure_string_type()

mrb_value mrb_ensure_string_type ( mrb_state mrb,
mrb_value  str 
)

Returns a Ruby string type.

Parameters
mrbThe current mruby state.
strRuby string.
Returns
[mrb_value] A Ruby string.

Definition at line 607 of file object.c.

References E_TYPE_ERROR, mrb_raisef(), mrb_string_p, and str.

Referenced by mrb_file_s_unlink(), mrb_mod_const_get(), mrb_str_concat_m(), mrb_str_end_with(), mrb_str_start_with(), mrb_string_type(), and mrb_to_str().

◆ mrb_gc_free_str()

void mrb_gc_free_str ( mrb_state mrb,
struct RString str 
)

Definition at line 269 of file string.c.

References mrb_free(), RSTR_EMBED_P, RSTR_FSHARED_P, RSTR_NOFREE_P, RSTR_SHARED_P, str, and str_decref().

Referenced by obj_free().

◆ mrb_obj_as_string()

mrb_value mrb_obj_as_string ( mrb_state mrb,
mrb_value  obj 
)

Returns an object as a Ruby string.

Parameters
mrbThe current mruby state.
objAn object to return as a Ruby string.
Returns
[mrb_value] An object as a Ruby string.

Definition at line 1913 of file string.c.

References mrb_fixnum_to_str(), mrb_mod_to_s(), MRB_SYM, mrb_sym_str(), mrb_symbol, MRB_TT_CLASS, MRB_TT_INTEGER, MRB_TT_MODULE, MRB_TT_SCLASS, MRB_TT_STRING, MRB_TT_SYMBOL, mrb_type(), and mrb_type_convert().

Referenced by join_ary(), mrb_ary_join(), mrb_check_type(), mrb_exc_inspect(), mrb_inspect(), mrb_print(), mrb_puts(), mrb_str_concat(), mrb_str_format(), mrb_string_value_ptr(), mrb_vformat(), p(), and range_to_s().

◆ mrb_ptr_to_str()

mrb_value mrb_ptr_to_str ( mrb_state mrb,
void p 
)

Converts pointer into a Ruby string.

Parameters
mrbThe current mruby state.
pThe pointer to convert to Ruby string.
Returns
[mrb_value] Returns a new Ruby String.

Definition at line 1932 of file string.c.

References c, CHAR_BIT, mrb_digitmap, mrb_obj_value(), n, NULL, p, p1, p2, RSTR_PTR, RSTR_SET_LEN, str_new(), and uintptr_t.

Referenced by class_name_str(), mrb_any_to_s(), mrb_obj_iv_inspect(), and mrb_proc_inspect().

◆ mrb_str_append()

mrb_value mrb_str_append ( mrb_state mrb,
mrb_value  str,
mrb_value  str2 
)

Adds str2 to the end of str1.

Definition at line 2729 of file string.c.

References mrb_str_cat_str(), mrb_to_str(), str1, and str2.

Referenced by mrb_file_realpath().

◆ mrb_str_beg_len()

mrb_bool mrb_str_beg_len ( mrb_int  str_len,
mrb_int begp,
mrb_int lenp 
)

Definition at line 623 of file string.c.

References FALSE, str_len(), and TRUE.

Referenced by mrb_str_byteslice(), and str_substr().

◆ mrb_str_byte_subseq()

mrb_value mrb_str_byte_subseq ( mrb_state mrb,
mrb_value  str,
mrb_int  beg,
mrb_int  len 
)

◆ mrb_str_cat()

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.

Parameters
mrbThe current mruby state.
strRuby string.
ptrA C string.
lenlength of C string.
Returns
[mrb_value] A Ruby string.
See also
mrb_str_cat_cstr

Definition at line 2669 of file string.c.

References RString::capa, E_ARGUMENT_ERROR, len, memcpy, mrb_assert_int_fit, mrb_raise(), MRB_SSIZE_MAX, mrb_str_modify(), mrb_str_ptr, fc-lang::off, ptr, resize_capa(), RSTR_CAPA, RSTR_LEN, RSTR_PTR, RSTR_SET_LEN, s, str, and gen-indic-table::total.

Referenced by flo_to_s(), inspect_i(), localjump_error(), mrb_class_find_path(), mrb_class_name_class(), mrb_debug_eval(), mrb_str_cat_cstr(), mrb_str_cat_str(), mrb_str_succ_bang(), mrb_vformat(), range_inspect(), range_to_s(), and str_escape().

◆ mrb_str_cat_cstr()

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.

Parameters
mrbThe current mruby state.
strRuby string.
ptrA C string.
Returns
[mrb_value] A Ruby string.
See also
mrb_str_cat

Definition at line 2714 of file string.c.

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

Referenced by dbgcmd_print(), dump_sym(), method_to_s(), mrb_any_to_s(), mrb_class_find_path(), mrb_obj_iv_inspect(), mrb_proc_inspect(), mrb_str_succ_bang(), mrb_unpack_backtrace(), and sym_var_name().

◆ mrb_str_cat_str()

◆ mrb_str_cmp()

int mrb_str_cmp ( mrb_state mrb,
mrb_value  str1,
mrb_value  str2 
)

Returns 0 if both Ruby strings are equal. Returns a value < 0 if Ruby str1 is less than Ruby str2. Returns a value > 0 if Ruby str2 is greater than Ruby str1.

Definition at line 981 of file string.c.

References len, lesser, memcmp, mrb_str_ptr, RSTR_LEN, RSTR_PTR, s1, s2, str1, and str2.

Referenced by mrb_cmp(), and mrb_str_cmp_m().

◆ mrb_str_concat()

void mrb_str_concat ( mrb_state mrb,
mrb_value  self,
mrb_value  other 
)

Appends self to other. Returns self as a concatenated string.

Example:

int
main(int argc,
     char **argv)
{
  // Variable declarations.
  mrb_value str1;
  mrb_value str2;

  mrb_state *mrb = mrb_open();
  if (!mrb)
  {
     // handle error
  }

  // Creates new Ruby strings.
  str1 = mrb_str_new_lit(mrb, "abc");
  str2 = mrb_str_new_lit(mrb, "def");

  // Concatenates str2 to str1.
  mrb_str_concat(mrb, str1, str2);

  // Prints new Concatenated Ruby string.
  mrb_p(mrb, str1);

  mrb_close(mrb);
  return 0;
}

Result:

=> "abcdef"
Parameters
mrbThe current mruby state.
selfString to concatenate.
otherString to append to self.
Returns
[mrb_value] Returns a new String appending other to self.

Definition at line 863 of file string.c.

References mrb_obj_as_string(), mrb_str_cat_str(), and other.

Referenced by method_to_s(), mrb_proc_inspect(), and mrb_vm_exec().

◆ mrb_str_dump()

mrb_value mrb_str_dump ( mrb_state mrb,
mrb_value  str 
)

Definition at line 2663 of file string.c.

References FALSE, str, and str_escape().

Referenced by dump_sym(), mrb_mruby_string_ext_gem_init(), str_dump(), and sym_name().

◆ mrb_str_dup()

◆ mrb_str_equal()

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.

Parameters
mrbThe current mruby state.
str1Ruby string to compare.
str2Ruby string to compare.
Returns
[mrb_value] boolean value.

Definition at line 1052 of file string.c.

References FALSE, mrb_string_p, str1, str2, and str_eql().

Referenced by mrb_str_equal_m(), and obj_eql().

◆ mrb_str_hash()

uint32_t mrb_str_hash ( mrb_state mrb,
mrb_value  str 
)

Definition at line 1752 of file string.c.

References hash, i, len, mrb_str_ptr, p, RSTR_LEN, RSTR_PTR, s, and str.

Referenced by mrb_str_hash_m(), and obj_hash_code().

◆ mrb_str_index()

mrb_int mrb_str_index ( mrb_state mrb,
mrb_value  str,
const char *  p,
mrb_int  len,
mrb_int  offset 
)

Finds the index of a substring in a string

Definition at line 646 of file string.c.

References len, mrb_memsearch(), offset, pos, RSTRING_LEN, RSTRING_PTR, s, slen, sptr, and str.

Referenced by str_index_str().

◆ mrb_str_inspect()

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 at line 2747 of file string.c.

References str, str_escape(), and TRUE.

Referenced by mrb_init_string(), and sym_inspect().

◆ mrb_str_intern()

mrb_value mrb_str_intern ( mrb_state mrb,
mrb_value  self 
)

Returns a symbol from a passed in Ruby string.

Parameters
mrbThe current mruby state.
selfRuby string.
Returns
[mrb_value] A symbol.

Definition at line 1907 of file string.c.

References mrb_intern_str(), and mrb_symbol_value().

Referenced by mrb_init_string().

◆ mrb_str_modify()

◆ mrb_str_modify_keep_ascii()

void mrb_str_modify_keep_ascii ( mrb_state mrb,
struct RString s 
)

◆ mrb_str_new_capa()

◆ mrb_str_plus()

mrb_value mrb_str_plus ( mrb_state mrb,
mrb_value  a,
mrb_value  b 
)

Adds two strings together.

Example:

int
main(int argc,
     char **argv)
{
  // Variable declarations.
  mrb_value a;
  mrb_value b;
  mrb_value c;

  mrb_state *mrb = mrb_open();
  if (!mrb)
  {
     // handle error
  }

  // Creates two Ruby strings from the passed in C strings.
  a = mrb_str_new_lit(mrb, "abc");
  b = mrb_str_new_lit(mrb, "def");

  // Prints both C strings.
  mrb_p(mrb, a);
  mrb_p(mrb, b);

  // Concatenates both Ruby strings.
  c = mrb_str_plus(mrb, a, b);

  // Prints new Concatenated Ruby string.
  mrb_p(mrb, c);

  mrb_close(mrb);
  return 0;
}

Result:

=> "abc"  # First string
=> "def"  # Second string
=> "abcdef" # First & Second concatenated.
Parameters
mrbThe current mruby state.
aFirst string to concatenate.
bSecond string to concatenate.
Returns
[mrb_value] Returns a new String containing a concatenated to b.

Definition at line 870 of file string.c.

References a, b, memcpy, mrb_obj_value(), mrb_str_ptr, RSTR_LEN, RSTR_PTR, s, s2, str_new(), and t.

Referenced by mrb_str_plus_m().

◆ mrb_str_resize()

mrb_value mrb_str_resize ( mrb_state mrb,
mrb_value  str,
mrb_int  len 
)

Resizes the string's length. Returns the amount of characters in the specified by len.

Example:

int
main(int argc,
     char **argv)
{
    // Variable declaration.
    mrb_value str;

    mrb_state *mrb = mrb_open();
    if (!mrb)
    {
       // handle error
    }
    // Creates a new string.
    str = mrb_str_new_lit(mrb, "Hello, world!");
    // Returns 5 characters of
    mrb_str_resize(mrb, str, 5);
    mrb_p(mrb, str);

    mrb_close(mrb);
    return 0;
 }

Result:

 => "Hello"
Parameters
mrbThe current mruby state.
strThe Ruby string to resize.
lenThe length.
Returns
[mrb_value] An object as a Ruby string.

Definition at line 832 of file string.c.

References E_ARGUMENT_ERROR, len, mrb_raise(), mrb_str_modify(), mrb_str_ptr, resize_capa(), RSTR_LEN, RSTR_PTR, RSTR_SET_LEN, s, slen, and str.

Referenced by mrb_addrinfo_getnameinfo(), mrb_basicsocket_recv(), mrb_basicsocket_recvfrom(), mrb_file_realpath(), mrb_io_readchar(), mrb_io_sysread_common(), mrb_ipsocket_recvfrom(), mrb_load_detect_file_cxt(), mrb_pack_pack(), mrb_socket_accept2(), mrb_socket_gethostname(), mrb_socket_sockaddr_un(), mrb_str_format(), mrb_str_succ_bang(), read_section_debug(), read_section_lv(), sa2addrlist(), str_len_ensure(), unpack_h(), and unpack_m().

◆ mrb_str_strlen()

mrb_int mrb_str_strlen ( mrb_state mrb,
struct RString s 
)

Definition at line 740 of file string.c.

References E_ARGUMENT_ERROR, i, max, mrb_raise(), p, RSTR_LEN, RSTR_PTR, and s.

◆ mrb_str_substr()

mrb_value mrb_str_substr ( mrb_state mrb,
mrb_value  str,
mrb_int  beg,
mrb_int  len 
)

Returns a sub string.

Example:

int
main(int argc,
char const **argv)
{
  // Variable declarations.
  mrb_value str1;
  mrb_value str2;

  mrb_state *mrb = mrb_open();
  if (!mrb)
  {
    // handle error
  }
  // Creates new string.
  str1 = mrb_str_new_lit(mrb, "Hello, world!");
  // Returns a sub-string within the range of 0..2
  str2 = mrb_str_substr(mrb, str1, 0, 2);

  // Prints sub-string.
  mrb_p(mrb, str2);

  mrb_close(mrb);
  return 0;
}

Result:

=> "He"
Parameters
mrbThe current mruby state.
strRuby string.
begThe beginning point of the sub-string.
lenThe end point of the sub-string.
Returns
[mrb_value] An object as a Ruby sub-string.

Definition at line 1746 of file string.c.

References len, str, and str_substr().

Referenced by mrb_str_chr(), mrb_str_del_prefix(), and mrb_str_del_suffix().

◆ mrb_str_to_cstr()

char* mrb_str_to_cstr ( mrb_state mrb,
mrb_value  str 
)

Returns a newly allocated C string from a Ruby string. This is an utility function to pass a Ruby string to C library functions.

  • Returned string does not contain any NUL characters (but terminator).
  • It raises an ArgumentError exception if Ruby string contains NUL characters.
  • Returned string will be freed automatically on next GC.
  • Caller can modify returned string without affecting Ruby string (e.g. it can be used for mkstemp(3)).
Parameters
mrbThe current mruby state.
strRuby string. Must be an instance of String.
Returns
[char *] A newly allocated C string.

Definition at line 853 of file string.c.

References check_null_byte(), RSTR_PTR, RSTRING_LEN, RSTRING_PTR, s, and str_new().

Referenced by mrb_file_basename(), and mrb_file_dirname().

◆ mrb_str_to_dbl()

double mrb_str_to_dbl ( mrb_state mrb,
mrb_value  str,
mrb_bool  badcheck 
)

Definition at line 2562 of file string.c.

References mrb_str_len_to_dbl(), RSTRING_LEN, RSTRING_PTR, and str.

Referenced by mrb_Float(), and mrb_str_to_f().

◆ mrb_str_to_inum()

mrb_value mrb_str_to_inum ( mrb_state mrb,
mrb_value  str,
mrb_int  base,
mrb_bool  badcheck 
)

◆ mrb_string_cstr()

const char* mrb_string_cstr ( mrb_state mrb,
mrb_value  str 
)

Definition at line 2415 of file string.c.

References mrb_string_value_cstr(), and str.

◆ mrb_string_type()

Definition at line 601 of file object.c.

References mrb_ensure_string_type(), and str.

◆ mrb_string_value_cstr()

const char* mrb_string_value_cstr ( mrb_state mrb,
mrb_value str 
)

Definition at line 2391 of file string.c.

References check_null_byte(), len, mrb_str_ptr, p, ps, ptr, RSTR_LEN, RSTR_PTR, and str_modify_keep_ascii().

Referenced by mrb_string_cstr().

◆ mrb_string_value_len()

mrb_int mrb_string_value_len ( mrb_state mrb,
mrb_value  str 
)

Definition at line 1088 of file string.c.

References mrb_to_str(), ptr, and RSTRING_LEN.

◆ mrb_string_value_ptr()

const char* mrb_string_value_ptr ( mrb_state mrb,
mrb_value  str 
)

Definition at line 1080 of file string.c.

References mrb_obj_as_string(), RSTRING_PTR, and str.

Variable Documentation

◆ mrb_digitmap

const char mrb_digitmap[]
extern

String class

Definition at line 33 of file string.c.

Referenced by mrb_fix2binstr(), mrb_fixnum_to_str(), mrb_ptr_to_str(), readint_mrb_int(), and str_escape().