mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/strscan/strscan.c: document enhancement.
* ext/strscan/strscan.c: update copyright year. * ext/strscan/strscan.c: update coding style. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
51cb36cc0e
commit
d277603d5e
2 changed files with 42 additions and 50 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Sat Sep 24 21:19:39 2005 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* ext/strscan/strscan.c: document enhancement.
|
||||||
|
|
||||||
|
* ext/strscan/strscan.c: update copyright year.
|
||||||
|
|
||||||
|
* ext/strscan/strscan.c: update coding style.
|
||||||
|
|
||||||
Sat Sep 24 20:20:05 2005 Minero Aoki <aamine@loveruby.net>
|
Sat Sep 24 20:20:05 2005 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* test/net/http/test_http.rb (teardown): Net::HTTP.version_1_1 breaks
|
* test/net/http/test_http.rb (teardown): Net::HTTP.version_1_1 breaks
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
/*
|
/*
|
||||||
|
$Id$
|
||||||
|
|
||||||
strscan.c
|
Copyright (c) 1999-2005 Minero Aoki
|
||||||
|
|
||||||
Copyright (c) 1999-2004 Minero Aoki
|
|
||||||
|
|
||||||
This program is free software.
|
This program is free software.
|
||||||
You can distribute/modify this program under the terms of
|
You can distribute/modify this program under the terms of
|
||||||
the Ruby License. For details, see the file COPYING.
|
the Ruby License. For details, see the file COPYING.
|
||||||
|
|
||||||
$Id$
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
#include "re.h"
|
#include "re.h"
|
||||||
|
|
||||||
|
@ -154,12 +149,10 @@ extract_beg_len(p, beg_i, len)
|
||||||
return infect(rb_str_new(S_PBEG(p) + beg_i, len), p);
|
return infect(rb_str_new(S_PBEG(p) + beg_i, len), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* =======================================================================
|
/* =======================================================================
|
||||||
Constructor
|
Constructor
|
||||||
======================================================================= */
|
======================================================================= */
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
strscan_mark(p)
|
strscan_mark(p)
|
||||||
struct strscanner *p;
|
struct strscanner *p;
|
||||||
|
@ -251,7 +244,6 @@ strscan_init_copy(vself, vorig)
|
||||||
return vself;
|
return vself;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* =======================================================================
|
/* =======================================================================
|
||||||
Instance Methods
|
Instance Methods
|
||||||
======================================================================= */
|
======================================================================= */
|
||||||
|
@ -379,7 +371,7 @@ strscan_concat(self, str)
|
||||||
* value is zero. In the 'terminated' position (i.e. the string is exhausted),
|
* value is zero. In the 'terminated' position (i.e. the string is exhausted),
|
||||||
* this value is the length of the string.
|
* this value is the length of the string.
|
||||||
*
|
*
|
||||||
* In short, it's a 1-based index into the string.
|
* In short, it's a 0-based index into the string.
|
||||||
*
|
*
|
||||||
* s = StringScanner.new('test string')
|
* s = StringScanner.new('test string')
|
||||||
* s.pos # -> 0
|
* s.pos # -> 0
|
||||||
|
@ -423,7 +415,6 @@ strscan_set_pos(self, v)
|
||||||
return INT2NUM(i);
|
return INT2NUM(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* I should implement this function? */
|
/* I should implement this function? */
|
||||||
#define strscan_prepare_re(re) /* none */
|
#define strscan_prepare_re(re) /* none */
|
||||||
|
|
||||||
|
@ -475,13 +466,7 @@ strscan_do_scan(self, regex, succptr, getstr, headonly)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq: scan(pattern) => String
|
||||||
* scanner.scan(pattern) => String
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* call-seq: scan(pattern)
|
|
||||||
*
|
*
|
||||||
* Tries to match with +pattern+ at the current position. If there's a match,
|
* Tries to match with +pattern+ at the current position. If there's a match,
|
||||||
* the scanner advances the "scan pointer" and returns the matched string.
|
* the scanner advances the "scan pointer" and returns the matched string.
|
||||||
|
@ -583,7 +568,6 @@ strscan_scan_full(self, re, s, f)
|
||||||
return strscan_do_scan(self, re, RTEST(s), RTEST(f), 1);
|
return strscan_do_scan(self, re, RTEST(s), RTEST(f), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq: scan_until(pattern)
|
* call-seq: scan_until(pattern)
|
||||||
*
|
*
|
||||||
|
@ -692,11 +676,17 @@ adjust_registers_to_matched(p)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scans one character and returns it.
|
* Scans one character and returns it.
|
||||||
|
* This method is multibyte character sensitive.
|
||||||
*
|
*
|
||||||
* s = StringScanner.new('ab')
|
* s = StringScanner.new("ab")
|
||||||
* s.getch # => "a"
|
* s.getch # => "a"
|
||||||
* s.getch # => "b"
|
* s.getch # => "b"
|
||||||
* s.getch # => nil
|
* s.getch # => nil
|
||||||
|
*
|
||||||
|
* $KCODE = 'EUC'
|
||||||
|
* s = StringScanner.new("\244\242")
|
||||||
|
* s.getch # => "\244\242" # Japanese hira-kana "A" in EUC-JP
|
||||||
|
* s.getch # => nil
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
strscan_getch(self)
|
strscan_getch(self)
|
||||||
|
@ -711,8 +701,9 @@ strscan_getch(self)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
|
||||||
len = mbclen(*CURPTR(p));
|
len = mbclen(*CURPTR(p));
|
||||||
if (p->curr + len > S_LEN(p))
|
if (p->curr + len > S_LEN(p)) {
|
||||||
len = S_LEN(p) - p->curr;
|
len = S_LEN(p) - p->curr;
|
||||||
|
}
|
||||||
p->prev = p->curr;
|
p->prev = p->curr;
|
||||||
p->curr += len;
|
p->curr += len;
|
||||||
MATCHED(p);
|
MATCHED(p);
|
||||||
|
@ -722,12 +713,20 @@ strscan_getch(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scans one byte and returns it. Similar to, but not the same as, #getch.
|
* Scans one byte and returns it.
|
||||||
|
* This method is not multibyte character sensitive.
|
||||||
|
* See also: #getch.
|
||||||
*
|
*
|
||||||
* s = StringScanner.new('ab')
|
* s = StringScanner.new('ab')
|
||||||
* s.get_byte # => "a"
|
* s.get_byte # => "a"
|
||||||
* s.get_byte # => "b"
|
* s.get_byte # => "b"
|
||||||
* s.get_byte # => nil
|
* s.get_byte # => nil
|
||||||
|
*
|
||||||
|
* $KCODE = 'EUC'
|
||||||
|
* s = StringScanner.new("\244\242")
|
||||||
|
* s.get_byte # => "\244"
|
||||||
|
* s.get_byte # => "\242"
|
||||||
|
* s.get_byte # => nil
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
strscan_get_byte(self)
|
strscan_get_byte(self)
|
||||||
|
@ -810,7 +809,7 @@ strscan_peep(self, vlen)
|
||||||
* s.unscan
|
* s.unscan
|
||||||
* s.scan(/../) # => "te"
|
* s.scan(/../) # => "te"
|
||||||
* s.scan(/\d/) # => nil
|
* s.scan(/\d/) # => nil
|
||||||
* s.unscan # ScanError: can't unscan: prev match had failed
|
* s.unscan # ScanError: unscan failed: previous match record not exist
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
strscan_unscan(self)
|
strscan_unscan(self)
|
||||||
|
@ -820,8 +819,7 @@ strscan_unscan(self)
|
||||||
|
|
||||||
GET_SCANNER(self, p);
|
GET_SCANNER(self, p);
|
||||||
if (! MATCHED_P(p))
|
if (! MATCHED_P(p))
|
||||||
rb_raise(ScanError, "can't unscan: prev match had failed");
|
rb_raise(ScanError, "unscan failed: previous match record not exist");
|
||||||
|
|
||||||
p->curr = p->prev;
|
p->curr = p->prev;
|
||||||
CLEAR_MATCH_STATUS(p);
|
CLEAR_MATCH_STATUS(p);
|
||||||
return self;
|
return self;
|
||||||
|
@ -868,10 +866,7 @@ strscan_eos_p(self)
|
||||||
struct strscanner *p;
|
struct strscanner *p;
|
||||||
|
|
||||||
GET_SCANNER(self, p);
|
GET_SCANNER(self, p);
|
||||||
if (EOS_P(p))
|
return EOS_P(p) ? Qtrue : Qfalse;
|
||||||
return Qtrue;
|
|
||||||
else
|
|
||||||
return Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -901,10 +896,7 @@ strscan_rest_p(self)
|
||||||
struct strscanner *p;
|
struct strscanner *p;
|
||||||
|
|
||||||
GET_SCANNER(self, p);
|
GET_SCANNER(self, p);
|
||||||
if (EOS_P(p))
|
return EOS_P(p) ? Qfalse : Qtrue;
|
||||||
return Qfalse;
|
|
||||||
else
|
|
||||||
return Qtrue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -923,10 +915,7 @@ strscan_matched_p(self)
|
||||||
struct strscanner *p;
|
struct strscanner *p;
|
||||||
|
|
||||||
GET_SCANNER(self, p);
|
GET_SCANNER(self, p);
|
||||||
if (MATCHED_P(p))
|
return MATCHED_P(p) ? Qtrue : Qfalse;
|
||||||
return Qtrue;
|
|
||||||
else
|
|
||||||
return Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -944,7 +933,6 @@ strscan_matched(self)
|
||||||
|
|
||||||
GET_SCANNER(self, p);
|
GET_SCANNER(self, p);
|
||||||
if (! MATCHED_P(p)) return Qnil;
|
if (! MATCHED_P(p)) return Qnil;
|
||||||
|
|
||||||
return extract_range(p, p->prev + p->regs.beg[0],
|
return extract_range(p, p->prev + p->regs.beg[0],
|
||||||
p->prev + p->regs.end[0]);
|
p->prev + p->regs.end[0]);
|
||||||
}
|
}
|
||||||
|
@ -967,7 +955,6 @@ strscan_matched_size(self)
|
||||||
|
|
||||||
GET_SCANNER(self, p);
|
GET_SCANNER(self, p);
|
||||||
if (! MATCHED_P(p)) return Qnil;
|
if (! MATCHED_P(p)) return Qnil;
|
||||||
|
|
||||||
return INT2NUM(p->regs.end[0] - p->regs.beg[0]);
|
return INT2NUM(p->regs.end[0] - p->regs.beg[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1035,7 +1022,6 @@ strscan_pre_match(self)
|
||||||
|
|
||||||
GET_SCANNER(self, p);
|
GET_SCANNER(self, p);
|
||||||
if (! MATCHED_P(p)) return Qnil;
|
if (! MATCHED_P(p)) return Qnil;
|
||||||
|
|
||||||
return extract_range(p, 0, p->prev + p->regs.beg[0]);
|
return extract_range(p, 0, p->prev + p->regs.beg[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1056,7 +1042,6 @@ strscan_post_match(self)
|
||||||
|
|
||||||
GET_SCANNER(self, p);
|
GET_SCANNER(self, p);
|
||||||
if (! MATCHED_P(p)) return Qnil;
|
if (! MATCHED_P(p)) return Qnil;
|
||||||
|
|
||||||
return extract_range(p, p->prev + p->regs.end[0], S_LEN(p));
|
return extract_range(p, p->prev + p->regs.end[0], S_LEN(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1091,7 +1076,6 @@ strscan_rest_size(self)
|
||||||
if (EOS_P(p)) {
|
if (EOS_P(p)) {
|
||||||
return INT2FIX(0);
|
return INT2FIX(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
i = S_LEN(p) - p->curr;
|
i = S_LEN(p) - p->curr;
|
||||||
return INT2FIX(i);
|
return INT2FIX(i);
|
||||||
}
|
}
|
||||||
|
@ -1261,7 +1245,7 @@ inspect2(p)
|
||||||
* === Advancing the Scan Pointer
|
* === Advancing the Scan Pointer
|
||||||
*
|
*
|
||||||
* - #getch
|
* - #getch
|
||||||
* - #getbyte
|
* - #get_byte
|
||||||
* - #scan
|
* - #scan
|
||||||
* - #scan_until
|
* - #scan_until
|
||||||
* - #skip
|
* - #skip
|
||||||
|
@ -1277,7 +1261,7 @@ inspect2(p)
|
||||||
*
|
*
|
||||||
* === Finding Where we Are
|
* === Finding Where we Are
|
||||||
*
|
*
|
||||||
* - #bol?
|
* - #beginning_of_line? (#bol?)
|
||||||
* - #eos?
|
* - #eos?
|
||||||
* - #rest?
|
* - #rest?
|
||||||
* - #rest_size
|
* - #rest_size
|
||||||
|
@ -1363,7 +1347,7 @@ Init_strscan()
|
||||||
rb_define_method(StringScanner, "unscan", strscan_unscan, 0);
|
rb_define_method(StringScanner, "unscan", strscan_unscan, 0);
|
||||||
|
|
||||||
rb_define_method(StringScanner, "beginning_of_line?", strscan_bol_p, 0);
|
rb_define_method(StringScanner, "beginning_of_line?", strscan_bol_p, 0);
|
||||||
rb_define_method(StringScanner, "bol?", strscan_bol_p, 0);
|
rb_alias(StringScanner, rb_intern("bol?"), rb_intern("beginning_of_line?"));
|
||||||
rb_define_method(StringScanner, "eos?", strscan_eos_p, 0);
|
rb_define_method(StringScanner, "eos?", strscan_eos_p, 0);
|
||||||
rb_define_method(StringScanner, "empty?", strscan_empty_p, 0);
|
rb_define_method(StringScanner, "empty?", strscan_empty_p, 0);
|
||||||
rb_define_method(StringScanner, "rest?", strscan_rest_p, 0);
|
rb_define_method(StringScanner, "rest?", strscan_rest_p, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue