Ruby  2.4.2p198(2017-09-14revision59899)
Data Structures | Macros | Functions | Variables
strscan.c File Reference
#include "ruby/ruby.h"
#include "ruby/re.h"
#include "ruby/encoding.h"
#include "regint.h"
Include dependency graph for strscan.c:

Go to the source code of this file.

Data Structures

struct  strscanner
 

Macros

#define STRSCAN_VERSION   "0.7.0"
 
#define FLAG_MATCHED   (1 << 0)
 
#define MATCHED_P(s)   ((s)->flags & FLAG_MATCHED)
 
#define MATCHED(s)   (s)->flags |= FLAG_MATCHED
 
#define CLEAR_MATCH_STATUS(s)   (s)->flags &= ~FLAG_MATCHED
 
#define S_PBEG(s)   (RSTRING_PTR((s)->str))
 
#define S_LEN(s)   (RSTRING_LEN((s)->str))
 
#define S_PEND(s)   (S_PBEG(s) + S_LEN(s))
 
#define CURPTR(s)   (S_PBEG(s) + (s)->curr)
 
#define S_RESTLEN(s)   (S_LEN(s) - (s)->curr)
 
#define EOS_P(s)   ((s)->curr >= RSTRING_LEN(p->str))
 
#define GET_SCANNER(obj, var)
 
#define INSPECT_LENGTH   5
 

Functions

static long minl _ ((const long n, const long x))
 
static VALUE infect _ ((VALUE str, struct strscanner *p))
 
static VALUE extract_range _ ((struct strscanner *p, long beg_i, long end_i))
 
static VALUE extract_beg_len _ ((struct strscanner *p, long beg_i, long len))
 
static struct strscanner *check_strscan _ ((VALUE obj))
 
static void strscan_mark _ ((void *p))
 
static size_t strscan_memsize _ ((const void *p))
 
static VALUE strscan_s_allocate _ ((VALUE klass))
 
static VALUE strscan_initialize _ ((int argc, VALUE *argv, VALUE self))
 
static VALUE strscan_init_copy _ ((VALUE vself, VALUE vorig))
 
static VALUE strscan_s_mustc _ ((VALUE self))
 
static VALUE strscan_set_string _ ((VALUE self, VALUE str))
 
static VALUE strscan_set_pos _ ((VALUE self, VALUE pos))
 
static VALUE strscan_do_scan _ ((VALUE self, VALUE regex, int succptr, int getstr, int headonly))
 
static VALUE strscan_scan _ ((VALUE self, VALUE re))
 
static VALUE strscan_scan_full _ ((VALUE self, VALUE re, VALUE succp, VALUE getp))
 
static void adjust_registers_to_matched _ ((struct strscanner *p))
 
static VALUE strscan_peek _ ((VALUE self, VALUE len))
 
static VALUE strscan_aref _ ((VALUE self, VALUE idx))
 
static VALUE infect (VALUE str, struct strscanner *p)
 
static VALUE str_new (struct strscanner *p, const char *ptr, long len)
 
static long minl (const long x, const long y)
 
static VALUE extract_range (struct strscanner *p, long beg_i, long end_i)
 
static VALUE extract_beg_len (struct strscanner *p, long beg_i, long len)
 
static void strscan_mark (void *ptr)
 
static void strscan_free (void *ptr)
 
static size_t strscan_memsize (const void *ptr)
 
static VALUE strscan_s_allocate (VALUE klass)
 
static VALUE strscan_initialize (int argc, VALUE *argv, VALUE self)
 
static struct strscannercheck_strscan (VALUE obj)
 
static VALUE strscan_init_copy (VALUE vself, VALUE vorig)
 
static VALUE strscan_s_mustc (VALUE self)
 
static VALUE strscan_reset (VALUE self)
 
static VALUE strscan_terminate (VALUE self)
 
static VALUE strscan_clear (VALUE self)
 
static VALUE strscan_get_string (VALUE self)
 
static VALUE strscan_set_string (VALUE self, VALUE str)
 
