Class: BioSyntax::Native::State
- Inherits:
-
Object
- Object
- BioSyntax::Native::State
- Defined in:
- ext/biosyntax/biosyntax_ext.c
Instance Method Summary collapse
- #colorize(line_value) ⇒ Object
- #format_id ⇒ Object
- #highlight(line_value) ⇒ Object
- #initialize(format_id_value) ⇒ Object constructor
- #line_no ⇒ Object
- #reset(*args) ⇒ Object
Constructor Details
#initialize(format_id_value) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/biosyntax/biosyntax_ext.c', line 83
static VALUE state_initialize(VALUE self, VALUE format_id_value) {
rb_biosyn_state_t *wrap = NULL;
biosyn_format_t format_id = format_id_from_value(format_id_value);
TypedData_Get_Struct(self, rb_biosyn_state_t, &state_type, wrap);
if (wrap->ptr) {
biosyn_state_free(wrap->ptr);
wrap->ptr = NULL;
}
wrap->ptr = biosyn_state_new(format_id);
if (!wrap->ptr) {
rb_raise(rb_eNoMemError, "could not allocate libbiosyntax state");
}
return self;
}
|
Instance Method Details
#colorize(line_value) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'ext/biosyntax/biosyntax_ext.c', line 261
static VALUE state_colorize(VALUE self, VALUE line_value) {
rb_biosyn_state_t *wrap = get_state(self);
span_buffer_t buf;
colorize_args_t args;
VALUE line = StringValue(line_value);
long len = RSTRING_LEN(line);
if (len < 0) {
rb_raise(rb_eArgError, "line is too large");
}
highlight_into_buffer(wrap->ptr, RSTRING_PTR(line), (uint64_t)len, &buf);
args.line = line;
args.buf = &buf;
return rb_ensure(state_colorize_body, (VALUE)&args, free_span_buffer, (VALUE)&buf);
}
|
#format_id ⇒ Object
121 122 123 124 |
# File 'ext/biosyntax/biosyntax_ext.c', line 121
static VALUE state_format_id(VALUE self) {
rb_biosyn_state_t *wrap = get_state(self);
return UINT2NUM(wrap->ptr->format);
}
|
#highlight(line_value) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'ext/biosyntax/biosyntax_ext.c', line 216
static VALUE state_highlight(VALUE self, VALUE line_value) {
rb_biosyn_state_t *wrap = get_state(self);
span_buffer_t buf;
VALUE line = StringValue(line_value);
long len = RSTRING_LEN(line);
if (len < 0) {
rb_raise(rb_eArgError, "line is too large");
}
highlight_into_buffer(wrap->ptr, RSTRING_PTR(line), (uint64_t)len, &buf);
return rb_ensure(state_highlight_body, (VALUE)&buf, free_span_buffer, (VALUE)&buf);
}
|
#line_no ⇒ Object
116 117 118 119 |
# File 'ext/biosyntax/biosyntax_ext.c', line 116
static VALUE state_line_no(VALUE self) {
rb_biosyn_state_t *wrap = get_state(self);
return ULL2NUM((unsigned long long)wrap->ptr->line_no);
}
|
#reset(*args) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'ext/biosyntax/biosyntax_ext.c', line 101
static VALUE state_reset(int argc, VALUE *argv, VALUE self) {
rb_biosyn_state_t *wrap = get_state(self);
biosyn_format_t format_id = wrap->ptr->format;
if (argc > 1) {
rb_error_arity(argc, 0, 1);
}
if (argc == 1 && !NIL_P(argv[0])) {
format_id = format_id_from_value(argv[0]);
}
biosyn_state_init(wrap->ptr, format_id);
return self;
}
|