15 #define STRSCAN_VERSION "0.7.0"
18 # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
19 # define RB_OBJ_STRING(obj) (obj)
21 # define PRIsVALUE "s"
22 # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
23 # define RB_OBJ_STRING(obj) StringValueCStr(obj)
37 #define FLAG_MATCHED (1 << 0)
50 #define MATCHED_P(s) ((s)->flags & FLAG_MATCHED)
51 #define MATCHED(s) (s)->flags |= FLAG_MATCHED
52 #define CLEAR_MATCH_STATUS(s) (s)->flags &= ~FLAG_MATCHED
54 #define S_PBEG(s) (RSTRING_PTR((s)->str))
55 #define S_LEN(s) (RSTRING_LEN((s)->str))
56 #define S_PEND(s) (S_PBEG(s) + S_LEN(s))
57 #define CURPTR(s) (S_PBEG(s) + (s)->curr)
58 #define S_RESTLEN(s) (S_LEN(s) - (s)->curr)
60 #define EOS_P(s) ((s)->curr >= RSTRING_LEN(p->str))
62 #define GET_SCANNER(obj,var) do {\
63 Data_Get_Struct((obj), struct strscanner, (var));\
64 if (NIL_P((var)->str)) rb_raise(rb_eArgError, "uninitialized StringScanner object");\
91 int succptr,
int getstr,
int headonly));
150 if (end_i >
S_LEN(p))
159 if (beg_i + len >
S_LEN(p))
160 len =
S_LEN(p) - beg_i;
219 "wrong argument type %s (expected StringScanner)",
240 self->flags = orig->
flags;
241 self->str = orig->
str;
242 self->prev = orig->
prev;
243 self->curr = orig->
curr;
304 rb_warning(
"StringScanner#clear is obsolete; use #terminate instead");
404 if (i < 0) i +=
S_LEN(p);
428 tmpreg = re !=
RREGEXP(regex)->ptr;
429 if (!tmpreg)
RREGEXP(regex)->usecnt++;
442 if (!tmpreg)
RREGEXP(regex)->usecnt--;
748 rb_warning(
"StringScanner#getbyte is obsolete; use #get_byte instead");
787 rb_warning(
"StringScanner#peep is obsolete; use #peek instead");
864 rb_warning(
"StringScanner#empty? is obsolete; use #eos? instead");
967 if (i < 0)
return Qnil;
1053 rb_warning(
"StringScanner#restsize is obsolete; use #rest_size instead");
1057 #define INSPECT_LENGTH 5
1112 strcpy(bp,
"..."); bp += 3;
1261 tmp =
rb_str_new2(
"$Id: strscan.c 44754 2014-01-30 03:49:07Z usa $");
static VALUE strscan_match_p(VALUE self, VALUE re)
static VALUE strscan_set_pos(VALUE self, VALUE v)
static long NUM2LONG(VALUE x)
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)
#define Data_Get_Struct(obj, type, sval)
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_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 VALUE strscan_rest(VALUE self)
static VALUE INT2NUM(int v)
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,...)
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)
#define RB_OBJ_CLASSNAME(obj)
static VALUE strscan_matched_size(VALUE self)
long onig_match(regex_t *reg, const UChar *str, const UChar *end, const UChar *at, OnigRegion *region, OnigOptionType option)
rb_alias(klass, key_id, value_id)
static VALUE strscan_bol_p(VALUE self)
const char * rb_obj_classname(VALUE)
static VALUE strscan_inspect(VALUE self)
static VALUE strscan_scan(VALUE self, VALUE re)
static VALUE strscan_restsize(VALUE self)
return rb_str_append(rb_str_new2(cmd_id_head), id_num)
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)
return Data_Wrap_Struct(CLASS_OF(interp), 0, ip_free, slave)
void onig_region_init(OnigRegion *region)
RUBY_EXTERN VALUE rb_cObject
static VALUE strscan_scan_full(VALUE self, VALUE re, VALUE s, VALUE f)
long onig_search(regex_t *reg, const UChar *str, const UChar *end, const UChar *start, const UChar *range, OnigRegion *region, OnigOptionType option)
static VALUE strscan_check(VALUE self, VALUE re)
VALUE rb_str_cat2(VALUE, const char *)
static VALUE infect(VALUE str, struct strscanner *p)
static void strscan_free(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)
unsigned char buf[MIME_BUF_SIZE]
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)
static VALUE strscan_peek(VALUE self, VALUE vlen)
static VALUE strscan_s_allocate(VALUE klass)
register unsigned int len
static VALUE strscan_aref(VALUE self, VALUE idx)
#define GET_SCANNER(obj, var)
#define RB_OBJ_STRING(obj)
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)
static VALUE strscan_scan_until(VALUE self, VALUE re)
static VALUE strscan_get_string(VALUE self)
void(* RUBY_DATA_FUNC)(void *)
static VALUE strscan_pre_match(VALUE self)
static VALUE inspect1(struct strscanner *p)
regex_t * rb_reg_prepare_re(VALUE re, VALUE str)
rb_const_set(self, ID_SUBST_INFO, cbsubst_obj)
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)
VALUE rb_obj_freeze(VALUE)
static VALUE strscan_empty_p(VALUE self)
static VALUE StringScanner
static void strscan_mark(struct strscanner *p)
void check_strscan(VALUE obj)
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_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_str_new(const char *, long)