static VALUE strscan_concat (VALUE self, VALUE str)
 
static VALUE strscan_get_pos (VALUE self)
 
static VALUE strscan_get_charpos (VALUE self)
 
static VALUE strscan_set_pos (VALUE self, VALUE v)
 
static VALUE strscan_do_scan (VALUE self, VALUE regex, int succptr, int getstr, int headonly)
 
static VALUE strscan_scan (VALUE self, VALUE re)
 
static VALUE strscan_match_p (VALUE self, VALUE re)
 
static VALUE strscan_skip (VALUE self, VALUE re)
 
static VALUE strscan_check (VALUE self, VALUE re)
 
static VALUE strscan_scan_full (VALUE self, VALUE re, VALUE s, VALUE f)
 
static VALUE strscan_scan_until (VALUE self, VALUE re)
 
static VALUE strscan_exist_p (VALUE self, VALUE re)
 
static VALUE strscan_skip_until (VALUE self, VALUE re)
 
static VALUE strscan_check_until (VALUE self, VALUE re)
 
static VALUE strscan_search_full (VALUE self, VALUE re, VALUE s, VALUE f)
 
static void adjust_registers_to_matched (struct strscanner *p)
 
static VALUE strscan_getch (VALUE self)
 
static VALUE strscan_get_byte (VALUE self)
 
static VALUE strscan_getbyte (VALUE self)
 
static VALUE strscan_peek (VALUE self, VALUE vlen)
 
static VALUE strscan_peep (VALUE self, VALUE vlen)
 
static VALUE strscan_unscan (VALUE self)
 
static VALUE strscan_bol_p (VALUE self)
 
static VALUE strscan_eos_p (VALUE self)
 
static VALUE strscan_empty_p (VALUE self)
 
static VALUE strscan_rest_p (VALUE self)
 
static VALUE strscan_matched_p (VALUE self)
 
static VALUE strscan_matched (VALUE self)
 
static VALUE strscan_matched_size (VALUE self)
 
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_aref (VALUE self, VALUE idx)
 
static VALUE strscan_pre_match (VALUE self)
 
static VALUE strscan_post_match (VALUE self)
 
static VALUE strscan_rest (VALUE self)
 
static VALUE strscan_rest_size (VALUE self)
 
static VALUE strscan_restsize (VALUE self)
 
static VALUE strscan_inspect (VALUE self)
 
static VALUE inspect1 (struct strscanner *p)
 
static VALUE inspect2 (struct strscanner *p)
 
void Init_strscan (void)
 

Variables

static VALUE StringScanner
 
static VALUE ScanError
 
static ID id_byteslice
 
static const rb_data_type_t strscanner_type
 

Macro Definition Documentation

◆ CLEAR_MATCH_STATUS

#define CLEAR_MATCH_STATUS (   s)    (s)->flags &= ~FLAG_MATCHED

◆ CURPTR

#define CURPTR (   s)    (S_PBEG(s) + (s)->curr)

Definition at line 53 of file strscan.c.

Referenced by inspect1(), inspect2(), strscan_bol_p(), strscan_do_scan(), and strscan_getch().

◆ EOS_P

#define EOS_P (   s)    ((s)->curr >= RSTRING_LEN(p->str))

◆ FLAG_MATCHED

#define FLAG_MATCHED   (1 << 0)

Definition at line 30 of file strscan.c.

◆ GET_SCANNER

#define GET_SCANNER (   obj,
  var 
)
Value:
do {\
(var) = check_strscan(obj);\
if (NIL_P((var)->str)) rb_raise(rb_eArgError, "uninitialized StringScanner object");\
} while (0)
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2207
static struct strscanner * check_strscan(VALUE obj)
Definition: strscan.c:231
#define NIL_P(v)
Definition: ruby.h:451
VALUE rb_eArgError
Definition: error.c:763

Definition at line 58 of file strscan.c.

