Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

string.c File Reference

#include "ruby.h"
#include "re.h"
#include <math.h>
#include <ctype.h>
#include <unistd.h>

Go to the source code of this file.

Data Structures

struct  tr

Defines

#define BEG(no)   regs->beg[no]
#define END(no)   regs->end[no]
#define STR_TMPLOCK   FL_USER1
#define STR_ASSOC   FL_USER3
#define STR_NOCAPA   (ELTS_SHARED|STR_ASSOC)
#define RESIZE_CAPA(str, capacity)
#define STR_BUF_MIN_SIZE   128
#define lesser(a, b)   (((a)>(b))?(b):(a))
#define IS_EVSTR(p, e)   ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))

Typedefs

typedef unsigned char * USTR

Functions

void str_mod_check (VALUE s, char *p, long len)
void str_frozen_check (VALUE s)
VALUE str_alloc (VALUE)
VALUE str_new (VALUE klass, const char *ptr, long len)
VALUE rb_str_new (char *ptr, long len) const
VALUE rb_str_new2 (char *ptr) const
VALUE rb_tainted_str_new (char *ptr, long len) const
VALUE rb_tainted_str_new2 (char *ptr) const
VALUE str_new3 (VALUE klass, VALUE str)
VALUE rb_str_new3 (VALUE str)
VALUE str_new4 (VALUE klass, VALUE str)
VALUE rb_str_new4 (VALUE orig)
VALUE rb_str_new5 (VALUE obj, const char *ptr, long len)
VALUE rb_str_buf_new (long capa)
VALUE rb_str_buf_new2 (char *ptr) const
VALUE rb_str_to_str (VALUE str)
void rb_str_shared_replace (VALUE str, VALUE str2)
VALUE rb_obj_as_string (VALUE obj)
VALUE rb_str_replace (VALUE, VALUE)
VALUE rb_str_dup (VALUE str)
VALUE rb_str_init (int argc, VALUE *argv, VALUE str)
VALUE rb_str_length (VALUE str)
VALUE rb_str_empty (VALUE str)
VALUE rb_str_plus (VALUE str1, VALUE str2)
VALUE rb_str_times (VALUE str, VALUE times)
VALUE rb_str_format (VALUE str, VALUE arg)
int str_independent (VALUE str)
void str_make_independent (VALUE str)
void rb_str_modify (VALUE str)
void rb_str_associate (VALUE str, VALUE add)
VALUE rb_str_associated (VALUE str)
VALUE rb_string_value (VALUE *ptr) volatile
char * rb_string_value_ptr (VALUE *ptr) volatile
char * rb_string_value_cstr (VALUE *ptr) volatile
VALUE rb_check_string_type (VALUE str)
VALUE rb_str_substr (VALUE str, long beg, long len)
VALUE rb_str_freeze (VALUE str)
VALUE rb_str_dup_frozen (VALUE str)
VALUE rb_str_locktmp (VALUE str)
VALUE rb_str_unlocktmp (VALUE str)
VALUE rb_str_resize (VALUE str, long len)
VALUE rb_str_buf_cat (VALUE str, const char *ptr, long len)
VALUE rb_str_buf_cat2 (VALUE str, const char *ptr)
VALUE rb_str_cat (VALUE str, const char *ptr, long len)
VALUE rb_str_cat2 (VALUE str, const char *ptr)
VALUE rb_str_buf_append (VALUE str, VALUE str2)
VALUE rb_str_append (VALUE str, VALUE str2)
VALUE rb_str_concat (VALUE str1, VALUE str2)
int rb_str_hash (VALUE str)
VALUE rb_str_hash_m (VALUE str)
int rb_str_cmp (VALUE str1, VALUE str2)
VALUE rb_str_equal (VALUE str1, VALUE str2)
VALUE rb_str_eql (VALUE str1, VALUE str2)
VALUE rb_str_cmp_m (VALUE str1, VALUE str2)
VALUE rb_str_casecmp (VALUE str1, VALUE str2)
long rb_str_index (VALUE str, VALUE sub, long offset)
VALUE rb_str_index_m (int argc, VALUE *argv, VALUE str)
long rb_str_rindex (VALUE str, VALUE sub, long pos)
VALUE rb_str_rindex_m (int argc, VALUE *argv, VALUE str)
VALUE rb_str_match (VALUE x, VALUE y)
VALUE get_pat (VALUE, int)
VALUE rb_str_match_m (VALUE str, VALUE re)
char succ_char (char *s)
VALUE rb_str_succ (VALUE orig)
VALUE rb_str_succ_bang (VALUE str)
VALUE rb_str_upto (VALUE beg, VALUE end, int excl)
VALUE rb_str_upto_m (VALUE beg, VALUE end)
VALUE rb_str_subpat (VALUE str, VALUE re, int nth)
VALUE rb_str_aref (VALUE str, VALUE indx)
VALUE rb_str_aref_m (int argc, VALUE *argv, VALUE str)
void rb_str_splice (VALUE str, long beg, long len, VALUE val)
void rb_str_update (VALUE str, long beg, long len, VALUE val)
void rb_str_subpat_set (VALUE str, VALUE re, int nth, VALUE val)
VALUE rb_str_aset (VALUE str, VALUE indx, VALUE val)
VALUE rb_str_aset_m (int argc, VALUE *argv, VALUE str)
VALUE rb_str_insert (VALUE str, VALUE idx, VALUE str2)
VALUE rb_str_slice_bang (int argc, VALUE *argv, VALUE str)
VALUE rb_str_sub_bang (int argc, VALUE *argv, VALUE str)
VALUE rb_str_sub (int argc, VALUE *argv, VALUE str)
VALUE str_gsub (int argc, VALUE *argv, VALUE str, int bang)
VALUE rb_str_gsub_bang (int argc, VALUE *argv, VALUE str)
VALUE rb_str_gsub (int argc, VALUE *argv, VALUE str)
VALUE uscore_get ()
VALUE rb_f_sub_bang (int argc, VALUE *argv)
VALUE rb_f_sub (int argc, VALUE *argv)
VALUE rb_f_gsub_bang (int argc, VALUE *argv)
VALUE rb_f_gsub (int argc, VALUE *argv)
VALUE rb_str_reverse_bang (VALUE str)
VALUE rb_str_reverse (VALUE str)
VALUE rb_str_include (VALUE str, VALUE arg)
VALUE rb_str_to_i (int argc, VALUE *argv, VALUE str)
VALUE rb_str_to_f (VALUE str)
VALUE rb_str_to_s (VALUE str)
VALUE rb_str_inspect (VALUE str)
VALUE rb_str_dump (VALUE str)
VALUE rb_str_upcase_bang (VALUE str)
VALUE rb_str_upcase (VALUE str)
VALUE rb_str_downcase_bang (VALUE str)
VALUE rb_str_downcase (VALUE str)
VALUE rb_str_capitalize_bang (VALUE str)
VALUE rb_str_capitalize (VALUE str)
VALUE rb_str_swapcase_bang (VALUE str)
VALUE rb_str_swapcase (VALUE str)
int trnext (struct tr *t)
VALUE rb_str_delete_bang (int, VALUE *, VALUE)
VALUE tr_trans (VALUE str, VALUE src, VALUE repl, int sflag)
VALUE rb_str_tr_bang (VALUE str, VALUE src, VALUE repl)
VALUE rb_str_tr (VALUE str, VALUE src, VALUE repl)
void tr_setup_table (VALUE str, table, int init)
VALUE rb_str_delete (int argc, VALUE *argv, VALUE str)
VALUE rb_str_squeeze_bang (int argc, VALUE *argv, VALUE str)
VALUE rb_str_squeeze (int argc, VALUE *argv, VALUE str)
VALUE rb_str_tr_s_bang (VALUE str, VALUE src, VALUE repl)
VALUE rb_str_tr_s (VALUE str, VALUE src, VALUE repl)
VALUE rb_str_count (int argc, VALUE *argv, VALUE str)
VALUE rb_str_split_m (int argc, VALUE *argv, VALUE str)
VALUE rb_str_split (VALUE str, const char *sep0)
VALUE rb_f_split (int argc, VALUE *argv)
VALUE rb_str_each_line (int argc, VALUE *argv, VALUE str)
VALUE rb_str_each_byte (VALUE str)
VALUE rb_str_chop_bang (VALUE str)
VALUE rb_str_chop (VALUE str)
VALUE rb_f_chop_bang (VALUE str)
VALUE rb_f_chop ()
VALUE rb_str_chomp_bang (int argc, VALUE *argv, VALUE str)
VALUE rb_str_chomp (int argc, VALUE *argv, VALUE str)
VALUE rb_f_chomp_bang (int argc, VALUE *argv)
VALUE rb_f_chomp (int argc, VALUE *argv)
VALUE rb_str_lstrip_bang (VALUE str)
VALUE rb_str_lstrip (VALUE str)
VALUE rb_str_rstrip_bang (VALUE str)
VALUE rb_str_rstrip (VALUE str)
VALUE rb_str_strip_bang (VALUE str)
VALUE rb_str_strip (VALUE str)
VALUE scan_once (VALUE str, VALUE pat, long *start)
VALUE rb_str_scan (VALUE str, VALUE pat)
VALUE rb_f_scan (VALUE self, VALUE pat)
VALUE rb_str_hex (VALUE str)
VALUE rb_str_oct (VALUE str)
VALUE rb_str_crypt (VALUE str, VALUE salt)
VALUE rb_str_intern (VALUE s)
VALUE rb_str_sum (int argc, VALUE *argv, VALUE str)
VALUE rb_str_justify (int argc, VALUE *argv, VALUE str, char jflag)
VALUE rb_str_ljust (int argc, VALUE *argv, VALUE str)
VALUE rb_str_rjust (int argc, VALUE *argv, VALUE str)
VALUE rb_str_center (int argc, VALUE *argv, VALUE str)
void rb_str_setter (VALUE val, ID id, VALUE *var)
void Init_String ()

