Class: MiniHTML::Scanner
- Inherits:
-
Object
- Object
- MiniHTML::Scanner
- Defined in:
- ext/minihtml_scanner/minihtml_scanner.c
Instance Method Summary collapse
- #eof? ⇒ Boolean
- #errors ⇒ Object
- #initialize(str) ⇒ Object constructor
- #stats ⇒ Object
- #tokenize ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize(str) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'ext/minihtml_scanner/minihtml_scanner.c', line 141
static VALUE scanner_initialize(VALUE self, VALUE str) {
Check_Type(str, T_STRING);
scanner_t *t;
TypedData_Get_Struct(self, scanner_t, &scanner_type, t);
str = rb_str_dup(str);
t->str = str;
t->p = (const uint8_t *) RSTRING_PTR(str);
t->end = t->p + RSTRING_LEN(str);
t->idx_cp = 0;
t->tokens = rb_ary_new();
t->errors = rb_ary_new();
t->line = 1;
t->col = 1;
// prime lookahead
t->look[0] = next_utf8_cp(&t->p, t->end);
t->look[1] = next_utf8_cp(&t->p, t->end);
t->look[2] = next_utf8_cp(&t->p, t->end);
t->look[3] = next_utf8_cp(&t->p, t->end);
return self;
}
|
Instance Method Details
#eof? ⇒ Boolean
488 489 490 491 492 |
# File 'ext/minihtml_scanner/minihtml_scanner.c', line 488
static VALUE scanner_at_eof(const VALUE self) {
scanner_t *t;
TypedData_Get_Struct(self, scanner_t, &scanner_type, t);
return t->look[0] == EOF ? Qtrue : Qfalse;
}
|
#errors ⇒ Object
472 473 474 475 476 |
# File 'ext/minihtml_scanner/minihtml_scanner.c', line 472
static VALUE scanner_errors(const VALUE self) {
scanner_t *t;
TypedData_Get_Struct(self, scanner_t, &scanner_type, t);
return t->errors;
}
|
#stats ⇒ Object
478 479 480 481 482 483 484 485 486 |
# File 'ext/minihtml_scanner/minihtml_scanner.c', line 478
static VALUE scanner_stats(const VALUE self) {
scanner_t *t;
TypedData_Get_Struct(self, scanner_t, &scanner_type, t);
const VALUE h = rb_hash_new();
rb_hash_aset(h, sym_line, LONG2NUM(t->line));
rb_hash_aset(h, sym_column, LONG2NUM(t->col));
rb_hash_aset(h, sym_offset, LONG2NUM(t->idx_cp));
return h;
}
|
#tokenize ⇒ Object
508 509 510 511 512 513 514 515 516 |
# File 'ext/minihtml_scanner/minihtml_scanner.c', line 508
static VALUE scanner_tokenize(const VALUE self) {
scanner_t *t;
TypedData_Get_Struct(self, scanner_t, &scanner_type, t);
while (t->look[0] != EOF) {
scanner_scan_token(t);
}
scanner_hydrate_tokens(t);
return t->tokens;
}
|
#tokens ⇒ Object
466 467 468 469 470 |
# File 'ext/minihtml_scanner/minihtml_scanner.c', line 466
static VALUE scanner_tokens(const VALUE self) {
scanner_t *t;
TypedData_Get_Struct(self, scanner_t, &scanner_type, t);
return t->tokens;
}
|