Class: NSAttributedString

Inherits:
Object show all
Defined in:
ext/accessibility/bridge/bridge.c,
ext/accessibility/bridge/bridge.c

Overview

A 90% drop-in replacement for Cocoa's NSAttributedString class. The most likely to use methods have been bridged. Remaining methods can be bridged upon request.

See Apple's Developer Reference for documentation on the methods available in this class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allocObject

LOL, but required to be a drop-in replacement



332
333
334
335
336
337
# File 'ext/accessibility/bridge/bridge.c', line 332

static
VALUE
rb_astring_alloc(const VALUE self)
{
  return wrap_nsattributed_string([NSAttributedString alloc]);
}

Instance Method Details

#initWithString(, self) ⇒ Object



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'ext/accessibility/bridge/bridge.c', line 339

static
VALUE
rb_astring_init_with_string(const int argc, VALUE* const argv, const VALUE self)
{
    if (!argc)
        rb_raise(rb_eArgError, "wrong number of arguments (0 for 1+)");

    NSString* const              nsstring =
        unwrap_nsstring(argv[0]);
    NSAttributedString* const old_astring =
        unwrap_nsattributed_string(self);
    NSAttributedString* const new_astring =
        [old_astring initWithString:nsstring];
    [nsstring release];

    if (old_astring == new_astring)
        return self;
    return wrap_nsattributed_string(new_astring);
}

#isEqualToAttributedString(other) ⇒ Object Also known as: ==

rb_define_method(rb_cAttributedString, "attributesAtIndex", rb_astring_attrs_at_index, -1);



375
376
377
378
379
380
# File 'ext/accessibility/bridge/bridge.c', line 375

static
VALUE
rb_astring_equality(const VALUE self, const VALUE other)
{
  OBJC_EQUALITY(rb_cAttributedString, unwrap_nsattributed_string);
}

#lengthObject



368
369
370
371
372
373
# File 'ext/accessibility/bridge/bridge.c', line 368

static
VALUE
rb_astring_length(const VALUE self)
{
  return ULONG2NUM([unwrap_nsattributed_string(self) length]);
}

#stringObject Also known as: to_s, to_str

rb_define_method(rb_cAttributedString, "initWithAttributedString", rb_astring_init_with_astring, 2);



359
360
361
362
363
364
365
366
# File 'ext/accessibility/bridge/bridge.c', line 359

static
VALUE
rb_astring_string(const VALUE self)
{
    NSString* const string = [unwrap_nsattributed_string(self) string];
    const VALUE     rb_str = wrap_nsstring(string);
    return rb_str;
}