Variables

VALUE rb_cString
VALUE rb_fs
ID id_to_s
char * null_str = ""


Define Documentation

#define BEG no   )     regs->beg[no]
 

Definition at line 18 of file string.c.

#define END no   )     regs->end[no]
 

Definition at line 19 of file string.c.

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

Definition at line 950 of file string.c.

Referenced by rb_str_dump(), and rb_str_inspect().

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

Definition at line 902 of file string.c.

Referenced by rb_str_casecmp(), rb_str_cmp(), and rb_str_eql().

#define RESIZE_CAPA str,
capacity   ) 
 

Value:

do {\
    REALLOC_N(RSTRING(str)->ptr, char, (capacity)+1);\
    if (!FL_TEST(str, STR_NOCAPA))\
        RSTRING(str)->aux.capa = (capacity);\
} while (0)

Definition at line 34 of file string.c.

Referenced by rb_str_aset(), rb_str_associate(), rb_str_buf_append(), rb_str_buf_cat(), rb_str_splice(), rb_str_sub_bang(), rb_str_succ(), and str_gsub().

#define STR_ASSOC   FL_USER3
 

Definition at line 31 of file string.c.

#define STR_BUF_MIN_SIZE   128
 

Definition at line 218 of file string.c.

Referenced by rb_str_buf_new().

