16 #define STRSCAN_VERSION "0.7.0" 30 #define FLAG_MATCHED (1 << 0) 43 #define MATCHED_P(s) ((s)->flags & FLAG_MATCHED) 44 #define MATCHED(s) (s)->flags |= FLAG_MATCHED 45 #define CLEAR_MATCH_STATUS(s) (s)->flags &= ~FLAG_MATCHED 47 #define S_PBEG(s) (RSTRING_PTR((s)->str)) 48 #define S_LEN(s) (RSTRING_LEN((s)->str)) 49 #define S_PEND(s) (S_PBEG(s) + S_LEN(s)) 50 #define CURPTR(s) (S_PBEG(s) + (s)->curr) 51 #define S_RESTLEN(s) (S_LEN(s) - (s)->curr) 53 #define EOS_P(s) ((s)->curr >= RSTRING_LEN(p->str)) 55 #define GET_SCANNER(obj,var) do {\ 56 (var) = check_strscan(obj);\ 57 if (NIL_P((var)->str)) rb_raise(rb_eArgError, "uninitialized StringScanner object");\ 85 int succptr,
int getstr,
int headonly));
153 if (beg_i + len >
S_LEN(
p))
247 self->flags = orig->
flags;
248 self->str = orig->
str;
249 self->prev = orig->
prev;
250 self->curr = orig->
curr;
311 rb_warning(
"StringScanner#clear is obsolete; use #terminate instead");
460 tmpreg = re !=
RREGEXP(regex)->ptr;
461 if (!tmpreg)
RREGEXP(regex)->usecnt++;
474 if (!tmpreg)
RREGEXP(regex)->usecnt--;
494 p->curr +=
p->regs.end[0];
728 if (
p->curr + len >
S_LEN(
p)) {
736 p->prev +
p->regs.end[0]);
770 p->prev +
p->regs.end[0]);
780 rb_warning(
"StringScanner#getbyte is obsolete; use #get_byte instead");
819 rb_warning(
"StringScanner#peep is obsolete; use #peek instead");
866 if (
p->curr == 0)
return Qtrue;
896 rb_warning(
"StringScanner#empty? is obsolete; use #eos? instead");
950 p->prev +
p->regs.end[0]);
970 return INT2NUM(
p->regs.end[0] -
p->regs.beg[0]);
998 i +=
p->regs.num_regs;
999 if (
i < 0)
return Qnil;
1000 if (
i >=
p->regs.num_regs)
return Qnil;
1001 if (
p->regs.beg[
i] == -1)
return Qnil;
1004 p->prev +
p->regs.end[
i]);
1085 rb_warning(
"StringScanner#restsize is obsolete; use #rest_size instead");
1089 #define INSPECT_LENGTH 5 1295 tmp =
rb_str_new2(
"$Id: strscan.c 44659 2014-01-19 16:28:53Z nagachika $");
static VALUE strscan_match_p(VALUE self, VALUE re)
static VALUE strscan_set_pos(VALUE self, VALUE v)
static size_t strscan_memsize(const void *ptr)
static VALUE strscan_rest_size(VALUE self)
static VALUE strscan_set_string(VALUE self, VALUE str)
VALUE rb_str_length(VALUE)
static VALUE infect _((VALUE str, struct strscanner *p))
void rb_enc_copy(VALUE obj1, VALUE obj2)
static VALUE strscan_eos_p(VALUE self)
static VALUE strscan_matched_p(VALUE self)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
static VALUE strscan_getbyte(VALUE self)
static VALUE strscan_clear(VALUE self)
static VALUE str_new(struct strscanner *p, const char *ptr, long len)
VALUE rb_str_cat(VALUE, const char *, long)
static VALUE strscan_get_charpos(VALUE self)
#define TypedData_Wrap_Struct(klass, data_type, sval)
static VALUE strscan_post_match(VALUE self)
void onig_region_copy(OnigRegion *to, OnigRegion *from)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define CLEAR_MATCH_STATUS(s)
static void strscan_mark(void *ptr)
static const rb_data_type_t strscanner_type
static VALUE strscan_rest(VALUE self)
static VALUE strscan_get_byte(VALUE self)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
void onig_region_clear(OnigRegion *region)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
int rb_const_defined(VALUE, ID)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
static struct strscanner * check_strscan(VALUE obj)
void rb_gc_mark(VALUE ptr)
static VALUE strscan_matched_size(VALUE self)
static VALUE strscan_bol_p(VALUE self)
static VALUE strscan_inspect(VALUE self)
static VALUE strscan_scan(VALUE self, VALUE re)
static VALUE strscan_restsize(VALUE self)
static VALUE strscan_check_until(VALUE self, VALUE re)
#define MEMZERO(p, type, n)
int onig_region_set(OnigRegion *region, int at, int beg, int end)
void onig_region_init(OnigRegion *region)
RUBY_EXTERN VALUE rb_cObject
static VALUE strscan_scan_full(VALUE self, VALUE re, VALUE s, VALUE f)
static VALUE strscan_check(VALUE self, VALUE re)
VALUE rb_str_cat2(VALUE, const char *)
static VALUE infect(VALUE str, struct strscanner *p)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE strscan_get_pos(VALUE self)
void onig_region_free(OnigRegion *r, int free_self)
static VALUE inspect2(struct strscanner *p)
size_t onig_region_memsize(const OnigRegion *regs)
static VALUE strscan_terminate(VALUE self)
static VALUE strscan_matched(VALUE self)
static VALUE strscan_reset(VALUE self)
static VALUE strscan_getch(VALUE self)
static VALUE strscan_unscan(VALUE self)
static VALUE strscan_concat(VALUE self, VALUE str)
static VALUE extract_range(struct strscanner *p, long beg_i, long end_i)
VALUE rb_sprintf(const char *format,...)
static VALUE strscan_init_copy(VALUE vself, VALUE vorig)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE strscan_exist_p(VALUE self, VALUE re)
static VALUE strscan_rest_p(VALUE self)
void rb_const_set(VALUE, ID, VALUE)
static VALUE strscan_peek(VALUE self, VALUE vlen)
static VALUE strscan_s_allocate(VALUE klass)
void rb_alias(VALUE, ID, ID)
static VALUE strscan_aref(VALUE self, VALUE idx)
VALUE rb_str_new_cstr(const char *)
#define GET_SCANNER(obj, var)
static VALUE extract_beg_len(struct strscanner *p, long beg_i, long len)
rb_encoding * rb_enc_get(VALUE obj)
static void adjust_registers_to_matched(struct strscanner *p)
OnigPosition onig_search(regex_t *reg, const UChar *str, const UChar *end, const UChar *start, const UChar *range, OnigRegion *region, OnigOptionType option)
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
static VALUE strscan_scan_until(VALUE self, VALUE re)
OnigPosition onig_match(regex_t *reg, const UChar *str, const UChar *end, const UChar *at, OnigRegion *region, OnigOptionType option)
static VALUE strscan_get_string(VALUE self)
static void strscan_free(void *ptr)
static VALUE strscan_pre_match(VALUE self)
static VALUE inspect1(struct strscanner *p)
regex_t * rb_reg_prepare_re(VALUE re, VALUE str)
static VALUE strscan_search_full(VALUE self, VALUE re, VALUE s, VALUE f)
void rb_warning(const char *fmt,...)
static VALUE strscan_peep(VALUE self, VALUE vlen)
static VALUE strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
VALUE rb_obj_freeze(VALUE)
static VALUE strscan_empty_p(VALUE self)
static VALUE StringScanner
void onig_free(regex_t *reg)
static VALUE strscan_skip(VALUE self, VALUE re)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
VALUE rb_str_new2(const char *)
static VALUE strscan_initialize(int argc, VALUE *argv, VALUE self)
static VALUE strscan_s_mustc(VALUE self)
static VALUE strscan_skip_until(VALUE self, VALUE re)
VALUE rb_obj_class(VALUE)
VALUE rb_str_new(const char *, long)