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.c File Reference
#include <float.h>
#include <math.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/class.h>
#include <mruby/range.h>
#include <mruby/numeric.h>
#include <mruby/presym.h>
#include <ctype.h>
#include <errno.h>
Include dependency graph for string.c:

Go to the source code of this file.

Classes

struct  mrb_shared_string
 

Macros

#define mrb_obj_alloc_string(mrb)   ((struct RString*)mrb_obj_alloc((mrb), MRB_TT_STRING, (mrb)->string_class))
 
#define RSTRING_CHAR_LEN(s)   RSTRING_LEN(s)
 
#define chars2bytes(p, off, ci)   (ci)
 
#define bytes2chars(p, end, bi)   (bi)
 
#define char_adjust(beg, end, ptr)   (ptr)
 
#define char_backtrack(ptr, end)   ((end) - 1)
 
#define BYTES_ALIGN_CHECK(pos)
 
#define str_index_str_by_char(mrb, str, sub, pos)   str_index_str(mrb, str, sub, pos)
 
#define MRB_QS_SHORT_STRING_LENGTH   2048
 
#define str_subseq(mrb, str, beg, len)   mrb_str_byte_subseq(mrb, str, beg, len)
 
#define lesser(a, b)   (((a)>(b))?(b):(a))
 
#define IS_EVSTR(p, e)   ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))
 
#define conv_digit(c)
 

Typedefs

typedef struct mrb_shared_string mrb_shared_string
 

Enumerations

enum  str_convert_range { STR_BYTE_RANGE_CORRECTED = 1 , STR_CHAR_RANGE = 2 , STR_CHAR_RANGE_CORRECTED = 3 , STR_OUT_OF_RANGE = -1 }
 

Functions

static struct RStringstr_init_normal_capa (mrb_state *mrb, struct RString *s, const char *p, size_t len, size_t capa)
 
static struct RStringstr_init_normal (mrb_state *mrb, struct RString *s, const char *p, size_t len)
 
static struct RStringstr_init_embed (struct RString *s, const char *p, size_t len)
 
static struct RStringstr_init_nofree (struct RString *s, const char *p, size_t len)
 
static struct RStringstr_init_shared (mrb_state *mrb, const struct RString *orig, struct RString *s, mrb_shared_string *shared)
 
static struct RStringstr_init_fshared (const struct RString *orig, struct RString *s, struct RString *fshared)
 
static struct RStringstr_init_modifiable (mrb_state *mrb, struct RString *s, const char *p, size_t len)
 
static struct RStringstr_new_static (mrb_state *mrb, const char *p, size_t len)
 
static struct RStringstr_new (mrb_state *mrb, const char *p, size_t len)
 
static void str_with_class (struct RString *s, mrb_value obj)
 