#define STR_NOCAPA   (ELTS_SHARED|STR_ASSOC)
 

Definition at line 32 of file string.c.

Referenced by rb_str_resize(), rb_str_shared_replace(), str_gsub(), and str_make_independent().

#define STR_TMPLOCK   FL_USER1
 

Definition at line 30 of file string.c.

Referenced by rb_str_locktmp(), rb_str_unlocktmp(), and str_independent().


Typedef Documentation

typedef unsigned char* USTR
 

Definition at line 2958 of file string.c.

Referenced by trnext().


Function Documentation

VALUE get_pat VALUE  ,
int 
[static]
 

Definition at line 1903 of file string.c.

References Check_Type, NIL_P, rb_check_string_type(), rb_reg_quote(), rb_reg_regcomp(), T_REGEXP, T_STRING, TYPE, and VALUE.

Referenced by rb_str_match_m(), rb_str_scan(), rb_str_split_m(), rb_str_sub_bang(), and str_gsub().

void Init_String void   ) 
 

Definition at line 4631 of file string.c.

References id_to_s, Qnil, rb_cObject, rb_cString, rb_define_alloc_func(), rb_define_class(), rb_define_global_function(), rb_define_method(), rb_define_variable(), rb_f_chomp(), rb_f_chomp_bang(), rb_f_chop(), rb_f_chop_bang(), rb_f_gsub(), rb_f_gsub_bang(), rb_f_scan(), rb_f_split(), rb_f_sub(), rb_f_sub_bang(), rb_fs, rb_include_module(), rb_intern(), rb_mComparable, rb_mEnumerable, rb_str_aref_m(), rb_str_aset_m(), rb_str_capitalize(), rb_str_capitalize_bang(), rb_str_casecmp(), rb_str_center(), rb_str_chomp(), rb_str_chomp_bang(), rb_str_chop(), rb_str_chop_bang(), rb_str_cmp_m(), rb_str_concat(), rb_str_count(), rb_str_crypt(), rb_str_delete(), rb_str_delete_bang(), rb_str_downcase(), rb_str_downcase_bang(), rb_str_dump(), rb_str_each_byte(), rb_str_each_line(), rb_str_empty(), rb_str_eql(), rb_str_equal(), rb_str_format(), rb_str_gsub(), rb_str_gsub_bang(), rb_str_hash_m(), rb_str_hex(), rb_str_include(), rb_str_index_m(), rb_str_init(), rb_str_insert(), rb_str_inspect(), rb_str_intern(), rb_str_length(), rb_str_ljust(), rb_str_lstrip(), rb_str_lstrip_bang(), rb_str_match(), rb_str_match_m(), rb_str_oct(), rb_str_plus(), rb_str_replace(), rb_str_reverse(), rb_str_reverse_bang(), rb_str_rindex_m(), rb_str_rjust(), rb_str_rstrip(), rb_str_rstrip_bang(), rb_str_scan(), rb_str_slice_bang(), rb_str_split_m(), rb_str_squeeze(), rb_str_squeeze_bang(), rb_str_strip(), rb_str_strip_bang(), rb_str_sub(), rb_str_sub_bang(), rb_str_succ(), rb_str_succ_bang(), rb_str_sum(), rb_str_swapcase(), rb_str_swapcase_bang(), rb_str_times(), rb_str_to_f(), rb_str_to_i(), rb_str_to_s(), rb_str_tr(), rb_str_tr_bang(), rb_str_tr_s(), rb_str_tr_s_bang(), rb_str_upcase(), rb_str_upcase_bang(), rb_str_upto_m(), and str_alloc().

