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");\ 67 static inline long minl _((
const long n,
const long x));
89 int succptr,
int getstr,
int headonly));
145 minl(
const long x,
const long y)
147 return (x < y) ? x : y;
251 self->flags = orig->
flags;
252 self->str = orig->
str;
253 self->prev = orig->
prev;
254 self->curr = orig->
curr;
317 rb_warning(
"StringScanner#clear is obsolete; use #terminate instead");
442 if (i < 0) i +=
S_LEN(p);
469 if (!tmpreg)
RREGEXP(regex)->usecnt++;
482 if (!tmpreg)
RREGEXP(regex)->usecnt--;
786 rb_warning(
"StringScanner#getbyte is obsolete; use #get_byte instead");
824 rb_warning(
"StringScanner#peep is obsolete; use #peek instead");
901 rb_warning(
"StringScanner#empty? is obsolete; use #eos? instead");
984 (
const unsigned char* )name, (
const unsigned char* )name_end, regs);
1032 switch (
TYPE(idx)) {
1047 if (i < 0)
return Qnil;
1133 rb_warning(
"StringScanner#restsize is obsolete; use #rest_size instead");
1137 #define INSPECT_LENGTH 5 1342 tmp =
rb_str_new2(
"$Id: strscan.c 59506 2017-08-04 15:55:45Z 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)
void rb_enc_copy(VALUE obj1, VALUE obj2)
#define RUBY_TYPED_FREE_IMMEDIATELY
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.
ONIG_EXTERN void onig_region_clear(OnigRegion *region)
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 int name_to_backref_number(struct re_registers *regs, VALUE regexp, const char *name, const char *name_end, rb_encoding *enc)
static VALUE strscan_get_charpos(VALUE self)
static VALUE strscan_post_match(VALUE self)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static long minl _((const long n, const long x))
#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)
ONIG_EXTERN void onig_region_free(OnigRegion *region, int free_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,...)
#define RSTRING_GETMEM(str, ptrvar, lenvar)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
int rb_const_defined(VALUE, ID)
ONIG_EXTERN void onig_free(OnigRegex)
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)
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 *)
ONIG_EXTERN int onig_name_to_backref_number(OnigRegex reg, const OnigUChar *name, const OnigUChar *name_end, const OnigRegion *region)
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)
static VALUE inspect2(struct strscanner *p)
size_t onig_region_memsize(const OnigRegion *regs)
ONIG_EXTERN int onig_region_set(OnigRegion *region, int at, int beg, int end)
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
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 long minl(const long x, const long y)
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)
ONIG_EXTERN OnigPosition onig_search(OnigRegex, const OnigUChar *str, const OnigUChar *end, const OnigUChar *start, const OnigUChar *range, OnigRegion *region, OnigOptionType option)
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)
register unsigned int len
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)
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
static VALUE strscan_scan_until(VALUE self, VALUE re)
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)
#define TypedData_Make_Struct(klass, type, data_type, sval)
static VALUE strscan_search_full(VALUE self, VALUE re, VALUE s, VALUE f)
int rb_reg_region_copy(struct re_registers *, const struct re_registers *)
ONIG_EXTERN OnigPosition onig_match(OnigRegex, const OnigUChar *str, const OnigUChar *end, const OnigUChar *at, OnigRegion *region, OnigOptionType option)
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
static VALUE strscan_skip(VALUE self, VALUE re)
ONIG_EXTERN void onig_region_init(OnigRegion *region)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
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)