---
name: "RunArray"
section: "3poc"
platform: "linux"
package: "objc-poc"
version: "3.1.26-2"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/RunArray/3poc"
---

# RunArray(3poc)

Portable Object Compiler RunArray class

## NAME

RunArray - Portable Object Compiler RunArray class

## RunArray

**Inherits from:**

Cltn

**Maturity Index:**

Experimental

## Class Description

This class is used by the  **Text** class, to associate lists of  **TextAttribute** instances, to segments of characters in a string (slices of text with the same formatting properties, called  *runs* ).

## Accessing

A  **RunArray** is  *not* indexed by segment number.

Rather, it is indexed by character offsets : the message  **at:** or  **runLengthAt:** takes a character offset as argument, and translates this offset to a segment offset (the segment to which the character belongs) and returns the attributes or segment length, for that segment.

The  **size** of a  **RunArray** is the largest character offset plus one;it is not the number of segments.

## Method types

**Creation**

\* new\
 \* free

**Accessing**

\* values\
 \* runs\
 \* at:\
 \* runLengthAt:\
 \* size\
 \* addAttribute:from:size:\
 \* at:insert:count:\
 \* deleteFrom:to:\
 \* concat:\
 \* coalesce

**Printing**

\* printOn:

## Methods

new

\+ **new**

Creates an empty RunArray collection.

free

\- **free**

values

\- **values**

Returns a collection of OrdCltn instances (each element being a list of  **TextAttribute** instances).

runs

\- **runs**

Returns the run array (array of  *int* ).

at:

\- **at** :(unsigned) *i*

Returns a collection of TextAttributes for the  *i* -th character.

This method translates a character offset into a segment number.  The segment number is cached so that a subsequent call to  **at:** or  **runLengthAt:** doesn't have to recompute it.

runLengthAt:

\- ( unsigned ) **runLengthAt** :(unsigned) *i*

Returns the number of remaining characters in the string segment to which the character at position  *i* belongs.  If  *i* is the first character of a run, this method returns the size of the run.  Otherwise it returns the size minus the index of character in the run.

size

\- ( unsigned ) **size**

Returns the size of the RunArray, which is the same as the size of the String instance for this RunArray object.

The number of runs can be obtained by sending a  **size** message to the object returned by  **values** .

addAttribute:from:size:

\- **addAttribute** : *attrib* **from** :(unsigned) *p* **size** :(unsigned) *s*

Adds  *attrib* to the attribute lists for the  *s* characters from position  *p* .

**Note:**

This method is optimized for adding at the end of the RunArray.

at:insert:count:

\- **at** :(unsigned) *anOffset* **insert** :(char\*) *aString* **count** :(int) *n*

deleteFrom:to:

\- **deleteFrom** :(unsigned) *p* **to** :(unsigned) *q*

concat:

\- **concat** : *b*

coalesce

\- **coalesce**

Merges adjacent lists of TextAttribute instances, by testing whether they are equal (in the sense of  **TextAttribute** 's  **isEqual** method).

printOn:

\- **printOn** :(IOD) *aFile*

Prints the RunArray values.