Referenced by rb_call_inits().

VALUE rb_f_chomp int  argc,
VALUE argv
[static]
 

Definition at line 4008 of file string.c.

References NIL_P, rb_lastline_set(), rb_str_chomp_bang(), rb_str_dup(), uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_f_chomp_bang int  argc,
VALUE argv
[static]
 

Definition at line 3983 of file string.c.

References rb_str_chomp_bang(), uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_f_chop  )  [static]
 

Definition at line 3843 of file string.c.

References rb_lastline_set(), rb_str_chop_bang(), rb_str_dup(), RSTRING, uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_f_chop_bang VALUE  str  )  [static]
 

Definition at line 3818 of file string.c.

References rb_str_chop_bang(), uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_f_gsub int  argc,
VALUE argv
[static]
 

Definition at line 2362 of file string.c.

References NIL_P, rb_lastline_set(), rb_str_dup(), rb_str_gsub_bang(), uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_f_gsub_bang int  argc,
VALUE argv
[static]
 

Definition at line 2341 of file string.c.

References rb_str_gsub_bang(), uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_f_scan VALUE  self,
VALUE  pat
[static]
 

Definition at line 4285 of file string.c.

References rb_str_scan(), uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_f_split int  argc,
VALUE argv
[static]
 

Definition at line 3621 of file string.c.

