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));
144 if (end_i >
S_LEN(p))
153 if (beg_i + len >
S_LEN(p))
154 len =
S_LEN(p) - beg_i;
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");
436 if (i < 0) i +=
S_LEN(p);
460 tmpreg = re !=
RREGEXP(regex)->ptr;
461 if (!tmpreg)
RREGEXP(regex)->usecnt++;
474 if (!tmpreg)
RREGEXP(regex)->usecnt--;
780 rb_warning(
"StringScanner#getbyte is obsolete; use #get_byte instead");
819 rb_warning(
"StringScanner#peep is obsolete; use #peek instead");
896 rb_warning(
"StringScanner#empty? is obsolete; use #eos? instead");
999 if (i < 0)
return Qnil;
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)
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)
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_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,...)
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)
VALUE rb_str_append(VALUE, VALUE)
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)
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)
VALUE rb_str_cat2(VALUE, const char *)
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)
#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)
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)
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)