Class: LibLouis::BrailleText
- Inherits:
-
Object
- Object
- LibLouis::BrailleText
- Includes:
- Enumerable
- Defined in:
- ext/liblouis/braille_text.c
Instance Attribute Summary collapse
- #characters ⇒ Object readonly
- #cursor_position ⇒ Object readonly
- #input_positions ⇒ Object readonly
- #output_positions ⇒ Object readonly
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](*args) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #inspect ⇒ Object
- #length ⇒ Object (also: #size)
- #unicode_text ⇒ Object (also: #to_s)
Constructor Details
#initialize(*args) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'ext/liblouis/braille_text.c', line 41
static VALUE
ll_text_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE input = Qnil;
VALUE characters = rb_ary_new();
long index;
rb_scan_args(argc, argv, "01", &input);
if (RB_TYPE_P(input, T_STRING)) {
int length;
VALUE storage = ll_wide_storage_from_string(input, &length);
for (index = 0; index < length; index++) {
unsigned int codepoint = LL_PTR(widechar, storage)[index];
if (codepoint < 0x2800 || codepoint > 0x28ff)
rb_raise(rb_eArgError,
"BrailleText strings may contain only Unicode braille characters");
rb_ary_push(characters, ll_character_new((uint8_t)(codepoint - 0x2800)));
}
} else if (!NIL_P(input)) {
Check_Type(input, T_ARRAY);
for (index = 0; index < RARRAY_LEN(input); index++)
rb_ary_push(characters, ll_character_from_input(rb_ary_entry(input, index)));
}
return ll_text_finish(self, characters, Qnil, Qnil, Qnil);
}
|
Instance Attribute Details
#characters ⇒ Object (readonly)
#cursor_position ⇒ Object (readonly)
#input_positions ⇒ Object (readonly)
#output_positions ⇒ Object (readonly)
Instance Method Details
#==(other) ⇒ Object
178 179 180 181 182 183 |
# File 'ext/liblouis/braille_text.c', line 178
static VALUE
ll_text_equal(VALUE self, VALUE other)
{
return ll_braille_text_p(other) &&
rb_equal(ll_text_characters(self), ll_text_characters(other)) ? Qtrue : Qfalse;
}
|
#[](*args) ⇒ Object
159 160 161 162 163 |
# File 'ext/liblouis/braille_text.c', line 159
static VALUE
ll_text_aref(int argc, VALUE *argv, VALUE self)
{
return rb_ary_aref(argc, argv, ll_text_characters(self));
}
|
#each ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'ext/liblouis/braille_text.c', line 165
static VALUE
ll_text_each(VALUE self)
{
VALUE characters;
long index;
RETURN_ENUMERATOR(self, 0, NULL);
characters = ll_text_characters(self);
for (index = 0; index < RARRAY_LEN(characters); index++)
rb_yield(rb_ary_entry(characters, index));
return self;
}
|
#empty? ⇒ Boolean
153 154 155 156 157 |
# File 'ext/liblouis/braille_text.c', line 153
static VALUE
ll_text_empty_p(VALUE self)
{
return RARRAY_LEN(ll_text_characters(self)) == 0 ? Qtrue : Qfalse;
}
|
#eql?(other) ⇒ Boolean
178 179 180 181 182 183 |
# File 'ext/liblouis/braille_text.c', line 178
static VALUE
ll_text_equal(VALUE self, VALUE other)
{
return ll_braille_text_p(other) &&
rb_equal(ll_text_characters(self), ll_text_characters(other)) ? Qtrue : Qfalse;
}
|
#hash ⇒ Object
185 186 187 188 189 |
# File 'ext/liblouis/braille_text.c', line 185
static VALUE
ll_text_hash(VALUE self)
{
return rb_hash(ll_text_characters(self));
}
|
#inspect ⇒ Object
191 192 193 194 195 |
# File 'ext/liblouis/braille_text.c', line 191
static VALUE
ll_text_inspect(VALUE self)
{
return rb_sprintf("#<LibLouis::BrailleText %"PRIsVALUE">", ll_text_unicode(self));
}
|
#length ⇒ Object Also known as: size
147 148 149 150 151 |
# File 'ext/liblouis/braille_text.c', line 147
static VALUE
ll_text_length(VALUE self)
{
return LONG2NUM(RARRAY_LEN(ll_text_characters(self)));
}
|
#unicode_text ⇒ Object Also known as: to_s
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'ext/liblouis/braille_text.c', line 133
static VALUE
ll_text_unicode(VALUE self)
{
VALUE characters = ll_text_characters(self);
VALUE result = rb_enc_str_new(NULL, 0, rb_utf8_encoding());
long index;
for (index = 0; index < RARRAY_LEN(characters); index++)
rb_str_buf_append(result, rb_enc_uint_chr(
0x2800u + ll_character_mask(rb_ary_entry(characters, index)),
rb_utf8_encoding()));
return result;
}
|