16 #define STRSCAN_VERSION "0.7.0"
30 #define FLAG_MATCHED (1 << 0)
46 #define MATCHED_P(s) ((s)->flags & FLAG_MATCHED)
47 #define MATCHED(s) (s)->flags |= FLAG_MATCHED
48 #define CLEAR_MATCH_STATUS(s) (s)->flags &= ~FLAG_MATCHED
50 #define S_PBEG(s) (RSTRING_PTR((s)->str))
51 #define S_LEN(s) (RSTRING_LEN((s)->str))
52 #define S_PEND(s) (S_PBEG(s) + S_LEN(s))
53 #define CURPTR(s) (S_PBEG(s) + (s)->curr)
54 #define S_RESTLEN(s) (S_LEN(s) - (s)->curr)
56 #define EOS_P(s) ((s)->curr >= RSTRING_LEN(p->str))
58 #define GET_SCANNER(obj,var) do {\
59 (var) = check_strscan(obj);\
60 if (NIL_P((var)->str)) rb_raise(rb_eArgError, "uninitialized StringScanner object");\
88 int succptr,
int getstr,
int headonly));
147 if (end_i >
S_LEN(p))
156 if (beg_i + len >
S_LEN(p))
157 len =
S_LEN(p) - beg_i;
251 self->flags = orig->
flags;
252 self->str = orig->
str;
253 self->prev = orig->
prev;
254 self->curr = orig->
curr;
315 rb_warning(
"StringScanner#clear is obsolete; use #terminate instead");
440 if (i < 0) i +=
S_LEN(p);
466 tmpreg = re !=
RREGEXP(regex)->ptr;
467 if (!tmpreg)
RREGEXP(regex)->usecnt++;
480 if (!tmpreg)
RREGEXP(regex)->usecnt--;
786 rb_warning(
"StringScanner#getbyte is obsolete; use #get_byte instead");
825 rb_warning(
"StringScanner#peep is obsolete; use #peek instead");
902 rb_warning(
"StringScanner#empty? is obsolete; use #eos? instead");
985 (
const unsigned char* )name, (
const unsigned char* )name_end, regs);
1034 switch (
TYPE(idx)) {
1037 goto name_to_backref;
1050 if (i < 0)
return Qnil;
1136 rb_warning(
"StringScanner#restsize is obsolete; use #rest_size instead");
1140 #define INSPECT_LENGTH 5
1346 tmp =
rb_str_new2(
"$Id: strscan.c 44903 2014-02-10 11:45:14Z naruse $");
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)
void rb_enc_copy(VALUE obj1, VALUE obj2)
size_t strlen(const char *)
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)
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
static VALUE strscan_get_charpos(VALUE self)
static VALUE strscan_post_match(VALUE self)
void onig_region_copy(OnigRegion *to, OnigRegion *from)
VALUE rb_str_new_cstr(const char *)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_obj_freeze(VALUE)
#define CLEAR_MATCH_STATUS(s)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
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_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,...)
VALUE rb_obj_class(VALUE)
void onig_region_clear(OnigRegion *region)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
static struct strscanner * check_strscan(VALUE obj)
static VALUE strscan_matched_size(VALUE self)
static VALUE strscan_bol_p(VALUE self)
static VALUE strscan_inspect(VALUE self)
#define MEMZERO(p, type, n)
static VALUE strscan_scan(VALUE self, VALUE re)
static VALUE strscan_restsize(VALUE self)
static VALUE strscan_check_until(VALUE self, VALUE re)
int onig_region_set(OnigRegion *region, int at, int beg, int end)
void onig_region_init(OnigRegion *region)
#define StringValuePtr(v)
static VALUE strscan_scan_full(VALUE self, VALUE re, VALUE s, VALUE f)
static VALUE strscan_check(VALUE self, VALUE re)
static VALUE infect(VALUE str, struct strscanner *p)
static int name_to_backref_number(struct re_registers *regs, VALUE regexp, const char *name, const char *name_end)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
int onig_name_to_backref_number(regex_t *reg, const UChar *name, const UChar *name_end, OnigRegion *region)
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)
#define TypedData_Wrap_Struct(klass, data_type, sval)
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,...)
int rb_const_defined(VALUE, ID)
#define RUBY_TYPED_FREE_IMMEDIATELY
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)
void rb_alias(VALUE, ID, ID)
static VALUE strscan_peek(VALUE self, VALUE vlen)
static VALUE strscan_s_allocate(VALUE klass)
static VALUE strscan_aref(VALUE self, VALUE idx)
#define GET_SCANNER(obj, var)
static VALUE extract_beg_len(struct strscanner *p, long beg_i, long len)
VALUE rb_str_cat(VALUE, const char *, long)
VALUE rb_str_length(VALUE)
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)
RUBY_EXTERN VALUE rb_cObject
regex_t * rb_reg_prepare_re(VALUE re, VALUE str)
VALUE rb_str_new(const char *, long)
static VALUE strscan_search_full(VALUE self, VALUE re, VALUE s, VALUE f)
const char * rb_id2name(ID id)
static struct tcltkip *VALUE self
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)
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)
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)