static mrb_value mrb_str_new_empty (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_str_new_capa (mrb_state *mrb, size_t capa)
 
static void resize_capa (mrb_state *mrb, struct RString *s, size_t capacity)
 
mrb_value mrb_str_new (mrb_state *mrb, const char *p, size_t len)
 
mrb_value mrb_str_new_cstr (mrb_state *mrb, const char *p)
 
mrb_value mrb_str_new_static (mrb_state *mrb, const char *p, size_t len)
 
static void str_decref (mrb_state *mrb, mrb_shared_string *shared)
 
static void str_modify_keep_ascii (mrb_state *mrb, struct RString *s)
 
static void check_null_byte (mrb_state *mrb, mrb_value str)
 
void mrb_gc_free_str (mrb_state *mrb, struct RString *str)
 
static mrb_int mrb_memsearch_qs (const unsigned char *xs, mrb_int m, const unsigned char *ys, mrb_int n)
 
static mrb_int mrb_memsearch (const void *x0, mrb_int m, const void *y0, mrb_int n)
 
static void str_share (mrb_state *mrb, struct RString *orig, struct RString *s)
 
mrb_value mrb_str_byte_subseq (mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
 
static void str_range_to_bytes (mrb_value str, mrb_int *pos, mrb_int *len)
 
mrb_bool mrb_str_beg_len (mrb_int str_len, mrb_int *begp, mrb_int *lenp)
 
static mrb_value str_substr (mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
 
mrb_int mrb_str_index (mrb_state *mrb, mrb_value str, const char *sptr, mrb_int slen, mrb_int offset)
 
static mrb_int str_index_str (mrb_state *mrb, mrb_value str, mrb_value str2, mrb_int offset)
 
static mrb_value str_replace (mrb_state *mrb, struct RString *s1, struct RString *s2)
 
static mrb_int str_rindex (mrb_state *mrb, mrb_value str, mrb_value sub, mrb_int pos)
 
mrb_int mrb_str_strlen (mrb_state *mrb, struct RString *s)
 
void mrb_str_modify_keep_ascii (mrb_state *mrb, struct RString *s)
 
void mrb_str_modify (mrb_state *mrb, struct RString *s)
 
mrb_value mrb_str_resize (mrb_state *mrb, mrb_value str, mrb_int len)
 
char * mrb_str_to_cstr (mrb_state *mrb, mrb_value str0)
 
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)
 
static mrb_value mrb_str_plus_m (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_size (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_bytesize (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_times (mrb_state *mrb, mrb_value self)
 
int mrb_str_cmp (mrb_state *mrb, mrb_value str1, mrb_value str2)
 
static mrb_value mrb_str_cmp_m (mrb_state *mrb, mrb_value str1)
 
static mrb_bool str_eql (mrb_state *mrb, const mrb_value str1, const mrb_value str2)
 
mrb_bool mrb_str_equal (mrb_state *mrb, mrb_value str1, mrb_value str2)
 
static mrb_value mrb_str_equal_m (mrb_state *mrb, mrb_value str1)
 
const char * mrb_string_value_ptr (mrb_state *mrb, mrb_value str)
 
mrb_int mrb_string_value_len (mrb_state *mrb, mrb_value ptr)
 
mrb_value mrb_str_dup (mrb_state *mrb, mrb_value str)
 
static enum str_convert_range str_convert_range (mrb_state *mrb, mrb_value str, mrb_value indx, mrb_value alen, mrb_int *beg, mrb_int *len)
 
static mrb_value mrb_str_aref (mrb_state *mrb, mrb_value str, mrb_value indx, mrb_value alen)
 
static mrb_value mrb_str_aref_m (mrb_state *mrb, mrb_value str)
 
static void str_out_of_index (mrb_state *mrb, mrb_value index)
 
static mrb_value str_replace_partial (mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb_value rep)
 
static mrb_value str_escape (mrb_state *mrb, mrb_value str, mrb_bool inspect)
 
static void mrb_str_aset (mrb_state *mrb, mrb_value str, mrb_value indx, mrb_value alen, mrb_value replace)
 
static mrb_value mrb_str_aset_m (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_capitalize_bang (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_capitalize (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_chomp_bang (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_chomp (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_chop_bang (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_chop (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_downcase_bang (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_downcase (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_empty_p (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_eql (mrb_state *mrb, mrb_value self)
 
mrb_value mrb_str_substr (mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
 
uint32_t mrb_str_hash (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_hash_m (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_include (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_index_m (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_replace (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_init (mrb_state *mrb, mrb_value self)
 
mrb_value mrb_str_intern (mrb_state *mrb, mrb_value self)
 
mrb_value mrb_obj_as_string (mrb_state *mrb, mrb_value obj)
 
mrb_value mrb_ptr_to_str (mrb_state *mrb, void *p)
 
static void str_reverse (char *p, char *e)
 
static mrb_value mrb_str_reverse_bang (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_reverse (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_rindex (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_split_m (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_str_len_to_inum (mrb_state *mrb, const char *str, size_t len, mrb_int base, int badcheck)
 
mrb_value mrb_cstr_to_inum (mrb_state *mrb, const char *str, mrb_int base, mrb_bool badcheck)
 
const char * mrb_string_value_cstr (mrb_state *mrb, mrb_value *ptr)
 
const char * mrb_string_cstr (mrb_state *mrb, mrb_value str)
 
mrb_value mrb_str_to_inum (mrb_state *mrb, mrb_value str, mrb_int base, mrb_bool badcheck)
 
static mrb_value mrb_str_to_i (mrb_state *mrb, mrb_value self)
 
double mrb_str_len_to_dbl (mrb_state *mrb, const char *s, size_t len, mrb_bool badcheck)
 
double mrb_cstr_to_dbl (mrb_state *mrb, const char *s, mrb_bool badcheck)
 
double mrb_str_to_dbl (mrb_state *mrb, mrb_value str, mrb_bool badcheck)
 
static mrb_value mrb_str_to_f (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_to_s (mrb_state *mrb, mrb_value self)
 
static mrb_value mrb_str_upcase_bang (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_upcase (mrb_state *mrb, mrb_value self)
 
mrb_value mrb_str_dump (mrb_state *mrb, mrb_value str)
 
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 str1, mrb_value str2)
 
mrb_value mrb_str_inspect (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_bytes (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_getbyte (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_setbyte (mrb_state *mrb, mrb_value str)
 
static mrb_value mrb_str_byteslice (mrb_state *mrb, mrb_value str)
 
void mrb_init_string (mrb_state *mrb)
 
double mrb_float_read (const char *string, char **endPtr)
 

Variables

const char mrb_digitmap [] = "0123456789abcdefghijklmnopqrstuvwxyz"
 
static const int maxExponent = 511
 
static const double powersOf10 []
 

Macro Definition Documentation

◆ bytes2chars

#define bytes2chars (   p,
  end,
  bi 
)    (bi)

Definition at line 490 of file string.c.

◆ BYTES_ALIGN_CHECK

#define BYTES_ALIGN_CHECK (   pos)

Definition at line 493 of file string.c.

◆ char_adjust

#define char_adjust (   beg,
  end,
  ptr 
)    (ptr)

Definition at line 491 of file string.c.

◆ char_backtrack

#define char_backtrack (   ptr,
  end 
)    ((end) - 1)

Definition at line 492 of file string.c.

◆ chars2bytes

#define chars2bytes (   p,
  off,
  ci 
)    (ci)

Definition at line 489 of file string.c.

◆ conv_digit

#define conv_digit (   c)
Value:
(ISDIGIT(c) ? ((c) - '0') : \
ISLOWER(c) ? ((c) - 'a' + 10) : \
ISUPPER(c) ? ((c) - 'A' + 10) : \
-1)
#define c(n)
Definition: gpos-common.c:150
#define ISDIGIT(c)
Definition: c-ctype.h:35

◆ IS_EVSTR

#define IS_EVSTR (   p,
  e 
)    ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))

Definition at line 1291 of file string.c.

◆ lesser

#define lesser (   a,
  b 
)    (((a)>(b))?(b):(a))

Definition at line 970 of file string.c.

◆ mrb_obj_alloc_string

#define mrb_obj_alloc_string (   mrb)    ((struct RString*)mrb_obj_alloc((mrb), MRB_TT_STRING, (mrb)->string_class))

Definition at line 35 of file string.c.

◆ MRB_QS_SHORT_STRING_LENGTH

#define MRB_QS_SHORT_STRING_LENGTH   2048

Definition at line 498 of file string.c.

◆ RSTRING_CHAR_LEN

#define RSTRING_CHAR_LEN (   s)    RSTRING_LEN(s)

Definition at line 488 of file string.c.

◆ str_index_str_by_char

#define str_index_str_by_char (   mrb,
  str,
  sub,
  pos 
)    str_index_str(mrb, str, sub, pos)

Definition at line 494 of file string.c.

◆ str_subseq

#define str_subseq (   mrb,
  str,
  beg,
  len 
)    mrb_str_byte_subseq(mrb, str, beg, len)

Definition at line 619 of file string.c.

Typedef Documentation

◆ mrb_shared_string

Enumeration Type Documentation

◆ str_convert_range

Enumerator
STR_BYTE_RANGE_CORRECTED 
STR_CHAR_RANGE 
STR_CHAR_RANGE_CORRECTED 
STR_OUT_OF_RANGE 

Definition at line 1104 of file string.c.

Function Documentation

◆ check_null_byte()

static void check_null_byte ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 260 of file string.c.

References E_ARGUMENT_ERROR, memchr(), mrb_raise(), mrb_to_str(), RSTRING_LEN, RSTRING_PTR, and str.

Referenced by mrb_str_to_cstr(), and mrb_string_value_cstr().

◆ 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 *  str,
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_float_read()

double mrb_float_read ( const char *  string,
char **  endPtr 
)

Definition at line 2982 of file string.c.

References c, d, errno, exp(), FALSE, ISDIGIT, ISSPACE, maxExponent, NULL, p, powersOf10, sign, string, and TRUE.

Referenced by codegen(), mrb_str_len_to_dbl(), and parser_yylex().

◆ 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_init_string()

◆ mrb_memsearch()

static mrb_int mrb_memsearch ( const void x0,
mrb_int  m,
const void y0,
mrb_int  n 
)
static

Definition at line 539 of file string.c.

References m, memchr(), memcmp, mrb_memsearch_qs(), n, cordic::x, x0, y, and y0.

Referenced by mrb_str_index(), and mrb_str_split_m().

◆ mrb_memsearch_qs()

static mrb_int mrb_memsearch_qs ( const unsigned char *  xs,
mrb_int  m,
const unsigned char *  ys,
mrb_int  n 
)
inlinestatic

Definition at line 502 of file string.c.

References i, m, memchr(), memcmp, MRB_QS_SHORT_STRING_LENGTH, n, NULL, cordic::x, and y.

Referenced by mrb_memsearch().

◆ 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_aref()

◆ mrb_str_aref_m()

static mrb_value mrb_str_aref_m ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 1230 of file string.c.

References a1, a2, mrb_get_args(), mrb_str_aref(), mrb_undef_value(), and str.

Referenced by mrb_init_string().

◆ mrb_str_aset()

◆ mrb_str_aset_m()

static mrb_value mrb_str_aset_m ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 1411 of file string.c.

References mrb_get_args(), mrb_str_aset(), mrb_undef_value(), replace(), and str.

Referenced by mrb_init_string().

◆ 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_bytes()

static mrb_value mrb_str_bytes ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 2762 of file string.c.

References a, mrb_ary_new_capa(), mrb_ary_push(), mrb_fixnum_value(), mrb_str_ptr, p, RSTR_LEN, RSTR_PTR, s, and str.

Referenced by mrb_init_string().

◆ mrb_str_bytesize()

static mrb_value mrb_str_bytesize ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 919 of file string.c.

References len, mrb_fixnum_value(), and RSTRING_LEN.

Referenced by mrb_init_string().

◆ mrb_str_byteslice()

◆ mrb_str_capitalize()

static mrb_value mrb_str_capitalize ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1477 of file string.c.

References mrb_str_capitalize_bang(), mrb_str_dup(), and str.

Referenced by mrb_init_string().

◆ mrb_str_capitalize_bang()

static mrb_value mrb_str_capitalize_bang ( mrb_state mrb,
mrb_value  str 
)
static

◆ 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_chomp()

static mrb_value mrb_str_chomp ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1581 of file string.c.

References mrb_str_chomp_bang(), mrb_str_dup(), and str.

Referenced by mrb_init_string().

◆ mrb_str_chomp_bang()

static mrb_value mrb_str_chomp_bang ( mrb_state mrb,
mrb_value  str 
)
static

◆ mrb_str_chop()

static mrb_value mrb_str_chop ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1650 of file string.c.

References mrb_str_chop_bang(), mrb_str_dup(), and str.

Referenced by mrb_init_string().

◆ mrb_str_chop_bang()

static mrb_value mrb_str_chop_bang ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 1600 of file string.c.

References e, len, mrb_nil_value(), mrb_str_modify_keep_ascii(), mrb_str_ptr, p, RSTR_LEN, RSTR_PTR, RSTR_SET_LEN, s, str, and t.

Referenced by mrb_init_string(), and mrb_str_chop().

◆ 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_cmp_m()

static mrb_value mrb_str_cmp_m ( mrb_state mrb,
mrb_value  str1 
)
static

◆ 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_downcase()

static mrb_value mrb_str_downcase ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1700 of file string.c.

References mrb_str_downcase_bang(), mrb_str_dup(), and str.

Referenced by mrb_init_string().

◆ mrb_str_downcase_bang()

static mrb_value mrb_str_downcase_bang ( mrb_state mrb,
mrb_value  str 
)
static

◆ 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_empty_p()

static mrb_value mrb_str_empty_p ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1720 of file string.c.

References mrb_bool_value(), mrb_str_ptr, RSTR_LEN, and s.

Referenced by mrb_init_string().

◆ mrb_str_eql()

static mrb_value mrb_str_eql ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1735 of file string.c.

References mrb_bool_value(), mrb_get_arg1(), mrb_string_p, str2, and str_eql().

Referenced by mrb_init_string().

◆ 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_equal_m()

static mrb_value mrb_str_equal_m ( mrb_state mrb,
mrb_value  str1 
)
static

Definition at line 1070 of file string.c.

References mrb_bool_value(), mrb_get_arg1(), mrb_str_equal(), str1, and str2.

Referenced by mrb_init_string().

◆ mrb_str_getbyte()

static mrb_value mrb_str_getbyte ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 2782 of file string.c.

References mrb_fixnum_value(), mrb_get_args(), mrb_nil_value(), pos, RSTRING_LEN, RSTRING_PTR, and str.

Referenced by mrb_init_string().

◆ 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_hash_m()

static mrb_value mrb_str_hash_m ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1779 of file string.c.

References key, mrb_fixnum_value(), and mrb_str_hash().

Referenced by mrb_init_string().

◆ mrb_str_include()

static mrb_value mrb_str_include ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1799 of file string.c.

References FALSE, mrb_bool_value(), mrb_get_args(), str2, str_index_str(), and TRUE.

Referenced by mrb_init_string().

◆ 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_index_m()

static mrb_value mrb_str_index_m ( mrb_state mrb,
mrb_value  str 
)
static

◆ mrb_str_init()

static mrb_value mrb_str_init ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1873 of file string.c.

References mrb_get_args(), mrb_obj_value(), mrb_str_ptr, s, str2, str_new(), and str_replace().

Referenced by mrb_init_string().

◆ 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_len_to_dbl()

double mrb_str_len_to_dbl ( mrb_state mrb,
const char *  s,
size_t  len,
mrb_bool  badcheck 
)

◆ mrb_str_len_to_inum()

mrb_value mrb_str_len_to_inum ( mrb_state mrb,
const char *  str,
size_t  len,
mrb_int  base,
int  badcheck 
)

◆ mrb_str_modify()

◆ mrb_str_modify_keep_ascii()

void mrb_str_modify_keep_ascii ( mrb_state mrb,
struct RString s 
)

◆ mrb_str_new()

◆ mrb_str_new_capa()

◆ mrb_str_new_cstr()

◆ mrb_str_new_empty()

static mrb_value mrb_str_new_empty ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 151 of file string.c.

References mrb_obj_value(), s, str, str_new(), and str_with_class().

Referenced by mrb_str_split_m().

◆ mrb_str_new_static()

mrb_value mrb_str_new_static ( mrb_state mrb,
const char *  p,
size_t  len 
)

Definition at line 221 of file string.c.

References len, mrb_obj_value(), p, s, and str_new_static().

Referenced by mrb_sym_str(), mrb_time_zone(), mrb_vm_exec(), and sym_name().

◆ 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_plus_m()

static mrb_value mrb_str_plus_m ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 895 of file string.c.

References mrb_get_args(), mrb_str_plus(), and str.

Referenced by mrb_init_string().

◆ mrb_str_replace()

static mrb_value mrb_str_replace ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 1857 of file string.c.

References mrb_get_args(), mrb_str_ptr, str, str2, and str_replace().

Referenced by mrb_init_string().

◆ 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_reverse()

static mrb_value mrb_str_reverse ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 2028 of file string.c.

References mrb_str_dup(), mrb_str_reverse_bang(), str, and str2.

Referenced by mrb_init_string().

◆ mrb_str_reverse_bang()

static mrb_value mrb_str_reverse_bang ( mrb_state mrb,
mrb_value  str 
)
static

Definition at line 1981 of file string.c.

References bytes, e, len, mrb_str_modify(), mrb_str_ptr, p, RSTR_LEN, RSTR_PTR, RSTRING_CHAR_LEN, s, str, and str_reverse().

Referenced by mrb_init_string(), and mrb_str_reverse().

◆ mrb_str_rindex()

◆ mrb_str_setbyte()

static mrb_value mrb_str_setbyte ( mrb_state mrb,
mrb_value  str 
)
static

◆ mrb_str_size()

static mrb_value mrb_str_size ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 912 of file string.c.

References len, mrb_fixnum_value(), and RSTRING_CHAR_LEN.

Referenced by mrb_init_string().

◆ mrb_str_split_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_times()

◆ 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_f()

static mrb_value mrb_str_to_f ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 2582 of file string.c.

References FALSE, mrb_float_value(), and mrb_str_to_dbl().

Referenced by mrb_init_string().

◆ mrb_str_to_i()

static mrb_value mrb_str_to_i ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 2454 of file string.c.

References base, E_ARGUMENT_ERROR, FALSE, mrb_get_args(), mrb_raisef(), and mrb_str_to_inum().

Referenced by mrb_init_string().

◆ mrb_str_to_inum()

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

◆ mrb_str_to_s()

static mrb_value mrb_str_to_s ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 2596 of file string.c.

References mrb_obj_class(), mrb_str_dup(), and mrb_state::string_class.

Referenced by mrb_init_string().

◆ mrb_str_upcase()

static mrb_value mrb_str_upcase ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 2646 of file string.c.

References mrb_str_dup(), mrb_str_upcase_bang(), and str.

Referenced by mrb_init_string().

◆ mrb_str_upcase_bang()

static mrb_value mrb_str_upcase_bang ( mrb_state mrb,
mrb_value  str 
)
static

◆ 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_value_cstr()

const char* mrb_string_value_cstr ( mrb_state mrb,
mrb_value ptr 
)

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  ptr 
)

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.

◆ resize_capa()

static void resize_capa ( mrb_state mrb,
struct RString s,
size_t  capacity 
)
static

◆ str_convert_range()

static enum str_convert_range str_convert_range ( mrb_state mrb,
mrb_value  str,
mrb_value  indx,
mrb_value  alen,
mrb_int beg,
mrb_int len 
)
static

Definition at line 1095 of file string.c.

◆ str_decref()

static void str_decref ( mrb_state mrb,
mrb_shared_string shared 
)
static

◆ str_eql()

static mrb_bool str_eql ( mrb_state mrb,
const mrb_value  str1,
const mrb_value  str2 
)
static

Definition at line 1041 of file string.c.

References FALSE, len, memcmp, RSTRING_LEN, RSTRING_PTR, str1, str2, and TRUE.

Referenced by mrb_str_eql(), and mrb_str_equal().

◆ str_escape()

◆ str_index_str()

static mrb_int str_index_str ( mrb_state mrb,
mrb_value  str,
mrb_value  str2,
mrb_int  offset 
)
static

Definition at line 671 of file string.c.

References len, mrb_str_index(), offset, ptr, RSTRING_LEN, RSTRING_PTR, str, and str2.

Referenced by mrb_str_include().

◆ str_init_embed()

static struct RString* str_init_embed ( struct RString s,
const char *  p,
size_t  len 
)
static

◆ str_init_fshared()

static struct RString* str_init_fshared ( const struct RString orig,
struct RString s,
struct RString fshared 
)
static

Definition at line 97 of file string.c.

References RString::as, RString::fshared, RString::heap, RString::len, RString::ptr, RSTR_SET_TYPE_FLAG, and s.

Referenced by str_share().

◆ str_init_modifiable()

static struct RString* str_init_modifiable ( mrb_state mrb,
struct RString s,
const char *  p,
size_t  len 
)
static

Definition at line 107 of file string.c.

References len, p, RSTR_EMBEDDABLE_P, s, str_init_embed(), and str_init_normal().

Referenced by str_modify_keep_ascii().

◆ str_init_nofree()

static struct RString* str_init_nofree ( struct RString s,
const char *  p,
size_t  len 
)
static

Definition at line 68 of file string.c.

References len, p, RSTR_SET_TYPE_FLAG, and s.

Referenced by str_new(), str_new_static(), and str_share().

◆ str_init_normal()

static struct RString* str_init_normal ( mrb_state mrb,
struct RString s,
const char *  p,
size_t  len 
)
static

Definition at line 52 of file string.c.

References len, p, s, and str_init_normal_capa().

Referenced by str_init_modifiable(), and str_new().

◆ str_init_normal_capa()

static struct RString* str_init_normal_capa ( mrb_state mrb,
struct RString s,
const char *  p,
size_t  len,
size_t  capa 
)
static

Definition at line 38 of file string.c.

References RString::capa, link_confs::dst, len, memcpy, mrb_malloc(), p, RSTR_UNSET_TYPE_FLAG, and s.

Referenced by mrb_str_new_capa(), resize_capa(), and str_init_normal().

◆ str_init_shared()

static struct RString* str_init_shared ( mrb_state mrb,
const struct RString orig,
struct RString s,
mrb_shared_string shared 
)
static

◆ str_modify_keep_ascii()

◆ str_new()

◆ str_new_static()

static struct RString* str_new_static ( mrb_state mrb,
const char *  p,
size_t  len 
)
static

◆ str_out_of_index()

static void str_out_of_index ( mrb_state mrb,
mrb_value  index 
)
static

Definition at line 1242 of file string.c.

References E_INDEX_ERROR, and mrb_raisef().

Referenced by mrb_str_aset(), and str_replace_partial().

◆ str_range_to_bytes()

static void str_range_to_bytes ( mrb_value  str,
mrb_int pos,
mrb_int len 
)
static

Definition at line 606 of file string.c.

References chars2bytes, len, pos, and str.

Referenced by mrb_str_aset().

◆ str_replace()

◆ str_replace_partial()

◆ str_reverse()

static void str_reverse ( char *  p,
char *  e 
)
inlinestatic

Definition at line 1962 of file string.c.

References c, e, and p.

Referenced by mrb_str_reverse_bang().

◆ str_rindex()

static mrb_int str_rindex ( mrb_state mrb,
mrb_value  str,
mrb_value  sub,
mrb_int  pos 
)
static

Definition at line 710 of file string.c.

References char_adjust, char_backtrack, len, memcmp, mrb_str_ptr, pos, ps, RSTR_LEN, RSTR_PTR, RSTRING_LEN, RSTRING_PTR, s, str, sub, and t.

Referenced by mrb_str_rindex().

◆ str_share()

◆ str_substr()

static mrb_value str_substr ( mrb_state mrb,
mrb_value  str,
mrb_int  beg,
mrb_int  len 
)
static

Definition at line 639 of file string.c.

References len, mrb_nil_value(), mrb_str_beg_len(), RSTRING_CHAR_LEN, str, and str_subseq.

Referenced by mrb_str_aref(), and mrb_str_substr().

◆ str_with_class()

static void str_with_class ( struct RString s,
mrb_value  obj 
)
inlinestatic

Definition at line 145 of file string.c.

References mrb_str_ptr, and s.

Referenced by mrb_str_dup(), mrb_str_new_empty(), and mrb_str_times().

Variable Documentation

◆ maxExponent

const int maxExponent = 511
static

Definition at line 2964 of file string.c.

Referenced by mrb_float_read().

◆ mrb_digitmap

const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz"

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().

◆ powersOf10

const double powersOf10[]
static
Initial value:
= {
10.,
100.,
1.0e4,
1.0e8,
1.0e16,
1.0e32,
1.0e64,
1.0e128,
1.0e256
}

Definition at line 2969 of file string.c.

Referenced by mrb_float_read().