References rb_str_split_m(), uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_f_sub int  argc,
VALUE argv
[static]
 

Definition at line 2315 of file string.c.

References NIL_P, rb_lastline_set(), rb_str_dup(), rb_str_sub_bang(), uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_f_sub_bang int  argc,
VALUE argv
[static]
 

Definition at line 2298 of file string.c.

References rb_str_sub_bang(), uscore_get(), and VALUE.

Referenced by Init_String().

VALUE rb_str_aref VALUE  str,
VALUE  indx
[static]
 

Definition at line 1512 of file string.c.

References FIX2LONG, INT2FIX, NUM2LONG, OBJ_INFECT, Qfalse, Qnil, rb_range_beg_len(), rb_str_dup(), rb_str_index(), rb_str_subpat(), rb_str_substr(), RSTRING, T_FIXNUM, T_REGEXP, T_STRING, TYPE, and VALUE.

Referenced by rb_str_aref_m().

VALUE rb_str_aref_m int  argc,
VALUE argv,
VALUE  str
[static]
 

Definition at line 1611 of file string.c.

References NUM2INT, NUM2LONG, rb_eArgError, rb_raise(), rb_str_aref(), rb_str_subpat(), rb_str_substr(), T_REGEXP, TYPE, and VALUE.

Referenced by Init_String(), and rb_str_slice_bang().

VALUE rb_str_aset VALUE  str,
VALUE  indx,
VALUE  val
[static]
 

Definition at line 1719 of file string.c.

References FIX2INT, FIX2LONG, FIXNUM_P, NUM2LONG, rb_eIndexError, rb_raise(), rb_range_beg_len(), rb_str_index(), rb_str_modify(), rb_str_splice(), rb_str_subpat_set(), RESIZE_CAPA, RSTRING, T_FIXNUM, T_REGEXP, T_STRING, TYPE, and VALUE.

Referenced by rb_str_aset_m().

VALUE rb_str_aset_m int  argc,
VALUE argv,
VALUE  str
[static]
 

Definition at line 1803 of file string.c.

References NUM2INT, NUM2LONG, rb_eArgError, rb_raise(), rb_str_aset(), rb_str_splice(), rb_str_subpat_set(), T_REGEXP, TYPE, and VALUE.

Referenced by Init_String(), and rb_str_slice_bang().

VALUE rb_str_buf_new2 char *  ptr  )  const
 

Definition at line 239 of file string.c.

References rb_str_buf_cat(), rb_str_buf_new(), and VALUE.

Referenced by compile_error(), env_inspect(), exc_inspect(), inspect_ary(), inspect_hash(), inspect_struct(), method_inspect(), rb_reg_desc(), rb_reg_to_s(), rb_stat_inspect(), and rb_str_inspect().

VALUE rb_str_capitalize VALUE  str  )  [static]
 

Definition at line 2892 of file string.c.

References rb_str_capitalize_bang(), rb_str_dup(), and VALUE.

Referenced by Init_String().

VALUE rb_str_capitalize_bang VALUE  str  )  [static]
 

Definition at line 2852 of file string.c.

References ISLOWER, ismbchar, ISUPPER, mbclen, Qnil, rb_str_modify(), RSTRING, and VALUE.

Referenced by Init_String(), and rb_str_capitalize().

VALUE rb_str_casecmp VALUE  str1,
VALUE  str2
[static]
 

Definition at line 1040 of file string.c.

References INT2FIX, lesser, rb_memcicmp(), RSTRING, StringValue, and VALUE.

Referenced by Init_String().

VALUE rb_str_center int  argc,
VALUE argv,
VALUE  str
[static]
 

Definition at line 4596 of file string.c.