Referenced by strscan_aref(), strscan_bol_p(), strscan_concat(), strscan_do_scan(), strscan_eos_p(), strscan_get_byte(), strscan_get_charpos(), strscan_get_pos(), strscan_get_string(), strscan_getch(), strscan_matched(), strscan_matched_p(), strscan_matched_size(), strscan_peek(), strscan_post_match(), strscan_pre_match(), strscan_reset(), strscan_rest(), strscan_rest_p(), strscan_rest_size(), strscan_set_pos(), strscan_terminate(), and strscan_unscan().

◆ INSPECT_LENGTH

#define INSPECT_LENGTH   5

Definition at line 1137 of file strscan.c.

Referenced by inspect1(), and inspect2().

◆ MATCHED

#define MATCHED (   s)    (s)->flags |= FLAG_MATCHED

Definition at line 47 of file strscan.c.

Referenced by strscan_do_scan(), strscan_get_byte(), and strscan_getch().

◆ MATCHED_P

#define MATCHED_P (   s)    ((s)->flags & FLAG_MATCHED)

◆ S_LEN

#define S_LEN (   s)    (RSTRING_LEN((s)->str))

◆ S_PBEG

#define S_PBEG (   s)    (RSTRING_PTR((s)->str))

Definition at line 50 of file strscan.c.

Referenced by extract_beg_len(), and extract_range().

◆ S_PEND

#define S_PEND (   s)    (S_PBEG(s) + S_LEN(s))

Definition at line 52 of file strscan.c.

Referenced by strscan_bol_p(), and strscan_getch().

◆ S_RESTLEN

#define S_RESTLEN (   s)    (S_LEN(s) - (s)->curr)

Definition at line 54 of file strscan.c.

Referenced by inspect2(), strscan_do_scan(), strscan_getch(), strscan_peek(), and strscan_rest_size().

◆ STRSCAN_VERSION

#define STRSCAN_VERSION   "0.7.0"

Definition at line 16 of file strscan.c.

Referenced by Init_strscan().

Function Documentation

◆ _() [1/19]

static long minl _ ( (const long n, const long x)  )
inlinestatic

◆ _() [2/19]

static VALUE infect _ ( (VALUE str, struct strscanner *p)  )
static

◆ _() [3/19]

static VALUE extract_range _ ( (struct strscanner *p, long beg_i, long end_i)  )
static

◆ _() [4/19]

