Class: Ragel::Array
- Inherits:
-
Object
- Object
- Ragel::Array
- Defined in:
- lib/ragel/array.rb,
lib/ragel/array/replace.rb,
lib/ragel/array/version.rb,
ext/ragel/array/ragel_array.c
Defined Under Namespace
Classes: Replace
Constant Summary collapse
- VERSION =
'0.1.1'
Class Method Summary collapse
Instance Method Summary collapse
Constructor Details
#initialize(rb_string, rb_size) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'ext/ragel/array/ragel_array.c', line 19
static VALUE ragel_array_initialize(VALUE self, VALUE rb_string, VALUE rb_size) {
Check_Type(rb_string, T_STRING);
Check_Type(rb_size, T_FIXNUM);
ragel_array_t *array;
Data_Get_Struct(self, ragel_array_t, array);
long size = FIX2LONG(rb_size);
array->data = calloc(size, sizeof(uint32_t));
array->size = size;
char *string = StringValueCStr(rb_string);
long length = RSTRING_LEN(rb_string);
char buffer[5];
for (long data_index = 0, num_start = 0, num_end = 0; data_index < size; data_index += 1) {
while (string[num_end++] != ' ' && num_end < length);
strncpy(buffer, string + num_start, num_end - num_start);
array->data[data_index] = (uint32_t) atoi(buffer);
num_start = num_end;
}
return self;
}
|
Class Method Details
Instance Method Details
#[](rb_index) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'ext/ragel/array/ragel_array.c', line 45
static VALUE ragel_array_get(VALUE self, VALUE rb_index) {
Check_Type(rb_index, T_FIXNUM);
ragel_array_t *array;
Data_Get_Struct(self, ragel_array_t, array);
long index = FIX2LONG(rb_index);
if (index < 0 || (unsigned) index >= array->size) {
return Qnil;
}
return LONG2FIX(array->data[index]);
}
|