References rb_str_justify(), and VALUE.

Referenced by Init_String().

VALUE rb_str_chomp int  argc,
VALUE argv,
VALUE  str
[static]
 

Definition at line 3957 of file string.c.

References rb_str_chomp_bang(), rb_str_dup(), and VALUE.

Referenced by Init_String().

VALUE rb_str_chomp_bang int  argc,
VALUE argv,
VALUE  str
[static]
 

Definition at line 3865 of file string.c.

References NIL_P, Qnil, rb_default_rs, rb_memcmp(), rb_rs, rb_scan_args(), rb_str_modify(), RSTRING, StringValue, and VALUE.

Referenced by Init_String(), rb_f_chomp(), rb_f_chomp_bang(), and rb_str_chomp().

VALUE rb_str_chop VALUE  str  )  [static]
 

Definition at line 3791 of file string.c.

References rb_str_chop_bang(), rb_str_dup(), and VALUE.

Referenced by Init_String().

VALUE rb_str_chop_bang VALUE  str  )  [static]
 

Definition at line 3754 of file string.c.

References Qnil, rb_str_modify(), RSTRING, and VALUE.

Referenced by Init_String(), rb_f_chop(), rb_f_chop_bang(), and rb_str_chop().

VALUE rb_str_cmp_m VALUE  str1,
VALUE  str2
[static]
 

Definition at line 999 of file string.c.

References FIX2LONG, FIXNUM_P, LONG2FIX, LONG2NUM, NIL_P, Qnil, rb_funcall(), rb_intern(), rb_respond_to(), rb_str_cmp(), T_STRING, TYPE, and VALUE.

Referenced by Init_String().

VALUE rb_str_count int  argc,
VALUE argv,
VALUE  str
[static]
 

Definition at line 3391 of file string.c.

References INT2FIX, INT2NUM, rb_eArgError, rb_raise(), RSTRING, StringValue, tr_setup_table(), and VALUE.

Referenced by Init_String().

VALUE rb_str_crypt VALUE  str,
VALUE  salt
[static]
 

Definition at line 4347 of file string.c.

References crypt(), OBJ_INFECT, rb_eArgError, rb_raise(), rb_str_new2(), RSTRING, StringValue, and VALUE.

Referenced by Init_String().

VALUE rb_str_delete int  argc,
VALUE argv,
VALUE  str
[static]
 

Definition at line 3240 of file string.c.

References rb_str_delete_bang(), rb_str_dup(), and VALUE.

Referenced by Init_String().

VALUE rb_str_delete_bang int  ,
VALUE ,
VALUE 
[static]
 

Definition at line 3184 of file string.c.

References Qnil, rb_eArgError, rb_raise(), rb_str_modify(), RSTRING, StringValue, tr_setup_table(), and VALUE.

Referenced by Init_String(), rb_str_delete(), and tr_trans().

VALUE rb_str_downcase VALUE  str  )  [static]
 

Definition at line 2829 of file string.c.

References rb_str_downcase_bang(), rb_str_dup(), and VALUE.

Referenced by Init_String().

VALUE rb_str_downcase_bang VALUE  str  )  [static]
 

Definition at line 2793 of file string.c.

References ismbchar, ISUPPER, mbclen, Qnil, rb_str_modify(), RSTRING, and VALUE.

Referenced by Init_String(), and rb_str_downcase().

VALUE rb_str_each_byte VALUE  str  )  [static]
 

Definition at line 3732 of file string.c.

References INT2FIX, rb_yield(), RSTRING, and VALUE.

Referenced by Init_String().

VALUE rb_str_each_line int  argc,
VALUE argv,
VALUE  str
[static]
 

Definition at line 3662 of file string.c.

References NIL_P, OBJ_INFECT, rb_memcmp(), rb_rs, rb_scan_args(), rb_str_new5(), rb_yield(), RSTRING, str_mod_check(), StringValue, and VALUE.

Referenced by Init_String().

VALUE rb_str_empty VALUE  str  )  [static]
 

Definition at line