static VALUE extract_beg_len _ ( (struct strscanner *p, long beg_i, long len )
static

◆ _() [5/19]

static struct strscanner* check_strscan _ ( (VALUE obj)  )
static

◆ _() [6/19]

static void strscan_free _ ( (void *p)  )
static

◆ _() [7/19]

static size_t strscan_memsize _ ( (const void *p)  )
static

◆ _() [8/19]

static VALUE strscan_s_allocate _ ( (VALUE klass)  )
static

◆ _() [9/19]

static VALUE strscan_initialize _ ( (int argc, VALUE *argv, VALUE self)  )
static

◆ _() [10/19]

static VALUE strscan_init_copy _ ( (VALUE vself, VALUE vorig)  )
static

◆ _() [11/19]

static VALUE strscan_inspect _ ( (VALUE self)  )
static

◆ _() [12/19]

static VALUE strscan_concat _ ( (VALUE self, VALUE str)  )
static

◆ _() [13/19]

static VALUE strscan_set_pos _ ( (VALUE self, VALUE pos)  )
static

◆ _() [14/19]

static VALUE strscan_do_scan _ ( (VALUE self, VALUE regex, int succptr, int getstr, int headonly)  )
static

◆ _() [15/19]

static VALUE strscan_check_until _ ( (VALUE self, VALUE re)  )
static

◆ _() [16/19]

static VALUE strscan_search_full _ ( (VALUE self, VALUE re, VALUE succp, VALUE getp)  )
static

◆ _() [17/19]

static VALUE inspect2 _ ( (struct strscanner *p)  )
static

◆ _() [18/19]

static VALUE strscan_peep _ ( (VALUE self, VALUE len )
static

◆ _() [19/19]

static VALUE strscan_aref _ ( (VALUE self, VALUE idx)  )
static

◆ adjust_registers_to_matched()

static void adjust_registers_to_matched ( struct strscanner p)
static

◆ check_strscan()

static struct strscanner* check_strscan ( VALUE  obj)
static

◆ extract_beg_len()

static VALUE extract_beg_len ( struct strscanner p,
long  beg_i,
long  len 
)
static

Definition at line 159 of file strscan.c.

References infect(), minl(), Qnil, S_LEN, S_PBEG, and str_new().

Referenced by strscan_do_scan(), and strscan_peek().

◆ extract_range()

static VALUE extract_range ( struct strscanner p,
long  beg_i,
long  end_i 
)
static

◆ infect()

static VALUE infect ( VALUE  str,
struct strscanner p 
)
static

Definition at line 130 of file strscan.c.

References OBJ_INFECT, and strscanner::str.

Referenced by extract_beg_len(), extract_range(), strscan_inspect(), strscan_peek(), and strscan_rest().

◆ Init_strscan()

void Init_strscan ( void  )

◆ inspect1()

static VALUE inspect1 ( struct strscanner p)
static

◆ inspect2()

static VALUE inspect2 ( struct strscanner p)
static

◆ minl()

static long minl ( const long  x,
const long  y 
)
inlinestatic

Definition at line 145 of file strscan.c.

Referenced by extract_beg_len(), extract_range(), strscan_getch(), and strscan_peek().

◆ name_to_backref_number()

static int name_to_backref_number ( struct re_registers regs,
VALUE  regexp,
const char *  name,
const char *  name_end,
rb_encoding enc 
)
static

◆ str_new()

static VALUE str_new ( struct strscanner p,
const char *  ptr,
long  len 
)
static

Definition at line 137 of file strscan.c.

References rb_enc_copy(), rb_str_new(), and strscanner::str.

Referenced by extract_beg_len(), extract_range(), strscan_peek(), and strscan_rest().

◆ strscan_aref()

static VALUE strscan_aref ( VALUE  self,
VALUE  idx 
)
static

◆ strscan_bol_p()

static VALUE strscan_bol_p ( VALUE  self)
static

Definition at line 865 of file strscan.c.

References CURPTR, strscanner::curr, GET_SCANNER, Qfalse, Qnil, Qtrue, and S_PEND.

Referenced by Init_strscan().

◆ strscan_check()

static VALUE strscan_check ( VALUE  self,
VALUE  re 
)
static

Definition at line 589 of file strscan.c.

References strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_check_until()

static VALUE strscan_check_until ( VALUE  self,
VALUE  re 
)
static

Definition at line 683 of file strscan.c.

References strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_clear()

static VALUE strscan_clear ( VALUE  self)
static

Definition at line 315 of file strscan.c.

References rb_warning(), and strscan_terminate().

Referenced by Init_strscan().

◆ strscan_concat()

static VALUE strscan_concat ( VALUE  self,
VALUE  str 
)
static

Definition at line 366 of file strscan.c.

References GET_SCANNER, rb_str_append(), strscanner::str, and StringValue.

Referenced by Init_strscan().

◆ strscan_do_scan()

static VALUE strscan_do_scan ( VALUE  self,
VALUE  regex,
int  succptr,
int  getstr,
int  headonly 
)
static

◆ strscan_empty_p()

static VALUE strscan_empty_p ( VALUE  self)
static

Definition at line 899 of file strscan.c.

References rb_warning(), and strscan_eos_p().

Referenced by Init_strscan().

◆ strscan_eos_p()

static VALUE strscan_eos_p ( VALUE  self)
static

Definition at line 886 of file strscan.c.

References EOS_P, GET_SCANNER, Qfalse, and Qtrue.

Referenced by Init_strscan(), and strscan_empty_p().

◆ strscan_exist_p()

static VALUE strscan_exist_p ( VALUE  self,
VALUE  re 
)
static

Definition at line 642 of file strscan.c.

References strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_free()

static void strscan_free ( void *  ptr)
static

Definition at line 178 of file strscan.c.

References onig_region_free(), strscanner::regs, and ruby_xfree().

◆ strscan_get_byte()

static VALUE strscan_get_byte ( VALUE  self)
static

◆ strscan_get_charpos()

static VALUE strscan_get_charpos ( VALUE  self)
static

◆ strscan_get_pos()

static VALUE strscan_get_pos ( VALUE  self)
static

Definition at line 391 of file strscan.c.

References strscanner::curr, GET_SCANNER, and INT2FIX.

Referenced by Init_strscan().

◆ strscan_get_string()

static VALUE strscan_get_string ( VALUE  self)
static

Definition at line 325 of file strscan.c.

References GET_SCANNER, and strscanner::str.

Referenced by Init_strscan().

◆ strscan_getbyte()

static VALUE strscan_getbyte ( VALUE  self)
static

Definition at line 784 of file strscan.c.

References rb_warning(), and strscan_get_byte().

Referenced by Init_strscan().

◆ strscan_getch()

static VALUE strscan_getch ( VALUE  self)
static

◆ strscan_init_copy()

static VALUE strscan_init_copy ( VALUE  vself,
VALUE  vorig 
)
static

◆ strscan_initialize()

static VALUE strscan_initialize ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 217 of file strscan.c.

References check_strscan(), rb_scan_args(), strscanner::str, and StringValue.

Referenced by Init_strscan().

◆ strscan_inspect()

static VALUE strscan_inspect ( VALUE  self)
static

◆ strscan_mark()

static void strscan_mark ( void *  ptr)
static

Definition at line 171 of file strscan.c.

References rb_gc_mark(), and strscanner::str.

◆ strscan_match_p()

static VALUE strscan_match_p ( VALUE  self,
VALUE  re 
)
static

Definition at line 545 of file strscan.c.

References strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_matched()

static VALUE strscan_matched ( VALUE  self)
static

◆ strscan_matched_p()

static VALUE strscan_matched_p ( VALUE  self)
static

Definition at line 932 of file strscan.c.

References GET_SCANNER, MATCHED_P, Qfalse, and Qtrue.

Referenced by Init_strscan().

◆ strscan_matched_size()

static VALUE strscan_matched_size ( VALUE  self)
static

Definition at line 969 of file strscan.c.

References re_registers::beg, re_registers::end, GET_SCANNER, INT2NUM, MATCHED_P, Qnil, and strscanner::regs.

Referenced by Init_strscan().

◆ strscan_memsize()

static size_t strscan_memsize ( const void *  ptr)
static

Definition at line 186 of file strscan.c.

References onig_region_memsize(), and strscanner::regs.

◆ strscan_peek()

static VALUE strscan_peek ( VALUE  self,
VALUE  vlen 
)
static

Definition at line 802 of file strscan.c.

References strscanner::curr, EOS_P, extract_beg_len(), GET_SCANNER, infect(), len, minl(), NUM2LONG, S_RESTLEN, and str_new().

Referenced by Init_strscan(), and strscan_peep().

◆ strscan_peep()

static VALUE strscan_peep ( VALUE  self,
VALUE  vlen 
)
static

Definition at line 822 of file strscan.c.

References rb_warning(), and strscan_peek().

Referenced by Init_strscan().

◆ strscan_post_match()

static VALUE strscan_post_match ( VALUE  self)
static

◆ strscan_pre_match()

static VALUE strscan_pre_match ( VALUE  self)
static

◆ strscan_reset()

static VALUE strscan_reset ( VALUE  self)
static

Definition at line 282 of file strscan.c.

References CLEAR_MATCH_STATUS, strscanner::curr, and GET_SCANNER.

Referenced by Init_strscan().

◆ strscan_rest()

static VALUE strscan_rest ( VALUE  self)
static

Definition at line 1098 of file strscan.c.

References strscanner::curr, EOS_P, extract_range(), GET_SCANNER, infect(), S_LEN, and str_new().

Referenced by Init_strscan().

◆ strscan_rest_p()

static VALUE strscan_rest_p ( VALUE  self)
static

Definition at line 914 of file strscan.c.

References EOS_P, GET_SCANNER, Qfalse, and Qtrue.

Referenced by Init_strscan().

◆ strscan_rest_size()

static VALUE strscan_rest_size ( VALUE  self)
static

Definition at line 1113 of file strscan.c.

References EOS_P, GET_SCANNER, INT2FIX, and S_RESTLEN.

Referenced by Init_strscan(), and strscan_restsize().

◆ strscan_restsize()

static VALUE strscan_restsize ( VALUE  self)
static

Definition at line 1131 of file strscan.c.

References rb_warning(), and strscan_rest_size().

Referenced by Init_strscan().

◆ strscan_s_allocate()

static VALUE strscan_s_allocate ( VALUE  klass)
static

◆ strscan_s_mustc()

static VALUE strscan_s_mustc ( VALUE  self)
static

Definition at line 273 of file strscan.c.

Referenced by Init_strscan().

◆ strscan_scan()

static VALUE strscan_scan ( VALUE  self,
VALUE  re 
)
static

Definition at line 528 of file strscan.c.

References strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_scan_full()

static VALUE strscan_scan_full ( VALUE  self,
VALUE  re,
VALUE  s,
VALUE  f 
)
static

Definition at line 605 of file strscan.c.

References RTEST, and strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_scan_until()

static VALUE strscan_scan_until ( VALUE  self,
VALUE  re 
)
static

Definition at line 623 of file strscan.c.

References strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_search_full()

static VALUE strscan_search_full ( VALUE  self,
VALUE  re,
VALUE  s,
VALUE  f 
)
static

Definition at line 698 of file strscan.c.

References RTEST, and strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_set_pos()

static VALUE strscan_set_pos ( VALUE  self,
VALUE  v 
)
static

Definition at line 435 of file strscan.c.

References strscanner::curr, GET_SCANNER, INT2NUM, NUM2INT, rb_eRangeError, rb_raise(), and S_LEN.

Referenced by Init_strscan().

◆ strscan_set_string()

static VALUE strscan_set_string ( VALUE  self,
VALUE  str 
)
static

Definition at line 340 of file strscan.c.

References check_strscan(), CLEAR_MATCH_STATUS, strscanner::curr, strscanner::str, and StringValue.

Referenced by Init_strscan().

◆ strscan_skip()

static VALUE strscan_skip ( VALUE  self,
VALUE  re 
)
static

Definition at line 568 of file strscan.c.

References strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_skip_until()

static VALUE strscan_skip_until ( VALUE  self,
VALUE  re 
)
static

Definition at line 664 of file strscan.c.

References strscan_do_scan().

Referenced by Init_strscan().

◆ strscan_terminate()

static VALUE strscan_terminate ( VALUE  self)
static

Definition at line 300 of file strscan.c.

References CLEAR_MATCH_STATUS, strscanner::curr, GET_SCANNER, and S_LEN.

Referenced by Init_strscan(), and strscan_clear().

◆ strscan_unscan()

static VALUE strscan_unscan ( VALUE  self)
static

Variable Documentation

◆ id_byteslice

ID id_byteslice
static

Definition at line 24 of file strscan.c.

Referenced by Init_strscan(), and strscan_get_charpos().

◆ ScanError

VALUE ScanError
static

Definition at line 23 of file strscan.c.

Referenced by Init_strscan(), strscan_do_scan(), and strscan_unscan().

◆ StringScanner

VALUE StringScanner
static

Definition at line 22 of file strscan.c.

Referenced by Init_strscan().

◆ strscanner_type

const rb_data_type_t strscanner_type
static
Initial value:
= {
"StringScanner",
}
static size_t strscan_memsize(const void *ptr)
Definition: strscan.c:186
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1145
static void strscan_mark(void *ptr)
Definition: strscan.c:171
static void strscan_free(void *ptr)
Definition: strscan.c:178

Definition at line 192 of file strscan.c.