2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
re.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Mon Aug 9 18:24:49 JST 1993
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-06-09 23:06:15 -04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/re.h"
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
#include "ruby/encoding.h"
|
2007-12-01 11:56:19 -05:00
|
|
|
#include "ruby/util.h"
|
2005-05-05 19:08:47 -04:00
|
|
|
#include "regint.h"
|
2001-05-16 05:05:54 -04:00
|
|
|
#include <ctype.h>
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2006-07-20 13:36:36 -04:00
|
|
|
VALUE rb_eRegexpError;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
typedef char onig_errmsg_buffer[ONIG_MAX_ERROR_MESSAGE_LEN];
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#define BEG(no) regs->beg[no]
|
|
|
|
#define END(no) regs->end[no]
|
|
|
|
|
|
|
|
#if 'a' == 97 /* it's ascii */
|
1999-08-13 01:45:20 -04:00
|
|
|
static const char casetable[] = {
|
1998-01-16 07:13:05 -05:00
|
|
|
'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
|
|
|
|
'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
|
|
|
|
'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
|
|
|
|
'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
|
|
|
|
/* ' ' '!' '"' '#' '$' '%' '&' ''' */
|
|
|
|
'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
|
|
|
|
/* '(' ')' '*' '+' ',' '-' '.' '/' */
|
|
|
|
'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
|
|
|
|
/* '0' '1' '2' '3' '4' '5' '6' '7' */
|
|
|
|
'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
|
|
|
|
/* '8' '9' ':' ';' '<' '=' '>' '?' */
|
|
|
|
'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
|
|
|
|
/* '@' 'A' 'B' 'C' 'D' 'E' 'F' 'G' */
|
|
|
|
'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
|
|
/* 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' */
|
|
|
|
'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
|
|
/* 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' */
|
|
|
|
'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
|
|
/* 'X' 'Y' 'Z' '[' '\' ']' '^' '_' */
|
|
|
|
'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
|
|
|
|
/* '`' 'a' 'b' 'c' 'd' 'e' 'f' 'g' */
|
|
|
|
'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
|
|
/* 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' */
|
|
|
|
'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
|
|
/* 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' */
|
|
|
|
'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
|
|
/* 'x' 'y' 'z' '{' '|' '}' '~' */
|
|
|
|
'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
|
|
|
|
'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
|
|
|
|
'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
|
|
|
|
'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
|
|
|
|
'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
|
|
|
|
'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
|
|
|
|
'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
|
|
|
|
'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
|
|
|
|
'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
|
|
|
|
'\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
|
|
|
|
'\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
|
|
|
|
'\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
|
|
|
|
'\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
|
|
|
|
'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
|
|
|
|
'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
|
|
|
|
'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
|
|
|
|
'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
|
|
|
|
};
|
|
|
|
#else
|
2002-08-21 11:47:54 -04:00
|
|
|
# error >>> "You lose. You will need a translation table for your character set." <<<
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
rb_memcicmp(const void *x, const void *y, long len)
|
2000-06-14 01:30:29 -04:00
|
|
|
{
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
const unsigned char *p1 = x, *p2 = y;
|
2000-06-14 01:30:29 -04:00
|
|
|
int tmp;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-06-14 01:30:29 -04:00
|
|
|
while (len--) {
|
2006-03-26 08:04:13 -05:00
|
|
|
if ((tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++]))
|
2000-06-14 01:30:29 -04:00
|
|
|
return tmp;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-06-14 01:30:29 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-06 01:32:37 -04:00
|
|
|
#undef rb_memcmp
|
|
|
|
|
2007-10-04 05:54:53 -04:00
|
|
|
int
|
|
|
|
rb_memcmp(const void *p1, const void *p2, long len)
|
|
|
|
{
|
2007-10-04 05:59:56 -04:00
|
|
|
return memcmp(p1, p2, len);
|
2007-10-04 05:54:53 -04:00
|
|
|
}
|
|
|
|
|
2003-02-07 01:35:26 -05:00
|
|
|
long
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
rb_memsearch(const void *x0, long m, const void *y0, long n)
|
2003-02-03 00:34:16 -05:00
|
|
|
{
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
const unsigned char *x = x0, *y = y0;
|
|
|
|
const unsigned char *s, *e;
|
2003-02-03 02:34:06 -05:00
|
|
|
long i;
|
|
|
|
int d;
|
2003-02-03 00:34:16 -05:00
|
|
|
unsigned long hx, hy;
|
|
|
|
|
2005-11-23 00:11:18 -05:00
|
|
|
#define KR_REHASH(a, b, h) (((h) << 1) - (((unsigned long)(a))<<d) + (b))
|
2003-02-03 00:34:16 -05:00
|
|
|
|
2003-09-01 11:44:39 -04:00
|
|
|
if (m > n) return -1;
|
|
|
|
s = y; e = s + n - m;
|
2003-02-03 00:34:16 -05:00
|
|
|
|
|
|
|
/* Preprocessing */
|
|
|
|
/* computes d = 2^(m-1) with
|
|
|
|
the left-shift operator */
|
2003-02-03 02:34:06 -05:00
|
|
|
d = sizeof(hx) * CHAR_BIT - 1;
|
|
|
|
if (d > m) d = m;
|
2003-02-03 00:34:16 -05:00
|
|
|
|
2007-10-04 03:31:50 -04:00
|
|
|
if (n == m) {
|
|
|
|
return memcmp(x, s, m) == 0 ? 0 : -1;
|
2003-02-03 00:34:16 -05:00
|
|
|
}
|
2007-10-04 03:31:50 -04:00
|
|
|
/* Prepare hash value */
|
|
|
|
for (hy = hx = i = 0; i < d; ++i) {
|
|
|
|
hx = KR_REHASH(0, x[i], hx);
|
|
|
|
hy = KR_REHASH(0, s[i], hy);
|
|
|
|
}
|
|
|
|
/* Searching */
|
|
|
|
while (hx != hy || memcmp(x, s, m)) {
|
|
|
|
if (s >= e) return -1;
|
|
|
|
hy = KR_REHASH(*s, *(s+d), hy);
|
|
|
|
s++;
|
2003-02-03 00:34:16 -05:00
|
|
|
}
|
2003-09-01 11:44:39 -04:00
|
|
|
return s-y;
|
2003-02-03 00:34:16 -05:00
|
|
|
}
|
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
#define REG_LITERAL FL_USER5
|
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
#define KCODE_FIXED FL_USER4
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-10-19 03:41:03 -04:00
|
|
|
#define ARG_REG_OPTION_MASK \
|
|
|
|
(ONIG_OPTION_IGNORECASE|ONIG_OPTION_MULTILINE|ONIG_OPTION_EXTEND)
|
|
|
|
#define ARG_ENCODING_FIXED 16
|
|
|
|
|
|
|
|
#define ARG_KCODE_NONE 0
|
2007-10-16 01:48:40 -04:00
|
|
|
#define ARG_KCODE_EUC 1
|
|
|
|
#define ARG_KCODE_SJIS 2
|
|
|
|
#define ARG_KCODE_UTF8 3
|
1998-01-16 07:13:05 -05:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
static int
|
|
|
|
char_to_option(int c)
|
|
|
|
{
|
|
|
|
int val;
|
2006-03-26 08:04:13 -05:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
switch (c) {
|
|
|
|
case 'i':
|
|
|
|
val = ONIG_OPTION_IGNORECASE;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
val = ONIG_OPTION_EXTEND;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
val = ONIG_OPTION_MULTILINE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
val = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return val;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2007-08-02 10:42:59 -04:00
|
|
|
static char *
|
|
|
|
option_to_str(char str[4], int options)
|
|
|
|
{
|
|
|
|
char *p = str;
|
|
|
|
if (options & ONIG_OPTION_MULTILINE) *p++ = 'm';
|
|
|
|
if (options & ONIG_OPTION_IGNORECASE) *p++ = 'i';
|
|
|
|
if (options & ONIG_OPTION_EXTEND) *p++ = 'x';
|
|
|
|
*p = 0;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
extern int
|
|
|
|
rb_char_to_option_kcode(int c, int *option, int *kcode)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*option = 0;
|
2006-03-26 08:04:13 -05:00
|
|
|
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
switch (c) {
|
2007-10-19 03:41:03 -04:00
|
|
|
case 'n':
|
|
|
|
*kcode = ARG_KCODE_NONE;
|
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
case 'e':
|
|
|
|
*kcode = ARG_KCODE_EUC;
|
2007-10-19 03:41:03 -04:00
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
case 's':
|
|
|
|
*kcode = ARG_KCODE_SJIS;
|
2007-10-19 03:41:03 -04:00
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
case 'u':
|
|
|
|
*kcode = ARG_KCODE_UTF8;
|
2007-10-19 03:41:03 -04:00
|
|
|
break;
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
default:
|
2007-10-19 03:41:03 -04:00
|
|
|
*kcode = -1;
|
2007-10-16 01:48:40 -04:00
|
|
|
return (*option = char_to_option(c));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2007-10-19 03:41:03 -04:00
|
|
|
*option = ARG_ENCODING_FIXED;
|
|
|
|
return 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_check(VALUE re)
|
2000-05-22 03:09:55 -04:00
|
|
|
{
|
|
|
|
if (!RREGEXP(re)->ptr || !RREGEXP(re)->str) {
|
|
|
|
rb_raise(rb_eTypeError, "uninitialized Regexp");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_expr_str(VALUE str, const char *s, long len)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
rb_encoding *enc = rb_enc_get(str);
|
1999-08-13 01:45:20 -04:00
|
|
|
const char *p, *pend;
|
2000-05-30 00:24:17 -04:00
|
|
|
int need_escape = 0;
|
2007-12-10 22:08:50 -05:00
|
|
|
int c, clen;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
p = s; pend = p + len;
|
|
|
|
while (p<pend) {
|
2007-12-10 22:08:50 -05:00
|
|
|
c = rb_enc_get_ascii(p, pend, &clen, enc);
|
|
|
|
if (c == -1) {
|
|
|
|
p += mbclen(p, pend, enc);
|
|
|
|
}
|
|
|
|
else if (c != '/' && rb_enc_isprint(c, enc)) {
|
|
|
|
p += clen;
|
|
|
|
}
|
|
|
|
else {
|
2000-05-30 00:24:17 -04:00
|
|
|
need_escape = 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
2007-12-10 22:08:50 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-05-30 00:24:17 -04:00
|
|
|
if (!need_escape) {
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(str, s, len);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
2004-03-05 17:37:35 -05:00
|
|
|
p = s;
|
1998-01-16 07:13:05 -05:00
|
|
|
while (p<pend) {
|
2007-12-10 22:08:50 -05:00
|
|
|
c = rb_enc_get_ascii(p, pend, &clen, enc);
|
|
|
|
if (c == '\\' && p+clen < pend) {
|
|
|
|
int n = clen + mbclen(p+clen, pend, enc);
|
2002-09-02 10:04:19 -04:00
|
|
|
rb_str_buf_cat(str, p, n);
|
|
|
|
p += n;
|
2002-06-28 10:42:46 -04:00
|
|
|
continue;
|
|
|
|
}
|
2007-12-07 21:50:43 -05:00
|
|
|
else if (c == '/') {
|
1998-01-16 07:13:05 -05:00
|
|
|
char c = '\\';
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat(str, &c, 1);
|
2007-12-10 22:08:50 -05:00
|
|
|
rb_str_buf_cat(str, p, clen);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2007-12-07 21:50:43 -05:00
|
|
|
else if (c == -1) {
|
|
|
|
int l = mbclen(p, pend, enc);
|
|
|
|
rb_str_buf_cat(str, p, l);
|
|
|
|
p += l;
|
2000-05-30 00:24:17 -04:00
|
|
|
continue;
|
|
|
|
}
|
2007-12-07 21:50:43 -05:00
|
|
|
else if (rb_enc_isprint(c, enc)) {
|
2007-12-10 22:08:50 -05:00
|
|
|
rb_str_buf_cat(str, p, clen);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2007-12-07 21:50:43 -05:00
|
|
|
else if (!rb_enc_isspace(c, enc)) {
|
2000-05-30 00:24:17 -04:00
|
|
|
char b[8];
|
2002-04-24 00:54:16 -04:00
|
|
|
|
2007-12-09 16:48:05 -05:00
|
|
|
sprintf(b, "\\x%02x", c);
|
2002-04-24 00:54:16 -04:00
|
|
|
rb_str_buf_cat(str, b, 4);
|
|
|
|
}
|
|
|
|
else {
|
2007-12-10 22:08:50 -05:00
|
|
|
rb_str_buf_cat(str, p, clen);
|
2000-05-30 00:24:17 -04:00
|
|
|
}
|
2007-12-10 22:08:50 -05:00
|
|
|
p += clen;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_desc(const char *s, long len, VALUE re)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2001-05-30 05:12:34 -04:00
|
|
|
VALUE str = rb_str_buf_new2("/");
|
2000-05-22 03:09:55 -04:00
|
|
|
|
2007-10-16 14:37:09 -04:00
|
|
|
rb_enc_copy(str, re);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_reg_expr_str(str, s, len);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_str_buf_cat2(str, "/");
|
1998-01-16 07:13:05 -05:00
|
|
|
if (re) {
|
2007-08-02 10:42:59 -04:00
|
|
|
char opts[4];
|
2000-05-24 03:36:46 -04:00
|
|
|
rb_reg_check(re);
|
2007-08-02 10:42:59 -04:00
|
|
|
if (*option_to_str(opts, RREGEXP(re)->ptr->options))
|
|
|
|
rb_str_buf_cat2(str, opts);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-02-23 00:23:12 -05:00
|
|
|
OBJ_INFECT(str, re);
|
1998-01-16 07:13:05 -05:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2007-12-09 08:35:38 -05:00
|
|
|
* rxp.source => str
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the original string of the pattern.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2007-12-09 08:35:38 -05:00
|
|
|
* /ab+c/ix.source #=> "ab+c"
|
|
|
|
*
|
|
|
|
* Note that escape sequences are retained as is.
|
|
|
|
*
|
|
|
|
* /\x20\+/.source #=> "\\x20\\+"
|
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_source(VALUE re)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
VALUE str;
|
|
|
|
|
|
|
|
rb_reg_check(re);
|
|
|
|
str = rb_str_new(RREGEXP(re)->str,RREGEXP(re)->len);
|
1999-12-01 04:24:48 -05:00
|
|
|
if (OBJ_TAINTED(re)) OBJ_TAINT(str);
|
|
|
|
return str;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-12-30 11:38:32 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.inspect => string
|
|
|
|
*
|
|
|
|
* Produce a nicely formatted string-version of _rxp_. Perhaps surprisingly,
|
|
|
|
* <code>#inspect</code> actually produces the more natural version of
|
|
|
|
* the string than <code>#to_s</code>.
|
|
|
|
*
|
2007-12-09 08:35:38 -05:00
|
|
|
* /ab+c/ix.inspect #=> "/ab+c/ix"
|
|
|
|
*
|
2003-12-30 11:38:32 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_inspect(VALUE re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_desc(RREGEXP(re)->str, RREGEXP(re)->len, re);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.to_s => str
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
* array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-14 00:06:52 -04:00
|
|
|
* Returns a string containing the regular expression and its options (using the
|
2007-12-02 10:46:21 -05:00
|
|
|
* <code>(?opts:source)</code> notation. This string can be fed back in to
|
2003-12-26 10:58:28 -05:00
|
|
|
* <code>Regexp::new</code> to a regular expression with the same semantics as
|
|
|
|
* the original. (However, <code>Regexp#==</code> may not return true when
|
|
|
|
* comparing the two, as the source of the regular expression itself may
|
|
|
|
* differ, as the example shows). <code>Regexp#inspect</code> produces a
|
|
|
|
* generally more readable version of <i>rxp</i>.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2007-12-09 08:35:38 -05:00
|
|
|
* r1 = /ab+c/ix #=> /ab+c/ix
|
|
|
|
* s1 = r1.to_s #=> "(?ix-m:ab+c)"
|
|
|
|
* r2 = Regexp.new(s1) #=> /(?ix-m:ab+c)/
|
|
|
|
* r1 == r2 #=> false
|
|
|
|
* r1.source #=> "ab+c"
|
|
|
|
* r2.source #=> "(?ix-m:ab+c)"
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
2002-04-18 04:04:57 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_to_s(VALUE re)
|
2002-04-18 04:04:57 -04:00
|
|
|
{
|
2006-03-26 08:04:13 -05:00
|
|
|
int options, opt;
|
2005-02-17 09:43:38 -05:00
|
|
|
const int embeddable = ONIG_OPTION_MULTILINE|ONIG_OPTION_IGNORECASE|ONIG_OPTION_EXTEND;
|
2002-04-19 00:14:07 -04:00
|
|
|
long len;
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
const UChar* ptr;
|
2002-04-18 04:04:57 -04:00
|
|
|
VALUE str = rb_str_buf_new2("(?");
|
2007-08-02 10:42:59 -04:00
|
|
|
char optbuf[5];
|
2002-04-18 04:04:57 -04:00
|
|
|
|
|
|
|
rb_reg_check(re);
|
|
|
|
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_enc_copy(str, re);
|
2002-04-19 00:14:07 -04:00
|
|
|
options = RREGEXP(re)->ptr->options;
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
ptr = (UChar*)RREGEXP(re)->str;
|
2002-04-19 00:14:07 -04:00
|
|
|
len = RREGEXP(re)->len;
|
2002-04-24 00:54:16 -04:00
|
|
|
again:
|
|
|
|
if (len >= 4 && ptr[0] == '(' && ptr[1] == '?') {
|
2002-04-19 01:59:45 -04:00
|
|
|
int err = 1;
|
2002-04-19 00:14:07 -04:00
|
|
|
ptr += 2;
|
2002-04-24 00:54:16 -04:00
|
|
|
if ((len -= 2) > 0) {
|
2002-04-19 00:14:07 -04:00
|
|
|
do {
|
2006-03-26 08:04:13 -05:00
|
|
|
opt = char_to_option((int )*ptr);
|
|
|
|
if (opt != 0) {
|
|
|
|
options |= opt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
2002-04-19 00:14:07 -04:00
|
|
|
++ptr;
|
|
|
|
} while (--len > 0);
|
|
|
|
}
|
|
|
|
if (len > 1 && *ptr == '-') {
|
|
|
|
++ptr;
|
|
|
|
--len;
|
|
|
|
do {
|
2006-03-26 08:04:13 -05:00
|
|
|
opt = char_to_option((int )*ptr);
|
|
|
|
if (opt != 0) {
|
|
|
|
options &= ~opt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
2002-04-19 00:14:07 -04:00
|
|
|
++ptr;
|
|
|
|
} while (--len > 0);
|
|
|
|
}
|
2002-04-24 00:54:16 -04:00
|
|
|
if (*ptr == ')') {
|
|
|
|
--len;
|
|
|
|
++ptr;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if (*ptr == ':' && ptr[len-1] == ')') {
|
2004-03-05 10:40:36 -05:00
|
|
|
int r;
|
2002-04-24 00:54:16 -04:00
|
|
|
Regexp *rp;
|
2005-02-17 09:43:38 -05:00
|
|
|
r = onig_alloc_init(&rp, ONIG_OPTION_DEFAULT,
|
2007-05-22 21:32:08 -04:00
|
|
|
ONIGENC_CASE_FOLD_DEFAULT,
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_enc_get(re),
|
2005-02-17 09:43:38 -05:00
|
|
|
OnigDefaultSyntax);
|
2004-03-05 10:40:36 -05:00
|
|
|
if (r == 0) {
|
2005-02-17 09:43:38 -05:00
|
|
|
++ptr;
|
|
|
|
len -= 2;
|
|
|
|
err = (onig_compile(rp, ptr, ptr + len, NULL) != 0);
|
2004-03-05 10:40:36 -05:00
|
|
|
}
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_free(rp);
|
2002-04-19 00:14:07 -04:00
|
|
|
}
|
2002-04-19 01:59:45 -04:00
|
|
|
if (err) {
|
2002-04-19 00:14:07 -04:00
|
|
|
options = RREGEXP(re)->ptr->options;
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
ptr = (UChar*)RREGEXP(re)->str;
|
2002-04-19 00:14:07 -04:00
|
|
|
len = RREGEXP(re)->len;
|
|
|
|
}
|
|
|
|
}
|
2002-04-18 04:04:57 -04:00
|
|
|
|
2007-08-02 10:42:59 -04:00
|
|
|
if (*option_to_str(optbuf, options)) rb_str_buf_cat2(str, optbuf);
|
2002-04-19 00:14:07 -04:00
|
|
|
|
|
|
|
if ((options & embeddable) != embeddable) {
|
2007-08-02 10:42:59 -04:00
|
|
|
optbuf[0] = '-';
|
|
|
|
option_to_str(optbuf + 1, ~options);
|
|
|
|
rb_str_buf_cat2(str, optbuf);
|
2002-04-18 04:04:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
rb_str_buf_cat2(str, ":");
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
rb_reg_expr_str(str, (char*)ptr, len);
|
2002-04-18 04:04:57 -04:00
|
|
|
rb_str_buf_cat2(str, ")");
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_enc_copy(str, re);
|
2002-04-18 04:04:57 -04:00
|
|
|
|
|
|
|
OBJ_INFECT(str, re);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static void
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
rb_reg_raise(const char *s, long len, const char *err, VALUE re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE desc = rb_reg_desc(s, len, re);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
rb_raise(rb_eRegexpError, "%s: %s", err, RSTRING_PTR(desc));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2007-08-25 03:06:47 -04:00
|
|
|
static VALUE
|
|
|
|
rb_reg_error_desc(VALUE str, int options, const char *err)
|
|
|
|
{
|
|
|
|
char opts[6];
|
|
|
|
VALUE desc = rb_str_buf_new2(err);
|
|
|
|
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_enc_copy(desc, str);
|
2007-08-25 03:06:47 -04:00
|
|
|
rb_str_buf_cat2(desc, ": /");
|
|
|
|
rb_reg_expr_str(desc, RSTRING_PTR(str), RSTRING_LEN(str));
|
|
|
|
opts[0] = '/';
|
|
|
|
option_to_str(opts + 1, options);
|
|
|
|
rb_str_buf_cat2(desc, opts);
|
|
|
|
return rb_exc_new3(rb_eRegexpError, desc);
|
|
|
|
}
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
static void
|
2007-08-25 03:06:47 -04:00
|
|
|
rb_reg_raise_str(VALUE str, int options, const char *err)
|
2007-08-18 01:05:36 -04:00
|
|
|
{
|
2007-08-25 03:06:47 -04:00
|
|
|
rb_exc_raise(rb_reg_error_desc(str, options, err));
|
2007-08-18 01:05:36 -04:00
|
|
|
}
|
2003-12-26 10:58:28 -05:00
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.casefold? => true or false
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the value of the case-insensitive flag.
|
2007-12-09 08:35:38 -05:00
|
|
|
*
|
|
|
|
* /a/.casefold? #=> false
|
|
|
|
* /a/i.casefold? #=> true
|
|
|
|
* /(?i:a)/.casefold? #=> false
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_casefold_p(VALUE re)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
2005-02-17 09:43:38 -05:00
|
|
|
if (RREGEXP(re)->ptr->options & ONIG_OPTION_IGNORECASE) return Qtrue;
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.options => fixnum
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the set of bits corresponding to the options used when creating this
|
|
|
|
* Regexp (see <code>Regexp::new</code> for details. Note that additional bits
|
|
|
|
* may be set in the returned options: these are used internally by the regular
|
|
|
|
* expression code. These extra bits are ignored if the options are passed to
|
|
|
|
* <code>Regexp::new</code>.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Regexp::IGNORECASE #=> 1
|
|
|
|
* Regexp::EXTENDED #=> 2
|
|
|
|
* Regexp::MULTILINE #=> 4
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2007-12-09 08:35:38 -05:00
|
|
|
* /cat/.options #=> 0
|
|
|
|
* /cat/ix.options #=> 3
|
|
|
|
* Regexp.new('cat', true).options #=> 1
|
|
|
|
* /\xa1\xa2/e.options #=> 16
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* r = /cat/ix
|
|
|
|
* Regexp.new(r.source, r.options) #=> /cat/ix
|
|
|
|
*/
|
|
|
|
|
2001-02-08 04:19:27 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_options_m(VALUE re)
|
2001-02-08 04:19:27 -05:00
|
|
|
{
|
2003-07-25 00:38:42 -04:00
|
|
|
int options = rb_reg_options(re);
|
|
|
|
return INT2NUM(options);
|
2001-02-08 04:19:27 -05:00
|
|
|
}
|
|
|
|
|
2007-12-09 16:44:19 -05:00
|
|
|
static int
|
|
|
|
reg_names_iter(const OnigUChar *name, const OnigUChar *name_end,
|
|
|
|
int back_num, int *back_refs, OnigRegex regex, void *arg)
|
|
|
|
{
|
|
|
|
VALUE ary = (VALUE)arg;
|
|
|
|
rb_ary_push(ary, rb_str_new((const char *)name, name_end-name));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.names => [name1, name2, ...]
|
|
|
|
*
|
|
|
|
* Returns a list of names of captures as an array of strings.
|
|
|
|
*
|
|
|
|
* /(?<foo>.)(?<bar>.)(?<baz>.)/.names
|
|
|
|
* #=> ["foo", "bar", "baz"]
|
|
|
|
*
|
|
|
|
* /(?<foo>.)(?<foo>.)/.names
|
|
|
|
* #=> ["foo"]
|
|
|
|
*
|
|
|
|
* /(.)(.)/.names'
|
|
|
|
* #=> []
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_reg_names(VALUE re)
|
|
|
|
{
|
|
|
|
VALUE ary = rb_ary_new();
|
|
|
|
onig_foreach_name(RREGEXP(re)->ptr, reg_names_iter, (void*)ary);
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
reg_named_captures_iter(const OnigUChar *name, const OnigUChar *name_end,
|
|
|
|
int back_num, int *back_refs, OnigRegex regex, void *arg)
|
|
|
|
{
|
|
|
|
VALUE hash = (VALUE)arg;
|
|
|
|
VALUE ary = rb_ary_new2(back_num);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < back_num; i++)
|
|
|
|
rb_ary_store(ary, i, INT2NUM(back_refs[i]));
|
|
|
|
|
|
|
|
rb_hash_aset(hash, rb_str_new((const char*)name, name_end-name),ary);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.named_captures => hash
|
|
|
|
*
|
|
|
|
* Returns a hash representing information about named captures of <i>rxp</i>.
|
|
|
|
*
|
|
|
|
* A key of the hash is a name of the named captures.
|
|
|
|
* A value of the hash is an array which is list of indexes of corresponding
|
|
|
|
* named captures.
|
|
|
|
*
|
|
|
|
* /(?<foo>.)(?<bar>.)/.named_captures
|
|
|
|
* #=> {"foo"=>[1], "bar"=>[2]}
|
|
|
|
*
|
|
|
|
* /(?<foo>.)(?<foo>.)/.named_captures'
|
|
|
|
* #=> {"foo"=>[1, 2]}
|
|
|
|
*
|
|
|
|
* If there are no named captures, an empty hash is returned.
|
|
|
|
*
|
|
|
|
* /(.)(.)/.named_captures'
|
|
|
|
* #=> {}
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_reg_named_captures(VALUE re)
|
|
|
|
{
|
|
|
|
VALUE hash = rb_hash_new();
|
|
|
|
onig_foreach_name(RREGEXP(re)->ptr, reg_named_captures_iter, (void*)hash);
|
|
|
|
return hash;
|
|
|
|
}
|
2003-12-26 10:58:28 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static Regexp*
|
2007-10-16 01:48:40 -04:00
|
|
|
make_regexp(const char *s, long len, rb_encoding *enc, int flags, onig_errmsg_buffer err)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
Regexp *rp;
|
2004-03-05 10:40:36 -05:00
|
|
|
int r;
|
2005-02-17 09:43:38 -05:00
|
|
|
OnigErrorInfo einfo;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
/* Handle escaped characters first. */
|
|
|
|
|
|
|
|
/* Build a copy of the string (in dest) with the
|
|
|
|
escaped characters translated, and generate the regex
|
|
|
|
from that.
|
|
|
|
*/
|
|
|
|
|
2007-10-16 01:48:40 -04:00
|
|
|
r = onig_alloc_init(&rp, flags, ONIGENC_CASE_FOLD_DEFAULT,
|
|
|
|
enc, OnigDefaultSyntax);
|
2004-03-05 10:40:36 -05:00
|
|
|
if (r) {
|
2005-05-22 23:24:28 -04:00
|
|
|
onig_error_code_to_str((UChar*)err, r);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
return 0;
|
2004-03-05 10:40:36 -05:00
|
|
|
}
|
2004-03-05 17:37:35 -05:00
|
|
|
|
2005-05-22 23:24:28 -04:00
|
|
|
r = onig_compile(rp, (UChar*)s, (UChar*)(s + len), &einfo);
|
2002-08-21 11:47:54 -04:00
|
|
|
|
2004-03-05 10:40:36 -05:00
|
|
|
if (r != 0) {
|
2005-03-16 04:25:45 -05:00
|
|
|
onig_free(rp);
|
2005-05-22 23:24:28 -04:00
|
|
|
(void )onig_error_code_to_str((UChar*)err, r, &einfo);
|
|
|
|
return 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return rp;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: MatchData
|
|
|
|
*
|
|
|
|
* <code>MatchData</code> is the type of the special variable <code>$~</code>,
|
|
|
|
* and is the type of the object returned by <code>Regexp#match</code> and
|
2007-12-09 08:35:38 -05:00
|
|
|
* <code>Regexp.last_match</code>. It encapsulates all the results of a pattern
|
2003-12-26 10:58:28 -05:00
|
|
|
* match, results normally accessed through the special variables
|
|
|
|
* <code>$&</code>, <code>$'</code>, <code>$`</code>, <code>$1</code>,
|
2007-12-09 08:35:38 -05:00
|
|
|
* <code>$2</code>, and so on.
|
2003-12-26 10:58:28 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-07-20 13:36:36 -04:00
|
|
|
VALUE rb_cMatch;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_alloc(VALUE klass)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
NEWOBJ(match, struct RMatch);
|
2002-08-30 04:22:09 -04:00
|
|
|
OBJSETUP(match, klass, T_MATCH);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
match->str = 0;
|
1999-01-19 23:59:39 -05:00
|
|
|
match->regs = 0;
|
2006-03-21 08:16:21 -05:00
|
|
|
match->regexp = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
match->regs = ALLOC(struct re_registers);
|
|
|
|
MEMZERO(match->regs, struct re_registers, 1);
|
|
|
|
|
|
|
|
return (VALUE)match;
|
|
|
|
}
|
|
|
|
|
2004-01-18 09:16:47 -05:00
|
|
|
/* :nodoc: */
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_init_copy(VALUE obj, VALUE orig)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2002-08-30 04:22:09 -04:00
|
|
|
if (obj == orig) return obj;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2002-08-30 04:22:09 -04:00
|
|
|
if (!rb_obj_is_instance_of(orig, rb_obj_class(obj))) {
|
|
|
|
rb_raise(rb_eTypeError, "wrong argument class");
|
|
|
|
}
|
|
|
|
RMATCH(obj)->str = RMATCH(orig)->str;
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_region_free(RMATCH(obj)->regs, 0);
|
2002-08-30 04:22:09 -04:00
|
|
|
RMATCH(obj)->regs->allocated = 0;
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_region_copy(RMATCH(obj)->regs, RMATCH(orig)->regs);
|
2002-08-27 04:31:08 -04:00
|
|
|
|
2002-08-30 04:22:09 -04:00
|
|
|
return obj;
|
2002-08-27 04:31:08 -04:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
2007-12-09 16:44:19 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.regexp => regexp
|
|
|
|
*
|
|
|
|
* Returns the regexp.
|
|
|
|
*
|
|
|
|
* m = /a.*b/.match("abc")
|
|
|
|
* m.regexp #=> /a.*b/
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
match_regexp(VALUE match)
|
|
|
|
{
|
|
|
|
return RMATCH(match)->regexp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.names => [name1, name2, ...]
|
|
|
|
*
|
|
|
|
* Returns a list of names of captures as an array of strings.
|
|
|
|
* It is same as mtch.regexp.names.
|
|
|
|
*
|
|
|
|
* /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").names
|
|
|
|
* #=> ["foo", "bar", "baz"]
|
|
|
|
*
|
|
|
|
* m = /(?<x>.)(?<y>.)?/.match("a") #=> #<MatchData "a" x:"a" y:nil>
|
|
|
|
* m.names #=> ["x", "y"]
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
match_names(VALUE match)
|
|
|
|
{
|
|
|
|
return rb_reg_names(RMATCH(match)->regexp);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.length => integer
|
|
|
|
* mtch.size => integer
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the number of elements in the match array.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.length #=> 5
|
|
|
|
* m.size #=> 5
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_size(VALUE match)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
|
|
|
return INT2FIX(RMATCH(match)->regs->num_regs);
|
|
|
|
}
|
|
|
|
|
2007-11-22 21:10:44 -05:00
|
|
|
static VALUE
|
|
|
|
match_sublen(VALUE str, int offset)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = rb_str_sublen(str, offset);
|
|
|
|
return INT2FIX(i);
|
|
|
|
}
|
|
|
|
|
2007-12-09 02:12:44 -05:00
|
|
|
static int
|
|
|
|
match_backref_number(VALUE match, VALUE backref)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
int num;
|
|
|
|
|
|
|
|
struct re_registers *regs = RMATCH(match)->regs;
|
|
|
|
VALUE regexp = RMATCH(match)->regexp;
|
|
|
|
|
|
|
|
switch(TYPE(backref)) {
|
|
|
|
default:
|
|
|
|
return NUM2INT(backref);
|
|
|
|
|
|
|
|
case T_SYMBOL:
|
|
|
|
name = rb_id2name(SYM2ID(backref));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STRING:
|
|
|
|
name = StringValueCStr(backref);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
num = onig_name_to_backref_number(RREGEXP(regexp)->ptr,
|
|
|
|
(const unsigned char*)name,
|
|
|
|
(const unsigned char*)name + strlen(name),
|
|
|
|
regs);
|
|
|
|
|
|
|
|
if (num < 1) {
|
|
|
|
rb_raise(rb_eIndexError, "undefined group name reference: %s", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.offset(n) => array
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns a two-element array containing the beginning and ending offsets of
|
|
|
|
* the <em>n</em>th match.
|
2007-12-09 08:35:38 -05:00
|
|
|
* <em>n</em> can be a string or symbol to reference a named capture.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
2007-12-09 08:35:38 -05:00
|
|
|
* m.offset(0) #=> [1, 7]
|
|
|
|
* m.offset(4) #=> [6, 7]
|
2007-12-09 02:35:54 -05:00
|
|
|
*
|
|
|
|
* m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
|
|
|
|
* p m.offset(:foo) #=> [0, 1]
|
|
|
|
* p m.offset(:bar) #=> [2, 3]
|
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_offset(VALUE match, VALUE n)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2007-12-09 02:12:44 -05:00
|
|
|
int i = match_backref_number(match, n);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
|
|
|
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
|
|
|
|
rb_raise(rb_eIndexError, "index %d out of matches", i);
|
|
|
|
|
|
|
|
if (RMATCH(match)->regs->beg[i] < 0)
|
|
|
|
return rb_assoc_new(Qnil, Qnil);
|
|
|
|
|
2007-11-22 21:10:44 -05:00
|
|
|
return rb_assoc_new(match_sublen(RMATCH(match)->str, RMATCH(match)->regs->beg[i]),
|
|
|
|
match_sublen(RMATCH(match)->str, RMATCH(match)->regs->end[i]));
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.begin(n) => integer
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the offset of the start of the <em>n</em>th element of the match
|
|
|
|
* array in the string.
|
2007-12-09 08:35:38 -05:00
|
|
|
* <em>n</em> can be a string or symbol to reference a named capture.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
2007-12-09 08:35:38 -05:00
|
|
|
* m.begin(0) #=> 1
|
|
|
|
* m.begin(2) #=> 2
|
2007-12-09 02:35:54 -05:00
|
|
|
*
|
|
|
|
* m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
|
|
|
|
* p m.begin(:foo) #=> 0
|
|
|
|
* p m.begin(:bar) #=> 2
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_begin(VALUE match, VALUE n)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2007-12-09 02:12:44 -05:00
|
|
|
int i = match_backref_number(match, n);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
|
|
|
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
|
|
|
|
rb_raise(rb_eIndexError, "index %d out of matches", i);
|
|
|
|
|
|
|
|
if (RMATCH(match)->regs->beg[i] < 0)
|
|
|
|
return Qnil;
|
|
|
|
|
2007-11-22 21:10:44 -05:00
|
|
|
return match_sublen(RMATCH(match)->str, RMATCH(match)->regs->beg[i]);
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.end(n) => integer
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the offset of the character immediately following the end of the
|
|
|
|
* <em>n</em>th element of the match array in the string.
|
2007-12-09 08:35:38 -05:00
|
|
|
* <em>n</em> can be a string or symbol to reference a named capture.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
2007-12-09 08:35:38 -05:00
|
|
|
* m.end(0) #=> 7
|
|
|
|
* m.end(2) #=> 3
|
2007-12-09 02:35:54 -05:00
|
|
|
*
|
|
|
|
* m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
|
|
|
|
* p m.end(:foo) #=> 1
|
|
|
|
* p m.end(:bar) #=> 3
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_end(VALUE match, VALUE n)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2007-12-09 02:12:44 -05:00
|
|
|
int i = match_backref_number(match, n);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
|
|
|
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
|
|
|
|
rb_raise(rb_eIndexError, "index %d out of matches", i);
|
|
|
|
|
|
|
|
if (RMATCH(match)->regs->beg[i] < 0)
|
|
|
|
return Qnil;
|
|
|
|
|
2007-11-22 21:10:44 -05:00
|
|
|
return match_sublen(RMATCH(match)->str, RMATCH(match)->regs->end[i]);
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MATCH_BUSY FL_USER2
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_match_busy(VALUE match)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2000-02-08 03:54:01 -05:00
|
|
|
FL_SET(match, MATCH_BUSY);
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
2007-12-09 06:57:06 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.fixed_encoding? => true or false
|
|
|
|
*
|
2007-12-09 08:35:38 -05:00
|
|
|
* Returns false if rxp is applicable to
|
|
|
|
* a string with any ASCII compatible encoding.
|
|
|
|
* Returns true otherwise.
|
2007-12-09 06:57:06 -05:00
|
|
|
*
|
|
|
|
* r = /a/
|
|
|
|
* r.fixed_encoding? #=> false
|
|
|
|
* r =~ "\u{6666} a" #=> 2
|
|
|
|
* r =~ "\xa1\xa2 a".force_encoding("euc-jp") #=> 2
|
2007-12-09 08:35:38 -05:00
|
|
|
* r =~ "abc".force_encoding("euc-jp") #=> 0
|
2007-12-09 06:57:06 -05:00
|
|
|
*
|
|
|
|
* r = /a/u
|
|
|
|
* r.fixed_encoding? #=> true
|
|
|
|
* r.encoding #=> <Encoding:UTF-8>
|
|
|
|
* r =~ "\u{6666} a" #=> 2
|
|
|
|
* r =~ "\xa1\xa2".force_encoding("euc-jp") # ArgumentError
|
2007-12-09 08:35:38 -05:00
|
|
|
* r =~ "abc".force_encoding("euc-jp") #=> 0
|
2007-12-09 06:57:06 -05:00
|
|
|
*
|
|
|
|
* r = /\u{6666}/
|
|
|
|
* r.fixed_encoding? #=> true
|
|
|
|
* r.encoding #=> <Encoding:UTF-8>
|
|
|
|
* r =~ "\u{6666} a" #=> 0
|
|
|
|
* r =~ "\xa1\xa2".force_encoding("euc-jp") # ArgumentError
|
2007-12-09 08:35:38 -05:00
|
|
|
* r =~ "abc".force_encoding("euc-jp") #=> nil
|
2007-12-09 06:57:06 -05:00
|
|
|
*/
|
|
|
|
|
2007-11-25 21:27:59 -05:00
|
|
|
static VALUE
|
|
|
|
rb_reg_fixed_encoding_p(VALUE re)
|
|
|
|
{
|
|
|
|
if (ENCODING_GET(re) != 0 || FL_TEST(re, KCODE_FIXED))
|
|
|
|
return Qtrue;
|
|
|
|
else
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
2007-12-01 11:56:19 -05:00
|
|
|
static VALUE
|
|
|
|
rb_reg_preprocess(const char *p, const char *end, rb_encoding *enc,
|
|
|
|
rb_encoding **fixed_enc, onig_errmsg_buffer err);
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static void
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_reg_prepare_re(VALUE re, VALUE str)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int need_recompile = 0;
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_encoding *enc;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
2000-06-13 05:42:40 -04:00
|
|
|
/* ignorecase status */
|
2007-11-25 21:27:59 -05:00
|
|
|
if (rb_reg_fixed_encoding_p(re)) {
|
2007-11-23 01:30:26 -05:00
|
|
|
if (ENCODING_GET(re) != rb_enc_get_index(str) &&
|
2007-11-26 21:21:17 -05:00
|
|
|
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
|
2007-11-23 01:30:26 -05:00
|
|
|
rb_raise(rb_eArgError, "character encodings differ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((enc = rb_enc_get(str)) != 0 &&
|
|
|
|
RREGEXP(re)->ptr->enc != enc) {
|
1998-01-16 07:13:05 -05:00
|
|
|
need_recompile = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_recompile) {
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
onig_errmsg_buffer err;
|
2004-03-05 10:40:36 -05:00
|
|
|
int r;
|
2005-02-17 09:43:38 -05:00
|
|
|
OnigErrorInfo einfo;
|
2006-05-15 08:39:25 -04:00
|
|
|
regex_t *reg, *reg2;
|
2005-02-17 09:43:38 -05:00
|
|
|
UChar *pattern;
|
2007-12-01 11:56:19 -05:00
|
|
|
VALUE unescaped;
|
|
|
|
rb_encoding *fixed_enc = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
2005-02-17 09:43:38 -05:00
|
|
|
reg = RREGEXP(re)->ptr;
|
2005-05-22 23:24:28 -04:00
|
|
|
pattern = ((UChar*)RREGEXP(re)->str);
|
2005-02-17 09:43:38 -05:00
|
|
|
|
2007-12-01 11:56:19 -05:00
|
|
|
unescaped = rb_reg_preprocess(
|
|
|
|
RREGEXP(re)->str, RREGEXP(re)->str + RREGEXP(re)->len, enc,
|
|
|
|
&fixed_enc, err);
|
|
|
|
|
|
|
|
r = onig_new(®2, (UChar* )RSTRING_PTR(unescaped),
|
|
|
|
(UChar* )(RSTRING_PTR(unescaped) + RSTRING_LEN(unescaped)),
|
2007-10-16 01:48:40 -04:00
|
|
|
reg->options, enc,
|
2006-05-15 08:39:25 -04:00
|
|
|
OnigDefaultSyntax, &einfo);
|
|
|
|
if (r) {
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
onig_error_code_to_str((UChar*)err, r, &einfo);
|
|
|
|
rb_reg_raise((char* )pattern, RREGEXP(re)->len, err, re);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2006-05-15 08:39:25 -04:00
|
|
|
|
|
|
|
RREGEXP(re)->ptr = reg2;
|
|
|
|
onig_free(reg);
|
2007-12-01 11:56:19 -05:00
|
|
|
RB_GC_GUARD(unescaped);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-11-22 21:10:44 -05:00
|
|
|
int
|
|
|
|
rb_reg_adjust_startpos(VALUE re, VALUE str, int pos, int reverse)
|
1999-12-14 01:50:43 -05:00
|
|
|
{
|
2007-11-22 21:10:44 -05:00
|
|
|
int range;
|
2005-02-17 09:43:38 -05:00
|
|
|
OnigEncoding enc;
|
|
|
|
UChar *p, *string;
|
1999-12-14 01:50:43 -05:00
|
|
|
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_reg_prepare_re(re, str);
|
1999-12-14 01:50:43 -05:00
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
range = -pos;
|
|
|
|
}
|
|
|
|
else {
|
2006-08-31 06:47:44 -04:00
|
|
|
range = RSTRING_LEN(str) - pos;
|
1999-12-14 01:50:43 -05:00
|
|
|
}
|
2005-02-17 09:43:38 -05:00
|
|
|
|
|
|
|
enc = (RREGEXP(re)->ptr)->enc;
|
|
|
|
|
2006-08-31 06:47:44 -04:00
|
|
|
if (pos > 0 && ONIGENC_MBC_MAXLEN(enc) != 1 && pos < RSTRING_LEN(str)) {
|
|
|
|
string = (UChar*)RSTRING_PTR(str);
|
2005-02-17 09:43:38 -05:00
|
|
|
|
|
|
|
if (range > 0) {
|
|
|
|
p = onigenc_get_right_adjust_char_head(enc, string, string + pos);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, string, string + pos);
|
|
|
|
}
|
|
|
|
return p - string;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
1999-12-14 01:50:43 -05:00
|
|
|
}
|
|
|
|
|
2007-11-22 21:10:44 -05:00
|
|
|
int
|
|
|
|
rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
2007-11-22 21:10:44 -05:00
|
|
|
int result;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE match;
|
2000-02-08 03:54:01 -05:00
|
|
|
static struct re_registers regs;
|
2007-11-22 21:10:44 -05:00
|
|
|
int range;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2006-08-31 06:47:44 -04:00
|
|
|
if (pos > RSTRING_LEN(str) || pos < 0) {
|
2002-03-19 04:03:11 -05:00
|
|
|
rb_backref_set(Qnil);
|
|
|
|
return -1;
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_reg_prepare_re(re, str);
|
1998-01-16 07:19:22 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (reverse) {
|
1999-08-13 01:45:20 -04:00
|
|
|
range = -pos;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
else {
|
2006-08-31 06:47:44 -04:00
|
|
|
range = RSTRING_LEN(str) - pos;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2005-02-17 09:43:38 -05:00
|
|
|
|
|
|
|
result = onig_search(RREGEXP(re)->ptr,
|
2006-08-31 06:47:44 -04:00
|
|
|
(UChar*)(RSTRING_PTR(str)),
|
|
|
|
((UChar*)(RSTRING_PTR(str)) + RSTRING_LEN(str)),
|
|
|
|
((UChar*)(RSTRING_PTR(str)) + pos),
|
|
|
|
((UChar*)(RSTRING_PTR(str)) + pos + range),
|
2005-02-17 09:43:38 -05:00
|
|
|
®s, ONIG_OPTION_NONE);
|
1999-11-04 03:39:57 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
if (result < 0) {
|
2004-09-24 01:53:43 -04:00
|
|
|
if (result == ONIG_MISMATCH) {
|
|
|
|
rb_backref_set(Qnil);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else {
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
onig_errmsg_buffer err;
|
2005-05-22 23:24:28 -04:00
|
|
|
onig_error_code_to_str((UChar*)err, result);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len, err, 0);
|
2004-09-24 01:53:43 -04:00
|
|
|
}
|
2000-02-08 03:54:01 -05:00
|
|
|
}
|
|
|
|
|
2001-09-20 02:23:50 -04:00
|
|
|
match = rb_backref_get();
|
2000-02-08 03:54:01 -05:00
|
|
|
if (NIL_P(match) || FL_TEST(match, MATCH_BUSY)) {
|
2002-09-02 10:04:19 -04:00
|
|
|
match = match_alloc(rb_cMatch);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2002-01-04 09:15:33 -05:00
|
|
|
else {
|
2004-03-05 17:37:35 -05:00
|
|
|
if (rb_safe_level() >= 3)
|
2002-01-04 09:15:33 -05:00
|
|
|
OBJ_TAINT(match);
|
|
|
|
else
|
|
|
|
FL_UNSET(match, FL_TAINT);
|
|
|
|
}
|
|
|
|
|
2005-02-17 09:43:38 -05:00
|
|
|
onig_region_copy(RMATCH(match)->regs, ®s);
|
2000-02-08 03:54:01 -05:00
|
|
|
RMATCH(match)->str = rb_str_new4(str);
|
2006-03-21 08:16:21 -05:00
|
|
|
RMATCH(match)->regexp = re;
|
2000-02-08 03:54:01 -05:00
|
|
|
rb_backref_set(match);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
OBJ_INFECT(match, re);
|
2000-01-04 23:41:21 -05:00
|
|
|
OBJ_INFECT(match, str);
|
2007-11-22 21:10:44 -05:00
|
|
|
|
2007-12-09 23:50:35 -05:00
|
|
|
return result;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_nth_defined(int nth, VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (nth >= RMATCH(match)->regs->num_regs) {
|
2001-10-03 03:19:19 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
if (nth < 0) {
|
|
|
|
nth += RMATCH(match)->regs->num_regs;
|
|
|
|
if (nth <= 0) return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RMATCH(match)->BEG(nth) == -1) return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_nth_match(int nth, VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-01-04 23:41:21 -05:00
|
|
|
VALUE str;
|
2002-08-28 04:05:23 -04:00
|
|
|
long start, end, len;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (nth >= RMATCH(match)->regs->num_regs) {
|
1998-01-16 07:13:05 -05:00
|
|
|
return Qnil;
|
|
|
|
}
|
2001-10-03 03:19:19 -04:00
|
|
|
if (nth < 0) {
|
|
|
|
nth += RMATCH(match)->regs->num_regs;
|
|
|
|
if (nth <= 0) return Qnil;
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
start = RMATCH(match)->BEG(nth);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (start == -1) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
end = RMATCH(match)->END(nth);
|
1998-01-16 07:13:05 -05:00
|
|
|
len = end - start;
|
2007-08-28 02:45:32 -04:00
|
|
|
str = rb_str_subseq(RMATCH(match)->str, start, len);
|
2002-12-17 07:15:45 -05:00
|
|
|
OBJ_INFECT(str, match);
|
2000-01-04 23:41:21 -05:00
|
|
|
return str;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_last_match(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_nth_match(0, match);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.pre_match => str
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the portion of the original string before the current match.
|
|
|
|
* Equivalent to the special variable <code>$`</code>.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.pre_match #=> "T"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match_pre(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-10-02 00:31:23 -04:00
|
|
|
VALUE str;
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RMATCH(match)->BEG(0) == -1) return Qnil;
|
2007-08-28 02:45:32 -04:00
|
|
|
str = rb_str_subseq(RMATCH(match)->str, 0, RMATCH(match)->BEG(0));
|
2001-10-02 00:31:23 -04:00
|
|
|
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
|
|
|
|
return str;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.post_match => str
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the portion of the original string after the current match.
|
|
|
|
* Equivalent to the special variable <code>$'</code>.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
|
|
|
|
* m.post_match #=> ": The Movie"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match_post(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-10-02 00:31:23 -04:00
|
|
|
VALUE str;
|
2002-12-19 10:21:01 -05:00
|
|
|
long pos;
|
2001-10-02 00:31:23 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RMATCH(match)->BEG(0) == -1) return Qnil;
|
2002-12-19 10:21:01 -05:00
|
|
|
str = RMATCH(match)->str;
|
|
|
|
pos = RMATCH(match)->END(0);
|
2007-08-28 02:45:32 -04:00
|
|
|
str = rb_str_subseq(str, pos, RSTRING_LEN(str) - pos);
|
2001-10-02 00:31:23 -04:00
|
|
|
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
|
|
|
|
return str;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match_last(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (NIL_P(match)) return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RMATCH(match)->BEG(0) == -1) return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
for (i=RMATCH(match)->regs->num_regs-1; RMATCH(match)->BEG(i) == -1 && i > 0; i--)
|
1998-01-16 07:13:05 -05:00
|
|
|
;
|
|
|
|
if (i == 0) return Qnil;
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_nth_match(i, match);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
last_match_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_last_match(rb_backref_get());
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
prematch_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_match_pre(rb_backref_get());
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
postmatch_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_match_post(rb_backref_get());
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
last_paren_match_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_reg_match_last(rb_backref_get());
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_array(VALUE match, int start)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
struct re_registers *regs = RMATCH(match)->regs;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE ary = rb_ary_new2(regs->num_regs);
|
2002-12-19 10:21:01 -05:00
|
|
|
VALUE target = RMATCH(match)->str;
|
1998-01-16 07:13:05 -05:00
|
|
|
int i;
|
2001-12-21 04:23:28 -05:00
|
|
|
int taint = OBJ_TAINTED(match);
|
2004-03-05 17:37:35 -05:00
|
|
|
|
2003-07-03 07:02:53 -04:00
|
|
|
for (i=start; i<regs->num_regs; i++) {
|
2001-12-21 04:23:28 -05:00
|
|
|
if (regs->beg[i] == -1) {
|
|
|
|
rb_ary_push(ary, Qnil);
|
2002-05-01 05:41:50 -04:00
|
|
|
}
|
|
|
|
else {
|
2007-08-28 02:45:32 -04:00
|
|
|
VALUE str = rb_str_subseq(target, regs->beg[i], regs->end[i]-regs->beg[i]);
|
2001-12-21 04:23:28 -05:00
|
|
|
if (taint) OBJ_TAINT(str);
|
|
|
|
rb_ary_push(ary, str);
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/* [MG]:FIXME: I put parens around the /.../.match() in the first line of the
|
|
|
|
second example to prevent the '*' followed by a '/' from ending the
|
|
|
|
comment. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.to_a => anArray
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the array of matches.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.to_a #=> ["HX1138", "H", "X", "113", "8"]
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
* array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-14 00:06:52 -04:00
|
|
|
* Because <code>to_a</code> is called when expanding
|
2003-12-26 10:58:28 -05:00
|
|
|
* <code>*</code><em>variable</em>, there's a useful assignment
|
|
|
|
* shortcut for extracting matched fields. This is slightly slower than
|
|
|
|
* accessing the fields directly (as an intermediate array is
|
|
|
|
* generated).
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* all,f1,f2,f3 = *(/(.)(.)(\d+)(\d)/.match("THX1138."))
|
|
|
|
* all #=> "HX1138"
|
|
|
|
* f1 #=> "H"
|
|
|
|
* f2 #=> "X"
|
|
|
|
* f3 #=> "113"
|
|
|
|
*/
|
|
|
|
|
2003-07-03 07:02:53 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_to_a(VALUE match)
|
2003-07-03 07:02:53 -04:00
|
|
|
{
|
|
|
|
return match_array(match, 0);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.captures => array
|
|
|
|
*
|
|
|
|
* Returns the array of captures; equivalent to <code>mtch.to_a[1..-1]</code>.
|
|
|
|
*
|
|
|
|
* f1,f2,f3,f4 = /(.)(.)(\d+)(\d)/.match("THX1138.").captures
|
|
|
|
* f1 #=> "H"
|
|
|
|
* f2 #=> "X"
|
|
|
|
* f3 #=> "113"
|
|
|
|
* f4 #=> "8"
|
|
|
|
*/
|
2003-07-03 07:02:53 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_captures(VALUE match)
|
2003-07-03 07:02:53 -04:00
|
|
|
{
|
|
|
|
return match_array(match, 1);
|
|
|
|
}
|
|
|
|
|
2006-03-22 10:03:40 -05:00
|
|
|
static int
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
|
2006-03-22 10:03:40 -05:00
|
|
|
{
|
|
|
|
int num;
|
|
|
|
|
|
|
|
num = onig_name_to_backref_number(RREGEXP(regexp)->ptr,
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
(const unsigned char* )name, (const unsigned char* )name_end, regs);
|
2006-03-22 10:03:40 -05:00
|
|
|
if (num >= 1) {
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE s = rb_str_new(name, (long )(name_end - name));
|
2007-12-09 02:12:44 -05:00
|
|
|
rb_raise(rb_eIndexError, "undefined group name reference: %s",
|
|
|
|
StringValuePtr(s));
|
2006-03-22 10:03:40 -05:00
|
|
|
}
|
|
|
|
}
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-03-24 07:14:18 -05:00
|
|
|
* mtch[i] => str or nil
|
2003-12-26 10:58:28 -05:00
|
|
|
* mtch[start, length] => array
|
|
|
|
* mtch[range] => array
|
2006-03-24 07:14:18 -05:00
|
|
|
* mtch[name] => str or nil
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Match Reference---<code>MatchData</code> acts as an array, and may be
|
|
|
|
* accessed using the normal array indexing techniques. <i>mtch</i>[0] is
|
|
|
|
* equivalent to the special variable <code>$&</code>, and returns the entire
|
|
|
|
* matched string. <i>mtch</i>[1], <i>mtch</i>[2], and so on return the values
|
|
|
|
* of the matched backreferences (portions of the pattern between parentheses).
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
2007-12-09 08:35:38 -05:00
|
|
|
* m #=> #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
2003-12-26 10:58:28 -05:00
|
|
|
* m[0] #=> "HX1138"
|
|
|
|
* m[1, 2] #=> ["H", "X"]
|
|
|
|
* m[1..3] #=> ["H", "X", "113"]
|
|
|
|
* m[-3, 2] #=> ["X", "113"]
|
2006-03-24 07:14:18 -05:00
|
|
|
*
|
|
|
|
* m = /(?<foo>a+)b/.match("ccaaab")
|
2007-12-09 08:35:38 -05:00
|
|
|
* m #=> #<MatchData "aaab" foo:"aaa">
|
2006-03-24 07:14:18 -05:00
|
|
|
* m["foo"] #=> "aaa"
|
|
|
|
* m[:foo] #=> "aaa"
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_aref(int argc, VALUE *argv, VALUE match)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
|
|
|
VALUE idx, rest;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &idx, &rest);
|
|
|
|
|
2006-03-21 08:16:21 -05:00
|
|
|
if (NIL_P(rest)) {
|
|
|
|
if (FIXNUM_P(idx)) {
|
|
|
|
if (FIX2INT(idx) >= 0) {
|
|
|
|
return rb_reg_nth_match(FIX2INT(idx), match);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
const char *p;
|
2006-03-21 08:16:21 -05:00
|
|
|
int num;
|
|
|
|
|
|
|
|
switch (TYPE(idx)) {
|
|
|
|
case T_SYMBOL:
|
|
|
|
p = rb_id2name(SYM2ID(idx));
|
|
|
|
goto name_to_backref;
|
|
|
|
break;
|
|
|
|
case T_STRING:
|
|
|
|
p = StringValuePtr(idx);
|
|
|
|
|
|
|
|
name_to_backref:
|
2006-03-22 10:03:40 -05:00
|
|
|
num = name_to_backref_number(RMATCH(match)->regs,
|
|
|
|
RMATCH(match)->regexp, p, p + strlen(p));
|
|
|
|
return rb_reg_nth_match(num, match);
|
2006-03-21 08:16:21 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
2006-03-21 08:16:21 -05:00
|
|
|
|
|
|
|
return rb_ary_aref(argc, argv, match_to_a(match));
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-07-03 07:02:53 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_entry(VALUE match, long n)
|
2003-07-03 07:02:53 -04:00
|
|
|
{
|
|
|
|
return rb_reg_nth_match(n, match);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2007-10-12 10:35:26 -04:00
|
|
|
*
|
|
|
|
* mtch.values_at([index]*) => array
|
2003-12-26 10:58:28 -05:00
|
|
|
* mtch.select([index]*) => array
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Uses each <i>index</i> to access the matching values, returning an array of
|
|
|
|
* the corresponding matches.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
|
|
|
|
* m.to_a #=> ["HX1138", "H", "X", "113", "8"]
|
2007-10-12 10:35:26 -04:00
|
|
|
* m.values_at(0, 2, -2) #=> ["HX1138", "X", "113"]
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
2001-12-10 22:48:08 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_values_at(int argc, VALUE *argv, VALUE match)
|
2001-12-10 22:48:08 -05:00
|
|
|
{
|
2004-04-06 22:51:05 -04:00
|
|
|
return rb_get_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry);
|
2001-12-10 22:48:08 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.to_s => str
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns the entire matched string.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.to_s #=> "HX1138"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_to_s(VALUE match)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE str = rb_reg_last_match(match);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-12-01 04:24:48 -05:00
|
|
|
if (NIL_P(str)) str = rb_str_new(0,0);
|
|
|
|
if (OBJ_TAINTED(match)) OBJ_TAINT(str);
|
2000-01-04 23:41:21 -05:00
|
|
|
if (OBJ_TAINTED(RMATCH(match)->str)) OBJ_TAINT(str);
|
1998-01-16 07:13:05 -05:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.string => str
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns a frozen copy of the string passed in to <code>match</code>.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
|
|
* m.string #=> "THX1138."
|
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_string(VALUE match)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
1999-10-15 04:52:18 -04:00
|
|
|
return RMATCH(match)->str; /* str is frozen */
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
2007-12-09 02:12:44 -05:00
|
|
|
struct backref_name_tag {
|
|
|
|
const UChar *name;
|
|
|
|
long len;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
match_inspect_name_iter(const OnigUChar *name, const OnigUChar *name_end,
|
|
|
|
int back_num, int *back_refs, OnigRegex regex, void *arg0)
|
|
|
|
{
|
|
|
|
struct backref_name_tag *arg = (struct backref_name_tag *)arg0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < back_num; i++) {
|
|
|
|
arg[back_refs[i]].name = name;
|
|
|
|
arg[back_refs[i]].len = name_end - name;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-02 09:42:05 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mtch.inspect => str
|
|
|
|
*
|
|
|
|
* Returns a printable version of <i>mtch</i>.
|
|
|
|
*
|
2007-12-09 02:35:54 -05:00
|
|
|
* puts /.$/.match("foo").inspect
|
2007-12-02 09:42:05 -05:00
|
|
|
* #=> #<MatchData "o">
|
|
|
|
*
|
2007-12-09 02:35:54 -05:00
|
|
|
* puts /(.)(.)(.)/.match("foo").inspect
|
|
|
|
* #=> #<MatchData "foo" 1:"f" 2:"o" 3:"o">
|
|
|
|
*
|
2007-12-09 08:35:38 -05:00
|
|
|
* puts /(.)(.)?(.)/.match("fo").inspect
|
|
|
|
* #=> #<MatchData "fo" 1:"f" 2:nil 3:"o">
|
|
|
|
*
|
2007-12-09 02:35:54 -05:00
|
|
|
* puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect
|
|
|
|
* #=> #<MatchData "hog" foo:"h" bar:"o" baz:"g">
|
|
|
|
*
|
2007-12-02 09:42:05 -05:00
|
|
|
*/
|
|
|
|
|
2007-06-23 04:26:08 -04:00
|
|
|
static VALUE
|
|
|
|
match_inspect(VALUE match)
|
|
|
|
{
|
|
|
|
char *cname = rb_obj_classname(match);
|
|
|
|
VALUE str;
|
|
|
|
int i;
|
2007-12-09 02:12:44 -05:00
|
|
|
int num_regs = RMATCH(match)->regs->num_regs;
|
|
|
|
struct backref_name_tag *names;
|
2007-12-09 16:44:19 -05:00
|
|
|
VALUE regexp = RMATCH(match)->regexp;
|
2007-12-09 02:12:44 -05:00
|
|
|
|
|
|
|
names = ALLOCA_N(struct backref_name_tag, num_regs);
|
|
|
|
MEMZERO(names, struct backref_name_tag, num_regs);
|
|
|
|
|
2007-12-09 16:44:19 -05:00
|
|
|
onig_foreach_name(RREGEXP(regexp)->ptr,
|
2007-12-09 02:12:44 -05:00
|
|
|
match_inspect_name_iter, names);
|
2007-06-23 04:26:08 -04:00
|
|
|
|
|
|
|
str = rb_str_buf_new2("#<");
|
|
|
|
rb_str_buf_cat2(str, cname);
|
|
|
|
|
2007-12-09 02:12:44 -05:00
|
|
|
for (i = 0; i < num_regs; i++) {
|
2007-06-23 04:26:08 -04:00
|
|
|
VALUE v;
|
|
|
|
rb_str_buf_cat2(str, " ");
|
2007-12-09 02:12:44 -05:00
|
|
|
if (0 < i) {
|
|
|
|
if (names[i].name)
|
|
|
|
rb_str_buf_cat(str, (const char *)names[i].name, names[i].len);
|
|
|
|
else {
|
|
|
|
char buf[sizeof(i)*3+1];
|
|
|
|
snprintf(buf, sizeof(buf), "%d", i);
|
|
|
|
rb_str_buf_cat2(str, buf);
|
|
|
|
}
|
|
|
|
rb_str_buf_cat2(str, ":");
|
|
|
|
}
|
2007-06-23 04:26:08 -04:00
|
|
|
v = rb_reg_nth_match(i, match);
|
|
|
|
if (v == Qnil)
|
|
|
|
rb_str_buf_cat2(str, "nil");
|
|
|
|
else
|
|
|
|
rb_str_buf_append(str, rb_str_inspect(v));
|
|
|
|
}
|
|
|
|
rb_str_buf_cat2(str, ">");
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_cRegexp;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-12-01 11:56:19 -05:00
|
|
|
static int
|
|
|
|
read_escaped_byte(const char **pp, const char *end, onig_errmsg_buffer err)
|
|
|
|
{
|
|
|
|
const char *p = *pp;
|
|
|
|
int code;
|
|
|
|
int meta_prefix = 0, ctrl_prefix = 0;
|
|
|
|
int len;
|
|
|
|
int retbyte;
|
|
|
|
|
|
|
|
retbyte = -1;
|
|
|
|
if (p == end || *p++ != '\\') {
|
|
|
|
strcpy(err, "too short escaped multibyte character");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
again:
|
|
|
|
if (p == end) {
|
|
|
|
strcpy(err, "too short escape sequence");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch (*p++) {
|
|
|
|
case '\\': code = '\\'; break;
|
|
|
|
case 'n': code = '\n'; break;
|
|
|
|
case 't': code = '\t'; break;
|
|
|
|
case 'r': code = '\r'; break;
|
|
|
|
case 'f': code = '\f'; break;
|
|
|
|
case 'v': code = '\013'; break;
|
|
|
|
case 'a': code = '\007'; break;
|
|
|
|
case 'e': code = '\033'; break;
|
|
|
|
|
|
|
|
/* \OOO */
|
|
|
|
case '0': case '1': case '2': case '3':
|
|
|
|
case '4': case '5': case '6': case '7':
|
|
|
|
p--;
|
|
|
|
code = ruby_scan_oct(p, end < p+3 ? end-p : 3, &len);
|
|
|
|
p += len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x': /* \xHH */
|
|
|
|
code = ruby_scan_hex(p, end < p+2 ? end-p : 2, &len);
|
|
|
|
if (len < 1) {
|
|
|
|
strcpy(err, "invalid hex escape");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
p += len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M': /* \M-X, \M-\C-X, \M-\cX */
|
|
|
|
if (meta_prefix) {
|
|
|
|
strcpy(err, "duplicate meta escape");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
meta_prefix = 1;
|
|
|
|
if (p+1 < end && *p++ == '-' && (*p & 0x80) == 0) {
|
|
|
|
if (*p == '\\') {
|
|
|
|
p++;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
code = *p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strcpy(err, "too short meta escape");
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case 'C': /* \C-X, \C-\M-X */
|
|
|
|
if (p == end || *p++ != '-') {
|
|
|
|
strcpy(err, "too short control escape");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
case 'c': /* \cX, \c\M-X */
|
|
|
|
if (ctrl_prefix) {
|
|
|
|
strcpy(err, "duplicate control escape");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ctrl_prefix = 1;
|
|
|
|
if (p < end && (*p & 0x80) == 0) {
|
|
|
|
if (*p == '\\') {
|
|
|
|
p++;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
code = *p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strcpy(err, "too short control escape");
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
strcpy(err, "unexpected escape sequence");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (code < 0 || 0xff < code) {
|
|
|
|
strcpy(err, "invalid escape code");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctrl_prefix)
|
|
|
|
code &= 0x1f;
|
|
|
|
if (meta_prefix)
|
|
|
|
code |= 0x80;
|
|
|
|
|
|
|
|
*pp = p;
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unescape_escaped_nonascii(const char **pp, const char *end, rb_encoding *enc,
|
|
|
|
VALUE buf, rb_encoding **encp, onig_errmsg_buffer err)
|
|
|
|
{
|
|
|
|
const char *p = *pp;
|
|
|
|
int chmaxlen = rb_enc_mbmaxlen(enc);
|
|
|
|
char *chbuf = ALLOCA_N(char, chmaxlen);
|
|
|
|
int chlen = 0;
|
|
|
|
int byte;
|
2007-12-07 21:50:43 -05:00
|
|
|
int l;
|
2007-12-01 11:56:19 -05:00
|
|
|
|
|
|
|
memset(chbuf, 0, chmaxlen);
|
|
|
|
|
|
|
|
byte = read_escaped_byte(&p, end, err);
|
|
|
|
if (byte == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
chbuf[chlen++] = byte;
|
2007-12-07 21:50:43 -05:00
|
|
|
while (chlen < chmaxlen &&
|
|
|
|
MBCLEN_NEEDMORE(rb_enc_precise_mbclen(chbuf, chbuf+chlen, enc))) {
|
2007-12-01 11:56:19 -05:00
|
|
|
byte = read_escaped_byte(&p, end, err);
|
|
|
|
if (byte == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
chbuf[chlen++] = byte;
|
|
|
|
}
|
|
|
|
|
2007-12-07 21:50:43 -05:00
|
|
|
l = rb_enc_precise_mbclen(chbuf, chbuf+chlen, enc);
|
|
|
|
if (MBCLEN_INVALID(l)) {
|
2007-12-01 11:56:19 -05:00
|
|
|
strcpy(err, "invalid multibyte escape");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (1 < chlen || (chbuf[0] & 0x80)) {
|
|
|
|
rb_str_buf_cat(buf, chbuf, chlen);
|
|
|
|
|
|
|
|
if (*encp == 0)
|
|
|
|
*encp = enc;
|
|
|
|
else if (*encp != enc) {
|
|
|
|
strcpy(err, "character encodings differ");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char escbuf[5];
|
|
|
|
snprintf(escbuf, sizeof(escbuf), "\\x%02x", chbuf[0]&0xff);
|
|
|
|
rb_str_buf_cat(buf, escbuf, 4);
|
|
|
|
}
|
|
|
|
*pp = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-08 22:50:11 -05:00
|
|
|
static int
|
|
|
|
check_unicode_range(unsigned long code, onig_errmsg_buffer err)
|
|
|
|
{
|
|
|
|
if ((0xd800 <= code && code <= 0xdfff) || /* Surrogates */
|
|
|
|
0x10ffff < code) {
|
|
|
|
strcpy(err, "invalid Unicode range");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-01 11:56:19 -05:00
|
|
|
static int
|
|
|
|
append_utf8(unsigned long uv,
|
|
|
|
VALUE buf, rb_encoding **encp, onig_errmsg_buffer err)
|
|
|
|
{
|
2007-12-08 22:50:11 -05:00
|
|
|
if (check_unicode_range(uv, err) != 0)
|
|
|
|
return -1;
|
2007-12-01 11:56:19 -05:00
|
|
|
if (uv < 0x80) {
|
|
|
|
char escbuf[5];
|
|
|
|
snprintf(escbuf, sizeof(escbuf), "\\x%02x", (int)uv);
|
|
|
|
rb_str_buf_cat(buf, escbuf, 4);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int len;
|
|
|
|
char utf8buf[6];
|
|
|
|
len = rb_uv_to_utf8(utf8buf, uv);
|
|
|
|
rb_str_buf_cat(buf, utf8buf, len);
|
|
|
|
|
|
|
|
if (*encp == 0)
|
|
|
|
*encp = rb_enc_find("utf-8");
|
|
|
|
else if (*encp != rb_enc_find("utf-8")) {
|
|
|
|
strcpy(err, "character encodings differ");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unescape_unicode_list(const char **pp, const char *end,
|
|
|
|
VALUE buf, rb_encoding **encp, onig_errmsg_buffer err)
|
|
|
|
{
|
|
|
|
const char *p = *pp;
|
|
|
|
int has_unicode = 0;
|
|
|
|
unsigned long code;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
while (p < end && ISSPACE(*p)) p++;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
code = ruby_scan_hex(p, end-p, &len);
|
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
if (6 < len) { /* max 10FFFF */
|
2007-12-01 21:53:46 -05:00
|
|
|
strcpy(err, "invalid Unicode range");
|
2007-12-01 11:56:19 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
p += len;
|
|
|
|
if (append_utf8(code, buf, encp, err) != 0)
|
|
|
|
return -1;
|
|
|
|
has_unicode = 1;
|
|
|
|
|
|
|
|
while (p < end && ISSPACE(*p)) p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_unicode == 0) {
|
2007-12-01 21:53:46 -05:00
|
|
|
strcpy(err, "invalid Unicode list");
|
2007-12-01 11:56:19 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pp = p;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unescape_unicode_bmp(const char **pp, const char *end,
|
|
|
|
VALUE buf, rb_encoding **encp, onig_errmsg_buffer err)
|
|
|
|
{
|
|
|
|
const char *p = *pp;
|
|
|
|
int len;
|
|
|
|
unsigned long code;
|
|
|
|
|
|
|
|
if (end < p+4) {
|
2007-12-01 21:53:46 -05:00
|
|
|
strcpy(err, "invalid Unicode escape");
|
2007-12-01 11:56:19 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
code = ruby_scan_hex(p, 4, &len);
|
|
|
|
if (len != 4) {
|
2007-12-01 21:53:46 -05:00
|
|
|
strcpy(err, "invalid Unicode escape");
|
2007-12-01 11:56:19 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (append_utf8(code, buf, encp, err) != 0)
|
|
|
|
return -1;
|
|
|
|
*pp = p + 4;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unescape_nonascii(const char *p, const char *end, rb_encoding *enc,
|
|
|
|
VALUE buf, rb_encoding **encp, onig_errmsg_buffer err)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
char smallbuf[2];
|
|
|
|
|
|
|
|
while (p < end) {
|
2007-12-07 21:50:43 -05:00
|
|
|
int chlen = rb_enc_precise_mbclen(p, end, enc);
|
|
|
|
if (!MBCLEN_CHARFOUND(chlen)) {
|
|
|
|
strcpy(err, "invalid multibyte character");
|
|
|
|
return -1;
|
|
|
|
}
|
2007-12-01 11:56:19 -05:00
|
|
|
if (1 < chlen || (*p & 0x80)) {
|
|
|
|
rb_str_buf_cat(buf, p, chlen);
|
|
|
|
p += chlen;
|
|
|
|
if (*encp == 0)
|
|
|
|
*encp = enc;
|
|
|
|
else if (*encp != enc) {
|
|
|
|
strcpy(err, "character encodings differ");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c = *p++) {
|
|
|
|
case '\\':
|
|
|
|
if (p == end) {
|
|
|
|
strcpy(err, "too short escape sequence");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch (c = *p++) {
|
|
|
|
case '1': case '2': case '3':
|
|
|
|
case '4': case '5': case '6': case '7': /* \O, \OO, \OOO or backref */
|
|
|
|
{
|
|
|
|
int octlen;
|
|
|
|
if (ruby_scan_oct(p-1, end-(p-1), &octlen) <= 0177) {
|
|
|
|
/* backref or 7bit octal.
|
|
|
|
no need to unescape anyway.
|
|
|
|
re-escaping may break backref */
|
|
|
|
goto escape_asis;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* xxx: How about more than 199 subexpressions? */
|
|
|
|
|
|
|
|
case '0': /* \0, \0O, \0OO */
|
|
|
|
|
|
|
|
case 'x': /* \xHH */
|
|
|
|
case 'c': /* \cX, \c\M-X */
|
|
|
|
case 'C': /* \C-X, \C-\M-X */
|
|
|
|
case 'M': /* \M-X, \M-\C-X, \M-\cX */
|
|
|
|
p = p-2;
|
|
|
|
if (unescape_escaped_nonascii(&p, end, enc, buf, encp, err) != 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
if (p == end) {
|
|
|
|
strcpy(err, "too short escape sequence");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*p == '{') {
|
|
|
|
/* \u{H HH HHH HHHH HHHHH HHHHHH ...} */
|
|
|
|
p++;
|
|
|
|
if (unescape_unicode_list(&p, end, buf, encp, err) != 0)
|
|
|
|
return -1;
|
|
|
|
if (p == end || *p++ != '}') {
|
2007-12-01 21:53:46 -05:00
|
|
|
strcpy(err, "invalid Unicode list");
|
2007-12-01 11:56:19 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* \uHHHH */
|
|
|
|
if (unescape_unicode_bmp(&p, end, buf, encp, err) != 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: /* \n, \\, \d, \9, etc. */
|
|
|
|
escape_asis:
|
|
|
|
smallbuf[0] = '\\';
|
|
|
|
smallbuf[1] = c;
|
|
|
|
rb_str_buf_cat(buf, smallbuf, 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rb_str_buf_cat(buf, &c, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_reg_preprocess(const char *p, const char *end, rb_encoding *enc,
|
|
|
|
rb_encoding **fixed_enc, onig_errmsg_buffer err)
|
|
|
|
{
|
|
|
|
VALUE buf;
|
|
|
|
|
|
|
|
buf = rb_str_buf_new(0);
|
|
|
|
|
|
|
|
*fixed_enc = 0;
|
|
|
|
if (unescape_nonascii(p, end, enc, buf, fixed_enc, err) != 0)
|
|
|
|
return Qnil;
|
|
|
|
|
|
|
|
if (fixed_enc) {
|
|
|
|
rb_enc_associate(buf, *fixed_enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2007-12-08 02:21:05 -05:00
|
|
|
VALUE
|
|
|
|
rb_reg_check_preprocess(VALUE str)
|
|
|
|
{
|
|
|
|
rb_encoding *fixed_enc = 0;
|
|
|
|
onig_errmsg_buffer err;
|
|
|
|
VALUE buf;
|
|
|
|
char *p, *end;
|
|
|
|
rb_encoding *enc;
|
|
|
|
|
|
|
|
StringValue(str);
|
|
|
|
p = RSTRING_PTR(str);
|
|
|
|
end = p + RSTRING_LEN(str);
|
|
|
|
enc = rb_enc_get(str);
|
|
|
|
|
|
|
|
buf = rb_reg_preprocess(p, end, enc, &fixed_enc, err);
|
|
|
|
RB_GC_GUARD(str);
|
|
|
|
|
|
|
|
if (buf == Qnil) {
|
|
|
|
return rb_reg_error_desc(str, 0, err);
|
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2007-12-01 11:56:19 -05:00
|
|
|
#if 0
|
|
|
|
static VALUE
|
|
|
|
rb_reg_preprocess_obj(VALUE str,
|
|
|
|
rb_encoding **fixed_enc, onig_errmsg_buffer err)
|
|
|
|
{
|
|
|
|
VALUE buf;
|
|
|
|
char *p, *end;
|
|
|
|
rb_encoding *enc;
|
|
|
|
|
|
|
|
StringValue(str);
|
|
|
|
p = RSTRING_PTR(str);
|
|
|
|
end = p + RSTRING_LEN(str);
|
|
|
|
enc = rb_enc_get(str);
|
|
|
|
|
|
|
|
buf = rb_reg_preprocess(p, end, enc, fixed_enc, err);
|
|
|
|
RB_GC_GUARD(str);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_reg_preprocess_m(VALUE klass, VALUE obj)
|
|
|
|
{
|
|
|
|
rb_encoding *fixed_enc = 0;
|
|
|
|
onig_errmsg_buffer err;
|
|
|
|
VALUE str = rb_reg_preprocess_obj(obj, &fixed_enc, err);
|
|
|
|
if (str == Qnil)
|
|
|
|
rb_raise(rb_eArgError, "%s", err);
|
|
|
|
return rb_assoc_new(str, fixed_enc ? Qtrue : Qfalse);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
static int
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
rb_reg_initialize(VALUE obj, const char *s, int len, rb_encoding *enc,
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
int options, onig_errmsg_buffer err)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-05-22 03:09:55 -04:00
|
|
|
struct RRegexp *re = RREGEXP(obj);
|
2007-12-01 11:56:19 -05:00
|
|
|
VALUE unescaped;
|
|
|
|
rb_encoding *fixed_enc = 0;
|
2000-05-22 03:09:55 -04:00
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-09 17:20:17 -04:00
|
|
|
if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)
|
|
|
|
rb_raise(rb_eSecurityError, "Insecure: can't modify regexp");
|
|
|
|
rb_check_frozen(obj);
|
|
|
|
if (FL_TEST(obj, REG_LITERAL))
|
|
|
|
rb_raise(rb_eSecurityError, "can't modify literal regexp");
|
2005-02-17 09:43:38 -05:00
|
|
|
if (re->ptr) onig_free(re->ptr);
|
2000-07-01 02:47:47 -04:00
|
|
|
if (re->str) free(re->str);
|
1999-01-19 23:59:39 -05:00
|
|
|
re->ptr = 0;
|
|
|
|
re->str = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-12-01 11:56:19 -05:00
|
|
|
unescaped = rb_reg_preprocess(s, s+len, enc, &fixed_enc, err);
|
|
|
|
if (unescaped == Qnil)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (fixed_enc && (options & ARG_ENCODING_FIXED) && fixed_enc != enc) {
|
|
|
|
strcpy(err, "character encodings differ");
|
|
|
|
return -1;
|
2007-11-23 01:30:26 -05:00
|
|
|
}
|
|
|
|
|
2007-12-01 11:56:19 -05:00
|
|
|
if (fixed_enc)
|
|
|
|
enc = fixed_enc;
|
|
|
|
else if (!(options & ARG_ENCODING_FIXED))
|
|
|
|
enc = rb_default_encoding();
|
|
|
|
|
2007-10-19 03:41:03 -04:00
|
|
|
rb_enc_associate((VALUE)re, enc);
|
2007-12-01 11:56:19 -05:00
|
|
|
if ((options & ARG_ENCODING_FIXED) || fixed_enc) {
|
2007-10-16 01:48:40 -04:00
|
|
|
re->basic.flags |= KCODE_FIXED;
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
}
|
2007-12-01 11:56:19 -05:00
|
|
|
re->ptr = make_regexp(RSTRING_PTR(unescaped), RSTRING_LEN(unescaped), enc,
|
|
|
|
options & ARG_REG_OPTION_MASK, err);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
if (!re->ptr) return -1;
|
1998-01-16 07:13:05 -05:00
|
|
|
re->str = ALLOC_N(char, len+1);
|
|
|
|
memcpy(re->str, s, len);
|
|
|
|
re->str[len] = '\0';
|
|
|
|
re->len = len;
|
2007-12-01 11:56:19 -05:00
|
|
|
RB_GC_GUARD(unescaped);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
return 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
static int
|
|
|
|
rb_reg_initialize_str(VALUE obj, VALUE str, int options, onig_errmsg_buffer err)
|
|
|
|
{
|
|
|
|
return rb_reg_initialize(obj, RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str),
|
|
|
|
options, err);
|
|
|
|
}
|
|
|
|
|
2001-10-05 02:30:42 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_s_alloc(VALUE klass)
|
2001-10-05 02:30:42 -04:00
|
|
|
{
|
|
|
|
NEWOBJ(re, struct RRegexp);
|
|
|
|
OBJSETUP(re, klass, T_REGEXP);
|
|
|
|
|
|
|
|
re->ptr = 0;
|
|
|
|
re->len = 0;
|
|
|
|
re->str = 0;
|
|
|
|
|
|
|
|
return (VALUE)re;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
rb_reg_new(VALUE s, int options)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-10-05 02:30:42 -04:00
|
|
|
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
2007-08-18 01:05:36 -04:00
|
|
|
onig_errmsg_buffer err;
|
2000-05-22 03:09:55 -04:00
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
if (rb_reg_initialize_str(re, s, options, err) != 0) {
|
2007-08-25 03:06:47 -04:00
|
|
|
rb_reg_raise_str(s, options, err);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return re;
|
2004-09-24 01:53:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
rb_reg_compile(VALUE str, int options)
|
2004-09-24 01:53:43 -04:00
|
|
|
{
|
|
|
|
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
2007-08-18 01:05:36 -04:00
|
|
|
onig_errmsg_buffer err;
|
2004-09-24 01:53:43 -04:00
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
if (!str) str = rb_str_new(0,0);
|
|
|
|
if (rb_reg_initialize_str(re, str, options, err) != 0) {
|
2007-08-25 03:06:47 -04:00
|
|
|
rb_set_errinfo(rb_reg_error_desc(str, options, err));
|
|
|
|
return Qnil;
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
}
|
|
|
|
FL_SET(re, REG_LITERAL);
|
|
|
|
return re;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE reg_cache;
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_regcomp(VALUE str)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2006-09-18 02:33:03 -04:00
|
|
|
volatile VALUE save_str = str;
|
2006-08-31 06:47:44 -04:00
|
|
|
if (reg_cache && RREGEXP(reg_cache)->len == RSTRING_LEN(str)
|
2007-10-16 01:48:40 -04:00
|
|
|
&& ENCODING_GET(reg_cache) == ENCODING_GET(str)
|
2006-08-31 06:47:44 -04:00
|
|
|
&& memcmp(RREGEXP(reg_cache)->str, RSTRING_PTR(str), RSTRING_LEN(str)) == 0)
|
1998-01-16 07:13:05 -05:00
|
|
|
return reg_cache;
|
|
|
|
|
2007-10-04 03:31:50 -04:00
|
|
|
return reg_cache = rb_reg_new(save_str, 0);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-12-30 11:38:32 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp.hash => fixnum
|
|
|
|
*
|
|
|
|
* Produce a hash based on the text and options of this regular expression.
|
|
|
|
*/
|
|
|
|
|
2002-12-12 04:17:32 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_hash(VALUE re)
|
2002-12-12 04:17:32 -05:00
|
|
|
{
|
|
|
|
int hashval, len;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
rb_reg_check(re);
|
|
|
|
hashval = RREGEXP(re)->ptr->options;
|
|
|
|
len = RREGEXP(re)->len;
|
|
|
|
p = RREGEXP(re)->str;
|
|
|
|
while (len--) {
|
|
|
|
hashval = hashval * 33 + *p++;
|
|
|
|
}
|
|
|
|
hashval = hashval + (hashval>>5);
|
2004-03-05 17:37:35 -05:00
|
|
|
|
2002-12-12 04:17:32 -05:00
|
|
|
return INT2FIX(hashval);
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp == other_rxp => true or false
|
|
|
|
* rxp.eql?(other_rxp) => true or false
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Equality---Two regexps are equal if their patterns are identical, they have
|
|
|
|
* the same character set code, and their <code>casefold?</code> values are the
|
|
|
|
* same.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* /abc/ == /abc/x #=> false
|
|
|
|
* /abc/ == /abc/i #=> false
|
2007-12-09 08:35:38 -05:00
|
|
|
* /abc/ == /abc/n #=> false
|
2003-12-26 10:58:28 -05:00
|
|
|
* /abc/u == /abc/n #=> false
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_equal(VALUE re1, VALUE re2)
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (re1 == re2) return Qtrue;
|
|
|
|
if (TYPE(re2) != T_REGEXP) return Qfalse;
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re1); rb_reg_check(re2);
|
2007-12-09 08:35:38 -05:00
|
|
|
if (FL_TEST(re1, KCODE_FIXED) != FL_TEST(re2, KCODE_FIXED)) return Qfalse;
|
2007-10-16 01:48:40 -04:00
|
|
|
if (RREGEXP(re1)->ptr->options != RREGEXP(re2)->ptr->options) return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
if (RREGEXP(re1)->len != RREGEXP(re2)->len) return Qfalse;
|
2007-10-16 01:48:40 -04:00
|
|
|
if (ENCODING_GET(re1) != ENCODING_GET(re2)) return Qfalse;
|
|
|
|
if (memcmp(RREGEXP(re1)->str, RREGEXP(re2)->str, RREGEXP(re1)->len) == 0) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2007-02-13 23:57:25 -05:00
|
|
|
static VALUE
|
|
|
|
reg_operand(VALUE s, int check)
|
|
|
|
{
|
|
|
|
if (SYMBOL_P(s)) {
|
|
|
|
return rb_sym_to_s(s);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE tmp = rb_check_string_type(s);
|
|
|
|
if (check && NIL_P(tmp)) {
|
|
|
|
rb_raise(rb_eTypeError, "can't convert %s to String",
|
|
|
|
rb_obj_classname(s));
|
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-09 23:50:35 -05:00
|
|
|
static long
|
2007-12-10 05:03:48 -05:00
|
|
|
reg_match_pos(VALUE re, VALUE *strp, long pos)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2007-12-10 05:03:48 -05:00
|
|
|
VALUE str = *strp;
|
|
|
|
|
2004-07-17 04:02:20 -04:00
|
|
|
if (NIL_P(str)) {
|
|
|
|
rb_backref_set(Qnil);
|
2007-12-09 23:50:35 -05:00
|
|
|
return -1;
|
2004-07-17 04:02:20 -04:00
|
|
|
}
|
2007-12-10 05:03:48 -05:00
|
|
|
*strp = str = reg_operand(str, Qtrue);
|
2004-07-17 02:28:10 -04:00
|
|
|
if (pos != 0) {
|
|
|
|
if (pos < 0) {
|
2006-08-31 06:47:44 -04:00
|
|
|
pos += RSTRING_LEN(str);
|
2004-07-17 02:28:10 -04:00
|
|
|
if (pos < 0) {
|
2007-12-09 23:50:35 -05:00
|
|
|
return pos;
|
2004-07-17 02:28:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pos = rb_reg_adjust_startpos(re, str, pos, 0);
|
|
|
|
}
|
2007-12-09 23:50:35 -05:00
|
|
|
return rb_reg_search(re, str, pos, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2004-10-19 21:38:04 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp =~ str => integer or nil
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2004-10-19 21:38:04 -04:00
|
|
|
* Match---Matches <i>rxp</i> against <i>str</i>.
|
|
|
|
*
|
|
|
|
* /at/ =~ "input data" #=> 7
|
2007-12-09 08:35:38 -05:00
|
|
|
* /ax/ =~ "input data" #=> nil
|
2004-10-19 21:38:04 -04:00
|
|
|
*/
|
|
|
|
|
2004-07-17 02:28:10 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match(VALUE re, VALUE str)
|
2004-07-17 02:28:10 -04:00
|
|
|
{
|
2007-12-10 05:03:48 -05:00
|
|
|
long pos = reg_match_pos(re, &str, 0);
|
2007-12-09 23:50:35 -05:00
|
|
|
if (pos < 0) return Qnil;
|
|
|
|
pos = rb_str_sublen(str, pos);
|
|
|
|
return LONG2FIX(pos);
|
2004-07-17 02:28:10 -04:00
|
|
|
}
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* rxp === str => true or false
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Case Equality---Synonym for <code>Regexp#=~</code> used in case statements.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* a = "HELLO"
|
|
|
|
* case a
|
2004-12-06 10:31:26 -05:00
|
|
|
* when /^[a-z]*$/; print "Lower case\n"
|
|
|
|
* when /^[A-Z]*$/; print "Upper case\n"
|
2003-12-26 10:58:28 -05:00
|
|
|
* else; print "Mixed case\n"
|
|
|
|
* end
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* <em>produces:</em>
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Upper case
|
|
|
|
*/
|
|
|
|
|
2002-12-19 04:20:20 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_eqq(VALUE re, VALUE str)
|
2002-12-19 04:20:20 -05:00
|
|
|
{
|
|
|
|
long start;
|
|
|
|
|
2007-02-13 23:57:25 -05:00
|
|
|
str = reg_operand(str, Qfalse);
|
|
|
|
if (NIL_P(str)) {
|
|
|
|
rb_backref_set(Qnil);
|
|
|
|
return Qfalse;
|
2002-12-19 04:20:20 -05:00
|
|
|
}
|
|
|
|
start = rb_reg_search(re, str, 0, 0);
|
|
|
|
if (start < 0) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ~ rxp => integer or nil
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Match---Matches <i>rxp</i> against the contents of <code>$_</code>.
|
|
|
|
* Equivalent to <code><i>rxp</i> =~ $_</code>.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* $_ = "input data"
|
|
|
|
* ~ /at/ #=> 7
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match2(VALUE re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-08-28 04:05:23 -04:00
|
|
|
long start;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE line = rb_lastline_get();
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-03-14 01:23:46 -05:00
|
|
|
if (TYPE(line) != T_STRING) {
|
|
|
|
rb_backref_set(Qnil);
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qnil;
|
2002-03-14 01:23:46 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
start = rb_reg_search(re, line, 0, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
if (start < 0) {
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2007-12-09 23:50:35 -05:00
|
|
|
start = rb_str_sublen(line, start);
|
2002-08-28 04:05:23 -04:00
|
|
|
return LONG2FIX(start);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-07-17 02:28:10 -04:00
|
|
|
* rxp.match(str) => matchdata or nil
|
|
|
|
* rxp.match(str,pos) => matchdata or nil
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Returns a <code>MatchData</code> object describing the match, or
|
|
|
|
* <code>nil</code> if there was no match. This is equivalent to retrieving the
|
|
|
|
* value of the special variable <code>$~</code> following a normal match.
|
2004-07-17 02:28:10 -04:00
|
|
|
* If the second parameter is present, it specifies the position in the string
|
|
|
|
* to begin the search.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* /(.)(.)(.)/.match("abc")[2] #=> "b"
|
2004-07-17 02:28:10 -04:00
|
|
|
* /(.)(.)/.match("abc", 1)[2] #=> "c"
|
2007-09-20 13:14:01 -04:00
|
|
|
*
|
|
|
|
* If a block is given, invoke the block with MatchData if match succeed, so
|
|
|
|
* that you can write
|
|
|
|
*
|
|
|
|
* pat.match(str) {|m| ...}
|
|
|
|
*
|
|
|
|
* instead of
|
|
|
|
*
|
|
|
|
* if m = pat.match(str)
|
|
|
|
* ...
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* The retuen value is a value from block exection in this case.
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_match_m(int argc, VALUE *argv, VALUE re)
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2004-07-17 02:28:10 -04:00
|
|
|
VALUE result, str, initpos;
|
|
|
|
long pos;
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2004-07-17 02:28:10 -04:00
|
|
|
if (rb_scan_args(argc, argv, "11", &str, &initpos) == 2) {
|
|
|
|
pos = NUM2LONG(initpos);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
|
2007-12-10 05:03:48 -05:00
|
|
|
pos = reg_match_pos(re, &str, pos);
|
2007-12-09 23:50:35 -05:00
|
|
|
if (pos < 0) {
|
2004-07-17 02:28:10 -04:00
|
|
|
rb_backref_set(Qnil);
|
|
|
|
return Qnil;
|
|
|
|
}
|
2000-07-14 03:18:58 -04:00
|
|
|
result = rb_backref_get();
|
|
|
|
rb_match_busy(result);
|
2007-09-20 13:14:01 -04:00
|
|
|
if (!NIL_P(result) && rb_block_given_p()) {
|
|
|
|
return rb_yield(result);
|
|
|
|
}
|
2000-07-14 03:18:58 -04:00
|
|
|
return result;
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
2003-12-30 11:38:32 -05:00
|
|
|
/*
|
|
|
|
* Document-method: compile
|
|
|
|
*
|
|
|
|
* Synonym for <code>Regexp.new</code>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2007-10-16 01:48:40 -04:00
|
|
|
* Regexp.new(string [, options]) => regexp
|
2003-12-26 10:58:28 -05:00
|
|
|
* Regexp.new(regexp) => regexp
|
2007-10-16 01:48:40 -04:00
|
|
|
* Regexp.compile(string [, options]) => regexp
|
2003-12-26 10:58:28 -05:00
|
|
|
* Regexp.compile(regexp) => regexp
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Constructs a new regular expression from <i>pattern</i>, which can be either
|
|
|
|
* a <code>String</code> or a <code>Regexp</code> (in which case that regexp's
|
|
|
|
* options are propagated, and new options may not be specified (a change as of
|
|
|
|
* Ruby 1.8). If <i>options</i> is a <code>Fixnum</code>, it should be one or
|
|
|
|
* more of the constants <code>Regexp::EXTENDED</code>,
|
2005-03-09 04:29:52 -05:00
|
|
|
* <code>Regexp::IGNORECASE</code>, and <code>Regexp::MULTILINE</code>,
|
2003-12-26 10:58:28 -05:00
|
|
|
* <em>or</em>-ed together. Otherwise, if <i>options</i> is not
|
2007-12-09 08:35:38 -05:00
|
|
|
* <code>nil</code>, the regexp will be case insensitive.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* r1 = Regexp.new('^a-z+:\\s+\w+') #=> /^a-z+:\s+\w+/
|
|
|
|
* r2 = Regexp.new('cat', true) #=> /cat/i
|
|
|
|
* r3 = Regexp.new('dog', Regexp::EXTENDED) #=> /dog/x
|
2007-12-09 08:35:38 -05:00
|
|
|
* r4 = Regexp.new(r2) #=> /cat/i
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
onig_errmsg_buffer err;
|
2001-02-02 06:38:20 -05:00
|
|
|
int flags = 0;
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
VALUE str;
|
2007-10-19 03:41:03 -04:00
|
|
|
rb_encoding *enc;
|
|
|
|
const char *ptr;
|
|
|
|
long len;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-10-16 12:57:08 -04:00
|
|
|
if (argc == 0 || argc > 3) {
|
2004-03-29 02:54:38 -05:00
|
|
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2003-02-03 03:45:26 -05:00
|
|
|
if (TYPE(argv[0]) == T_REGEXP) {
|
2007-10-16 01:48:40 -04:00
|
|
|
VALUE re = argv[0];
|
|
|
|
|
2003-02-03 03:45:26 -05:00
|
|
|
if (argc > 1) {
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_warn("flags ignored");
|
2003-02-03 03:45:26 -05:00
|
|
|
}
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_reg_check(re);
|
2007-10-19 03:41:03 -04:00
|
|
|
flags = rb_reg_options(re);
|
2007-10-16 01:48:40 -04:00
|
|
|
ptr = RREGEXP(re)->str;
|
|
|
|
len = RREGEXP(re)->len;
|
|
|
|
enc = rb_enc_get(re);
|
|
|
|
if (rb_reg_initialize(self, ptr, len, enc, flags, err)) {
|
|
|
|
str = rb_enc_str_new(ptr, len, enc);
|
|
|
|
rb_reg_raise_str(str, flags, err);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
else {
|
2003-02-03 03:45:26 -05:00
|
|
|
if (argc >= 2) {
|
|
|
|
if (FIXNUM_P(argv[1])) flags = FIX2INT(argv[1]);
|
2005-02-17 09:43:38 -05:00
|
|
|
else if (RTEST(argv[1])) flags = ONIG_OPTION_IGNORECASE;
|
2003-02-03 03:45:26 -05:00
|
|
|
}
|
2007-10-19 03:41:03 -04:00
|
|
|
enc = 0;
|
2007-10-16 12:57:08 -04:00
|
|
|
if (argc == 3 && !NIL_P(argv[2])) {
|
|
|
|
char *kcode = StringValuePtr(argv[2]);
|
|
|
|
if (kcode[0] == 'n' || kcode[1] == 'N') {
|
2007-10-19 03:41:03 -04:00
|
|
|
enc = rb_enc_from_index(0);
|
|
|
|
flags |= ARG_ENCODING_FIXED;
|
2007-10-16 12:57:08 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_warning("encoding option is obsolete - %s", kcode);
|
|
|
|
}
|
|
|
|
}
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
str = argv[0];
|
2007-11-04 09:53:36 -05:00
|
|
|
ptr = StringValuePtr(str);
|
2007-10-19 03:41:03 -04:00
|
|
|
if (enc
|
|
|
|
? rb_reg_initialize(self, ptr, RSTRING_LEN(str), enc, flags, err)
|
|
|
|
: rb_reg_initialize_str(self, str, flags, err)) {
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_reg_raise_str(str, flags, err);
|
|
|
|
}
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
}
|
2001-01-15 02:01:00 -05:00
|
|
|
return self;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2002-07-26 02:12:39 -04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_quote(VALUE str)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
rb_encoding *enc = rb_enc_get(str);
|
1999-08-13 01:45:20 -04:00
|
|
|
char *s, *send, *t;
|
2000-10-10 03:03:36 -04:00
|
|
|
VALUE tmp;
|
2007-12-10 22:08:50 -05:00
|
|
|
int c, clen;
|
2007-11-25 08:25:34 -05:00
|
|
|
int ascii_only = rb_enc_str_asciionly_p(str);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2006-08-31 06:47:44 -04:00
|
|
|
s = RSTRING_PTR(str);
|
|
|
|
send = s + RSTRING_LEN(str);
|
2007-12-10 22:08:50 -05:00
|
|
|
while (s < send) {
|
|
|
|
c = rb_enc_get_ascii(s, send, &clen, enc);
|
2007-12-07 21:50:43 -05:00
|
|
|
if (c == -1) {
|
2007-12-10 22:08:50 -05:00
|
|
|
s += mbclen(s, send, enc);
|
2002-07-26 02:12:39 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (c) {
|
|
|
|
case '[': case ']': case '{': case '}':
|
|
|
|
case '(': case ')': case '|': case '-':
|
|
|
|
case '*': case '.': case '\\':
|
|
|
|
case '?': case '+': case '^': case '$':
|
|
|
|
case ' ': case '#':
|
2007-11-04 10:03:31 -05:00
|
|
|
case '\t': case '\f': case '\v': case '\n': case '\r':
|
2002-07-26 02:12:39 -04:00
|
|
|
goto meta_found;
|
|
|
|
}
|
2007-12-10 22:08:50 -05:00
|
|
|
s += clen;
|
2002-07-26 02:12:39 -04:00
|
|
|
}
|
2007-11-25 08:25:34 -05:00
|
|
|
if (ascii_only && rb_enc_get_index(str) != 0) {
|
|
|
|
str = rb_str_new3(str);
|
|
|
|
rb_enc_associate(str, rb_enc_from_index(0));
|
|
|
|
}
|
2002-07-26 02:12:39 -04:00
|
|
|
return str;
|
|
|
|
|
|
|
|
meta_found:
|
2006-08-31 06:47:44 -04:00
|
|
|
tmp = rb_str_new(0, RSTRING_LEN(str)*2);
|
2007-11-25 08:25:34 -05:00
|
|
|
if (!ascii_only) {
|
|
|
|
rb_enc_copy(tmp, str);
|
|
|
|
}
|
2006-08-31 06:47:44 -04:00
|
|
|
t = RSTRING_PTR(tmp);
|
2002-07-29 02:14:10 -04:00
|
|
|
/* copy upto metacharacter */
|
2006-08-31 06:47:44 -04:00
|
|
|
memcpy(t, RSTRING_PTR(str), s - RSTRING_PTR(str));
|
|
|
|
t += s - RSTRING_PTR(str);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2007-12-10 22:08:50 -05:00
|
|
|
while (s < send) {
|
|
|
|
c = rb_enc_get_ascii(s, send, &clen, enc);
|
2007-12-07 21:50:43 -05:00
|
|
|
if (c == -1) {
|
2007-09-06 08:33:45 -04:00
|
|
|
int n = mbclen(s, send, enc);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2007-12-10 22:08:50 -05:00
|
|
|
while (n--)
|
1999-08-13 01:45:20 -04:00
|
|
|
*t++ = *s++;
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-10 22:08:50 -05:00
|
|
|
s += clen;
|
2002-05-01 05:41:50 -04:00
|
|
|
switch (c) {
|
|
|
|
case '[': case ']': case '{': case '}':
|
|
|
|
case '(': case ')': case '|': case '-':
|
|
|
|
case '*': case '.': case '\\':
|
|
|
|
case '?': case '+': case '^': case '$':
|
2003-05-16 19:28:31 -04:00
|
|
|
case '#':
|
|
|
|
*t++ = '\\';
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
*t++ = '\\';
|
2003-05-19 00:48:57 -04:00
|
|
|
*t++ = ' ';
|
|
|
|
continue;
|
2003-05-16 19:28:31 -04:00
|
|
|
case '\t':
|
|
|
|
*t++ = '\\';
|
|
|
|
*t++ = 't';
|
2003-05-19 00:48:57 -04:00
|
|
|
continue;
|
2003-05-16 19:28:31 -04:00
|
|
|
case '\n':
|
|
|
|
*t++ = '\\';
|
|
|
|
*t++ = 'n';
|
2003-05-19 00:48:57 -04:00
|
|
|
continue;
|
2003-05-16 19:28:31 -04:00
|
|
|
case '\r':
|
|
|
|
*t++ = '\\';
|
|
|
|
*t++ = 'r';
|
2003-05-19 00:48:57 -04:00
|
|
|
continue;
|
2003-05-16 19:28:31 -04:00
|
|
|
case '\f':
|
2002-05-01 05:41:50 -04:00
|
|
|
*t++ = '\\';
|
2003-05-16 19:28:31 -04:00
|
|
|
*t++ = 'f';
|
2003-05-19 00:48:57 -04:00
|
|
|
continue;
|
2007-11-04 10:03:31 -05:00
|
|
|
case '\v':
|
|
|
|
*t++ = '\\';
|
|
|
|
*t++ = 'v';
|
|
|
|
continue;
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
2002-05-01 05:41:50 -04:00
|
|
|
*t++ = c;
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
2006-08-31 06:47:44 -04:00
|
|
|
rb_str_resize(tmp, t - RSTRING_PTR(tmp));
|
2001-12-21 04:23:28 -05:00
|
|
|
OBJ_INFECT(tmp, str);
|
2000-10-10 03:03:36 -04:00
|
|
|
return tmp;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2007-12-09 08:35:38 -05:00
|
|
|
* Regexp.escape(str) => string
|
|
|
|
* Regexp.quote(str) => string
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* Escapes any characters that would have special meaning in a regular
|
2005-03-16 04:25:45 -05:00
|
|
|
* expression. Returns a new escaped string, or self if no characters are
|
|
|
|
* escaped. For any string,
|
2007-12-09 08:35:38 -05:00
|
|
|
* <code>Regexp.new(Regexp.escape(<i>str</i>))=~<i>str</i></code> will be true.
|
|
|
|
*
|
|
|
|
* Regexp.escape('\*?{}.') #=> \\\*\?\{\}\.
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
2002-07-26 02:12:39 -04:00
|
|
|
static VALUE
|
2007-10-10 10:34:42 -04:00
|
|
|
rb_reg_s_quote(VALUE c, VALUE str)
|
2002-07-26 02:12:39 -04:00
|
|
|
{
|
2007-10-10 10:34:42 -04:00
|
|
|
return rb_reg_quote(reg_operand(str, Qtrue));
|
2002-07-26 02:12:39 -04:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_options(VALUE re)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-07-25 00:38:42 -04:00
|
|
|
int options;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
2007-10-19 03:41:03 -04:00
|
|
|
options = RREGEXP(re)->ptr->options & ARG_REG_OPTION_MASK;
|
|
|
|
if (RBASIC(re)->flags & KCODE_FIXED) options |= ARG_ENCODING_FIXED;
|
1999-01-19 23:59:39 -05:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2007-08-02 10:42:59 -04:00
|
|
|
VALUE
|
|
|
|
rb_check_regexp_type(VALUE re)
|
|
|
|
{
|
|
|
|
return rb_check_convert_type(re, T_REGEXP, "Regexp", "to_regexp");
|
|
|
|
}
|
|
|
|
|
2007-08-24 13:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Regexp.try_convert(obj) -> re or nil
|
|
|
|
*
|
|
|
|
* Try to convert <i>obj</i> into a Regexp, using to_regexp method.
|
|
|
|
* Returns converted regexp or nil if <i>obj</i> cannot be converted
|
|
|
|
* for any reason.
|
|
|
|
*
|
2007-12-09 08:35:38 -05:00
|
|
|
* Regexp.try_convert(/re/) #=> /re/
|
|
|
|
* Regexp.try_convert("re") #=> nil
|
|
|
|
*
|
|
|
|
* o = Object.new
|
|
|
|
* Regexp.try_convert(o) #=> nil
|
|
|
|
* def o.to_regexp() /foo/ end
|
|
|
|
* Regexp.try_convert(o) #=> /foo/
|
|
|
|
*
|
2007-08-24 13:47:09 -04:00
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_reg_s_try_convert(VALUE dummy, VALUE re)
|
|
|
|
{
|
|
|
|
return rb_check_regexp_type(re);
|
|
|
|
}
|
2003-12-26 10:58:28 -05:00
|
|
|
|
2003-10-29 03:31:43 -05:00
|
|
|
static VALUE
|
2007-10-05 08:26:35 -04:00
|
|
|
rb_reg_s_union(VALUE self, VALUE args0)
|
2003-10-29 03:31:43 -05:00
|
|
|
{
|
2007-10-05 08:26:35 -04:00
|
|
|
long argc = RARRAY_LEN(args0);
|
2007-10-16 01:06:30 -04:00
|
|
|
|
2003-10-29 03:31:43 -05:00
|
|
|
if (argc == 0) {
|
|
|
|
VALUE args[1];
|
|
|
|
args[0] = rb_str_new2("(?!)");
|
|
|
|
return rb_class_new_instance(1, args, rb_cRegexp);
|
|
|
|
}
|
|
|
|
else if (argc == 1) {
|
2007-11-25 08:25:34 -05:00
|
|
|
VALUE arg = rb_ary_entry(args0, 0);
|
|
|
|
VALUE re = rb_check_regexp_type(arg);
|
|
|
|
if (!NIL_P(re))
|
|
|
|
return re;
|
2003-10-29 03:31:43 -05:00
|
|
|
else {
|
2007-11-25 08:25:34 -05:00
|
|
|
VALUE quoted;
|
|
|
|
quoted = rb_reg_s_quote(Qnil, arg);
|
|
|
|
return rb_reg_new(quoted, 0);
|
2003-10-29 03:31:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-10-16 01:48:40 -04:00
|
|
|
int i;
|
|
|
|
VALUE source = rb_str_buf_new(0);
|
2007-11-25 21:27:59 -05:00
|
|
|
rb_encoding *result_enc;
|
2007-11-25 08:25:34 -05:00
|
|
|
|
2007-11-25 21:27:59 -05:00
|
|
|
int has_asciionly = 0;
|
|
|
|
rb_encoding *has_ascii_compat_fixed = 0;
|
|
|
|
rb_encoding *has_ascii_incompat = 0;
|
2007-10-16 01:06:30 -04:00
|
|
|
|
2007-10-16 01:48:40 -04:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
volatile VALUE v;
|
2007-10-16 06:48:02 -04:00
|
|
|
VALUE e = rb_ary_entry(args0, i);
|
2007-11-25 08:25:34 -05:00
|
|
|
|
2007-10-16 01:48:40 -04:00
|
|
|
if (0 < i)
|
2007-11-25 08:25:34 -05:00
|
|
|
rb_str_buf_cat2(source, "|"); /* xxx: UTF-16 */
|
|
|
|
|
2007-10-16 06:48:02 -04:00
|
|
|
v = rb_check_regexp_type(e);
|
2007-10-16 01:48:40 -04:00
|
|
|
if (!NIL_P(v)) {
|
2007-11-25 21:27:59 -05:00
|
|
|
rb_encoding *enc = rb_enc_get(v);
|
|
|
|
if (!rb_enc_asciicompat(enc)) {
|
|
|
|
if (!has_ascii_incompat)
|
|
|
|
has_ascii_incompat = enc;
|
|
|
|
else if (has_ascii_incompat != enc)
|
|
|
|
rb_raise(rb_eArgError, "regexp encodings differ");
|
2007-11-25 08:25:34 -05:00
|
|
|
}
|
2007-11-25 21:27:59 -05:00
|
|
|
else if (rb_reg_fixed_encoding_p(v)) {
|
|
|
|
if (!has_ascii_compat_fixed)
|
|
|
|
has_ascii_compat_fixed = enc;
|
|
|
|
else if (has_ascii_compat_fixed != enc)
|
|
|
|
rb_raise(rb_eArgError, "regexp encodings differ");
|
2007-11-25 08:25:34 -05:00
|
|
|
}
|
|
|
|
else {
|
2007-11-25 21:27:59 -05:00
|
|
|
has_asciionly = 1;
|
2007-11-25 08:25:34 -05:00
|
|
|
}
|
2007-10-16 01:48:40 -04:00
|
|
|
v = rb_reg_to_s(v);
|
|
|
|
}
|
|
|
|
else {
|
2007-11-25 21:27:59 -05:00
|
|
|
rb_encoding *enc = rb_enc_get(e);
|
2007-11-25 08:25:34 -05:00
|
|
|
StringValue(e);
|
2007-11-25 21:27:59 -05:00
|
|
|
enc = rb_enc_get(e);
|
2007-11-25 08:25:34 -05:00
|
|
|
if (!rb_enc_str_asciicompat_p(e)) {
|
2007-11-25 21:27:59 -05:00
|
|
|
if (!has_ascii_incompat)
|
|
|
|
has_ascii_incompat = enc;
|
|
|
|
else if (has_ascii_incompat != enc)
|
|
|
|
rb_raise(rb_eArgError, "regexp encodings differ");
|
2007-11-25 08:25:34 -05:00
|
|
|
}
|
|
|
|
else if (rb_enc_str_asciionly_p(e)) {
|
2007-11-25 21:27:59 -05:00
|
|
|
has_asciionly = 1;
|
2007-11-25 08:25:34 -05:00
|
|
|
}
|
|
|
|
else {
|
2007-11-25 21:27:59 -05:00
|
|
|
if (!has_ascii_compat_fixed)
|
|
|
|
has_ascii_compat_fixed = enc;
|
|
|
|
else if (has_ascii_compat_fixed != enc)
|
|
|
|
rb_raise(rb_eArgError, "regexp encodings differ");
|
2007-11-25 08:25:34 -05:00
|
|
|
}
|
2007-10-16 06:48:02 -04:00
|
|
|
v = rb_reg_s_quote(Qnil, e);
|
2007-10-17 01:21:10 -04:00
|
|
|
}
|
2007-11-25 21:27:59 -05:00
|
|
|
if (has_ascii_incompat && (has_asciionly || has_ascii_compat_fixed)) {
|
|
|
|
rb_raise(rb_eArgError, "regexp encodings differ");
|
|
|
|
}
|
|
|
|
|
2007-10-16 14:37:09 -04:00
|
|
|
rb_str_append(source, v);
|
2007-08-02 10:42:59 -04:00
|
|
|
}
|
2007-11-25 21:27:59 -05:00
|
|
|
|
|
|
|
if (has_ascii_incompat) {
|
|
|
|
result_enc = has_ascii_incompat;
|
2007-11-25 08:25:34 -05:00
|
|
|
}
|
2007-11-25 21:27:59 -05:00
|
|
|
else if (has_ascii_compat_fixed) {
|
|
|
|
result_enc = has_ascii_compat_fixed;
|
2007-11-25 08:25:34 -05:00
|
|
|
}
|
|
|
|
else {
|
2007-11-25 21:27:59 -05:00
|
|
|
result_enc = rb_enc_from_index(0);
|
2007-11-25 08:25:34 -05:00
|
|
|
}
|
|
|
|
|
2007-11-25 21:27:59 -05:00
|
|
|
rb_enc_associate(source, result_enc);
|
2007-10-16 01:48:40 -04:00
|
|
|
return rb_class_new_instance(1, &source, rb_cRegexp);
|
2003-10-29 03:31:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-08 12:03:53 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Regexp.union(pat1, pat2, ...) => new_regexp
|
|
|
|
* Regexp.union(pats_ary) => new_regexp
|
|
|
|
*
|
|
|
|
* Return a <code>Regexp</code> object that is the union of the given
|
|
|
|
* <em>pattern</em>s, i.e., will match any of its parts. The <em>pattern</em>s
|
|
|
|
* can be Regexp objects, in which case their options will be preserved, or
|
|
|
|
* Strings. If no patterns are given, returns <code>/(?!)/</code>.
|
|
|
|
*
|
|
|
|
* Regexp.union #=> /(?!)/
|
|
|
|
* Regexp.union("penzance") #=> /penzance/
|
|
|
|
* Regexp.union("a+b*c") #=> /a\+b\*c/
|
|
|
|
* Regexp.union("skiing", "sledding") #=> /skiing|sledding/
|
|
|
|
* Regexp.union(["skiing", "sledding"]) #=> /skiing|sledding/
|
|
|
|
* Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/
|
|
|
|
*/
|
2007-10-05 08:26:35 -04:00
|
|
|
static VALUE
|
|
|
|
rb_reg_s_union_m(VALUE self, VALUE args)
|
|
|
|
{
|
|
|
|
VALUE v;
|
|
|
|
if (RARRAY_LEN(args) == 1 &&
|
|
|
|
!NIL_P(v = rb_check_array_type(rb_ary_entry(args, 0)))) {
|
|
|
|
return rb_reg_s_union(self, v);
|
|
|
|
}
|
|
|
|
return rb_reg_s_union(self, args);
|
|
|
|
}
|
|
|
|
|
2004-01-18 09:16:47 -05:00
|
|
|
/* :nodoc: */
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_init_copy(VALUE copy, VALUE re)
|
2000-01-04 23:41:21 -05:00
|
|
|
{
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
onig_errmsg_buffer err;
|
|
|
|
const char *s;
|
|
|
|
long len;
|
|
|
|
|
2002-09-03 01:20:14 -04:00
|
|
|
if (copy == re) return copy;
|
|
|
|
rb_check_frozen(copy);
|
2002-08-27 04:31:08 -04:00
|
|
|
/* need better argument type check */
|
2002-09-03 01:20:14 -04:00
|
|
|
if (!rb_obj_is_instance_of(re, rb_obj_class(copy))) {
|
2002-08-27 04:31:08 -04:00
|
|
|
rb_raise(rb_eTypeError, "wrong argument type");
|
|
|
|
}
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_reg_check(re);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
s = RREGEXP(re)->str;
|
|
|
|
len = RREGEXP(re)->len;
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
if (rb_reg_initialize(copy, s, len, rb_enc_get(re), rb_reg_options(re), err) != 0) {
|
2007-08-25 03:06:47 -04:00
|
|
|
rb_reg_raise(s, len, err, re);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
}
|
2002-09-03 01:20:14 -04:00
|
|
|
return copy;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2006-03-22 10:03:40 -05:00
|
|
|
rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
VALUE val = 0;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 09:43:08 -05:00
|
|
|
char *p, *s, *e;
|
2007-12-10 22:08:50 -05:00
|
|
|
int no, clen;
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
rb_encoding *enc = rb_enc_check(str, src);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
rb_enc_check(str, regexp);
|
2006-08-31 06:47:44 -04:00
|
|
|
p = s = RSTRING_PTR(str);
|
|
|
|
e = s + RSTRING_LEN(str);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (s < e) {
|
2007-12-10 22:08:50 -05:00
|
|
|
int c = rb_enc_get_ascii(s, e, &clen, enc);
|
|
|
|
char *ss;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2007-12-07 21:50:43 -05:00
|
|
|
if (c == -1) {
|
2007-12-10 22:08:50 -05:00
|
|
|
s += mbclen(s, e, enc);
|
1999-01-19 23:59:39 -05:00
|
|
|
continue;
|
|
|
|
}
|
2007-12-10 22:08:50 -05:00
|
|
|
ss = s;
|
|
|
|
s += clen;
|
|
|
|
|
2007-12-07 21:50:43 -05:00
|
|
|
if (c != '\\' || s == e) continue;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2001-05-30 05:12:34 -04:00
|
|
|
if (!val) {
|
|
|
|
val = rb_str_buf_new(ss-p);
|
|
|
|
}
|
2007-12-10 22:08:50 -05:00
|
|
|
rb_str_buf_cat(val, p, ss-p);
|
|
|
|
|
|
|
|
c = rb_enc_get_ascii(s, e, &clen, enc);
|
|
|
|
if (c == -1) {
|
|
|
|
s += mbclen(s, e, enc);
|
|
|
|
rb_str_buf_cat(val, ss, s-ss);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
s += clen;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
p = s;
|
2007-12-10 22:08:50 -05:00
|
|
|
switch (c) {
|
2006-03-23 07:43:51 -05:00
|
|
|
case '1': case '2': case '3': case '4':
|
1998-01-16 07:13:05 -05:00
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
2006-03-23 07:43:51 -05:00
|
|
|
if (onig_noname_group_capture_is_active(RREGEXP(regexp)->ptr)) {
|
2007-12-10 22:08:50 -05:00
|
|
|
no = c - '0';
|
2006-03-23 07:43:51 -05:00
|
|
|
}
|
|
|
|
else {
|
2007-12-10 22:08:50 -05:00
|
|
|
continue;
|
2006-03-23 07:43:51 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
2006-03-22 10:03:40 -05:00
|
|
|
|
|
|
|
case 'k':
|
2007-12-10 22:08:50 -05:00
|
|
|
if (s < e && rb_enc_get_ascii(s, e, &clen, enc) == '<') {
|
|
|
|
char *name, *name_end;
|
|
|
|
|
|
|
|
name_end = name = s + clen;
|
|
|
|
while (name_end < e) {
|
|
|
|
c = rb_enc_get_ascii(name_end, e, &clen, enc);
|
|
|
|
if (c == '>') break;
|
|
|
|
name_end += c == -1 ? mbclen(name_end, e, enc) : clen;
|
|
|
|
}
|
|
|
|
if (name_end < e) {
|
|
|
|
no = name_to_backref_number(regs, regexp, name, name_end);
|
|
|
|
p = s = name_end + clen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eRuntimeError, "invalid group name reference format");
|
|
|
|
}
|
2006-03-22 10:03:40 -05:00
|
|
|
}
|
|
|
|
|
2007-12-10 22:08:50 -05:00
|
|
|
rb_str_buf_cat(val, ss, s-ss);
|
2006-03-22 10:03:40 -05:00
|
|
|
continue;
|
|
|
|
|
2006-03-23 07:43:51 -05:00
|
|
|
case '0':
|
1998-01-16 07:13:05 -05:00
|
|
|
case '&':
|
|
|
|
no = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '`':
|
2006-08-31 06:47:44 -04:00
|
|
|
rb_str_buf_cat(val, RSTRING_PTR(src), BEG(0));
|
1998-01-16 07:13:05 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case '\'':
|
2006-08-31 06:47:44 -04:00
|
|
|
rb_str_buf_cat(val, RSTRING_PTR(src)+END(0), RSTRING_LEN(src)-END(0));
|
1998-01-16 07:13:05 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
no = regs->num_regs-1;
|
|
|
|
while (BEG(no) == -1 && no > 0) no--;
|
|
|
|
if (no == 0) continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\\':
|
2007-12-10 22:08:50 -05:00
|
|
|
rb_str_buf_cat(val, s-clen, clen);
|
1998-01-16 07:13:05 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
default:
|
2007-12-10 22:08:50 -05:00
|
|
|
rb_str_buf_cat(val, ss, s-ss);
|
1998-01-16 07:13:05 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (no >= 0) {
|
2000-02-08 03:54:01 -05:00
|
|
|
if (no >= regs->num_regs) continue;
|
1998-01-16 07:13:05 -05:00
|
|
|
if (BEG(no) == -1) continue;
|
2006-08-31 06:47:44 -04:00
|
|
|
rb_str_buf_cat(val, RSTRING_PTR(src)+BEG(no), END(no)-BEG(no));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p < e) {
|
2001-05-30 05:12:34 -04:00
|
|
|
if (!val) {
|
|
|
|
val = rb_str_buf_new(e-p);
|
|
|
|
}
|
2007-12-10 22:08:50 -05:00
|
|
|
rb_str_buf_cat(val, p, e-p);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
if (!val) return str;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
kcode_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_warn("variable $KCODE is no longer effective");
|
|
|
|
return Qnil;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-10-16 01:48:40 -04:00
|
|
|
kcode_setter(VALUE val, ID id)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2007-10-16 01:48:40 -04:00
|
|
|
rb_warn("variable $KCODE is no longer effective; ignored");
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
ignorecase_getter(void)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2007-10-04 04:09:06 -04:00
|
|
|
rb_warn("variable $= is no longer effective");
|
2007-10-04 03:31:50 -04:00
|
|
|
return Qfalse;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
ignorecase_setter(VALUE val, ID id)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2007-10-04 04:09:06 -04:00
|
|
|
rb_warn("variable $= is no longer effective; ignored");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_getter(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
VALUE match = rb_backref_get();
|
|
|
|
|
|
|
|
if (NIL_P(match)) return Qnil;
|
2000-02-08 03:54:01 -05:00
|
|
|
rb_match_busy(match);
|
|
|
|
return match;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
match_setter(VALUE val)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-04-01 02:39:09 -05:00
|
|
|
if (!NIL_P(val)) {
|
|
|
|
Check_Type(val, T_MATCH);
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_backref_set(val);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Regexp.last_match => matchdata
|
2007-12-09 08:35:38 -05:00
|
|
|
* Regexp.last_match(n) => str
|
* compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c,
pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci,
thread_pthread.ci, thread_win32.ci: fixed indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-05 00:25:10 -04:00
|
|
|
*
|
2003-12-26 10:58:28 -05:00
|
|
|
* The first form returns the <code>MatchData</code> object generated by the
|
|
|
|
* last successful pattern match. Equivalent to reading the global variable
|
2007-12-09 08:35:38 -05:00
|
|
|
* <code>$~</code>. The second form returns the <i>n</i>th field in this
|
2003-12-26 10:58:28 -05:00
|
|
|
* <code>MatchData</code> object.
|
2007-12-09 08:35:38 -05:00
|
|
|
* <em>n</em> can be a string or symbol to reference a named capture.
|
|
|
|
*
|
|
|
|
* /c(.)t/ =~ 'cat' #=> 0
|
|
|
|
* Regexp.last_match #=> #<MatchData "cat" "a">
|
|
|
|
* Regexp.last_match(0) #=> "cat"
|
|
|
|
* Regexp.last_match(1) #=> "a"
|
|
|
|
* Regexp.last_match(2) #=> nil
|
|
|
|
*
|
|
|
|
* /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ "var = val"
|
|
|
|
* Regexp.last_match #=> #<MatchData "var = val" lhs:"var" rhs:"val">
|
|
|
|
* Regexp.last_match(:lhs) #=> "var"
|
|
|
|
* Regexp.last_match(:rhs) #=> "val"
|
2003-12-26 10:58:28 -05:00
|
|
|
*/
|
|
|
|
|
2001-01-15 02:01:00 -05:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
rb_reg_s_last_match(int argc, VALUE *argv)
|
2001-01-15 02:01:00 -05:00
|
|
|
{
|
|
|
|
VALUE nth;
|
|
|
|
|
|
|
|
if (rb_scan_args(argc, argv, "01", &nth) == 1) {
|
2007-12-09 08:35:38 -05:00
|
|
|
VALUE match = rb_backref_get();
|
|
|
|
int n;
|
|
|
|
if (NIL_P(match)) return Qnil;
|
|
|
|
n = match_backref_number(match, nth);
|
|
|
|
return rb_reg_nth_match(n, match);
|
2001-01-15 02:01:00 -05:00
|
|
|
}
|
|
|
|
return match_getter();
|
|
|
|
}
|
|
|
|
|
2003-12-26 10:58:28 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: Regexp
|
|
|
|
*
|
|
|
|
* A <code>Regexp</code> holds a regular expression, used to match a pattern
|
|
|
|
* against strings. Regexps are created using the <code>/.../</code> and
|
|
|
|
* <code>%r{...}</code> literals, and by the <code>Regexp::new</code>
|
|
|
|
* constructor.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 06:44:21 -04:00
|
|
|
Init_Regexp(void)
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2000-08-28 05:53:42 -04:00
|
|
|
rb_eRegexpError = rb_define_class("RegexpError", rb_eStandardError);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-05-22 23:24:28 -04:00
|
|
|
onigenc_set_default_caseconv_table((UChar*)casetable);
|
2007-10-05 13:39:59 -04:00
|
|
|
onigenc_set_default_encoding(ONIG_ENCODING_ASCII);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
rb_define_virtual_variable("$~", match_getter, match_setter);
|
|
|
|
rb_define_virtual_variable("$&", last_match_getter, 0);
|
|
|
|
rb_define_virtual_variable("$`", prematch_getter, 0);
|
|
|
|
rb_define_virtual_variable("$'", postmatch_getter, 0);
|
|
|
|
rb_define_virtual_variable("$+", last_paren_match_getter, 0);
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_virtual_variable("$=", ignorecase_getter, ignorecase_setter);
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_define_virtual_variable("$KCODE", kcode_getter, kcode_setter);
|
|
|
|
rb_define_virtual_variable("$-K", kcode_getter, kcode_setter);
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_cRegexp = rb_define_class("Regexp", rb_cObject);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_define_alloc_func(rb_cRegexp, rb_reg_s_alloc);
|
2001-10-03 03:19:19 -04:00
|
|
|
rb_define_singleton_method(rb_cRegexp, "compile", rb_class_new_instance, -1);
|
2007-10-10 10:34:42 -04:00
|
|
|
rb_define_singleton_method(rb_cRegexp, "quote", rb_reg_s_quote, 1);
|
|
|
|
rb_define_singleton_method(rb_cRegexp, "escape", rb_reg_s_quote, 1);
|
2007-10-05 08:26:35 -04:00
|
|
|
rb_define_singleton_method(rb_cRegexp, "union", rb_reg_s_union_m, -2);
|
2001-01-15 02:01:00 -05:00
|
|
|
rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
|
2007-08-24 13:47:09 -04:00
|
|
|
rb_define_singleton_method(rb_cRegexp, "try_convert", rb_reg_s_try_convert, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2007-12-01 11:56:19 -05:00
|
|
|
#if 0
|
|
|
|
rb_define_singleton_method(rb_cRegexp, "preprocess", rb_reg_preprocess_m, 1);
|
|
|
|
#endif
|
|
|
|
|
2000-05-22 03:09:55 -04:00
|
|
|
rb_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1);
|
2003-05-19 01:41:08 -04:00
|
|
|
rb_define_method(rb_cRegexp, "initialize_copy", rb_reg_init_copy, 1);
|
2002-12-12 04:17:32 -05:00
|
|
|
rb_define_method(rb_cRegexp, "hash", rb_reg_hash, 0);
|
|
|
|
rb_define_method(rb_cRegexp, "eql?", rb_reg_equal, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1);
|
|
|
|
rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1);
|
2002-12-19 04:20:20 -05:00
|
|
|
rb_define_method(rb_cRegexp, "===", rb_reg_eqq, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cRegexp, "~", rb_reg_match2, 0);
|
2004-07-17 02:28:10 -04:00
|
|
|
rb_define_method(rb_cRegexp, "match", rb_reg_match_m, -1);
|
2002-04-18 04:04:57 -04:00
|
|
|
rb_define_method(rb_cRegexp, "to_s", rb_reg_to_s, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cRegexp, "inspect", rb_reg_inspect, 0);
|
|
|
|
rb_define_method(rb_cRegexp, "source", rb_reg_source, 0);
|
|
|
|
rb_define_method(rb_cRegexp, "casefold?", rb_reg_casefold_p, 0);
|
2001-02-08 04:19:27 -05:00
|
|
|
rb_define_method(rb_cRegexp, "options", rb_reg_options_m, 0);
|
2007-10-04 02:57:19 -04:00
|
|
|
rb_define_method(rb_cRegexp, "encoding", rb_obj_encoding, 0); /* in encoding.c */
|
2007-11-26 03:33:11 -05:00
|
|
|
rb_define_method(rb_cRegexp, "fixed_encoding?", rb_reg_fixed_encoding_p, 0);
|
2007-12-09 16:44:19 -05:00
|
|
|
rb_define_method(rb_cRegexp, "names", rb_reg_names, 0);
|
|
|
|
rb_define_method(rb_cRegexp, "named_captures", rb_reg_named_captures, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2005-02-17 09:43:38 -05:00
|
|
|
rb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(ONIG_OPTION_IGNORECASE));
|
|
|
|
rb_define_const(rb_cRegexp, "EXTENDED", INT2FIX(ONIG_OPTION_EXTEND));
|
|
|
|
rb_define_const(rb_cRegexp, "MULTILINE", INT2FIX(ONIG_OPTION_MULTILINE));
|
1999-08-13 01:45:20 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
rb_global_variable(®_cache);
|
|
|
|
|
2000-02-23 00:23:12 -05:00
|
|
|
rb_cMatch = rb_define_class("MatchData", rb_cObject);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_define_alloc_func(rb_cMatch, match_alloc);
|
1999-10-15 04:52:18 -04:00
|
|
|
rb_undef_method(CLASS_OF(rb_cMatch), "new");
|
|
|
|
|
2003-05-19 01:41:08 -04:00
|
|
|
rb_define_method(rb_cMatch, "initialize_copy", match_init_copy, 1);
|
2007-12-09 16:44:19 -05:00
|
|
|
rb_define_method(rb_cMatch, "regexp", match_regexp, 0);
|
|
|
|
rb_define_method(rb_cMatch, "names", match_names, 0);
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_define_method(rb_cMatch, "size", match_size, 0);
|
|
|
|
rb_define_method(rb_cMatch, "length", match_size, 0);
|
|
|
|
rb_define_method(rb_cMatch, "offset", match_offset, 1);
|
|
|
|
rb_define_method(rb_cMatch, "begin", match_begin, 1);
|
|
|
|
rb_define_method(rb_cMatch, "end", match_end, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cMatch, "to_a", match_to_a, 0);
|
|
|
|
rb_define_method(rb_cMatch, "[]", match_aref, -1);
|
2003-07-17 05:53:16 -04:00
|
|
|
rb_define_method(rb_cMatch, "captures", match_captures, 0);
|
2003-05-04 12:03:24 -04:00
|
|
|
rb_define_method(rb_cMatch, "values_at", match_values_at, -1);
|
2007-10-12 10:35:26 -04:00
|
|
|
rb_define_method(rb_cMatch, "select", match_values_at, -1);
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);
|
|
|
|
rb_define_method(rb_cMatch, "post_match", rb_reg_match_post, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cMatch, "to_s", match_to_s, 0);
|
2007-06-23 04:26:08 -04:00
|
|
|
rb_define_method(rb_cMatch, "inspect", match_inspect, 0);
|
2001-09-05 02:54:57 -04:00
|
|
|
rb_define_method(rb_cMatch, "string", match_string, 0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|