IO_METHOD(IoSeq, replaceFirstSeq) { /*doc Sequence replaceFirstSeq(aSequence, anotherSequence, optionalStartIndex) Returns a new Sequence with the first occurance of aSequence replaced with anotherSequence in the receiver. If optionalStartIndex is provided, the search for aSequence begins at that index. Returns self. */ IoSeq *subSeq = IoMessage_locals_seqArgAt_(m, locals, 0); IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 1); size_t startIndex = 0; if (IoMessage_argCount(m) > 2) { startIndex = IoMessage_locals_longArgAt_(m, locals, 2); } IO_ASSERT_NOT_SYMBOL(self); { UArray *a = DATA(self); UArray *b = DATA(subSeq); UArray *c = DATA(otherSeq); long i = UArray_find_from_(a, b, startIndex); if(i != -1) { UArray_removeRange(a, i, UArray_size(b)); UArray_at_putAll_(a, i, c); } } return self; }
IO_METHOD(IoSeq, atInsertSeq) { /*doc Sequence atInsertSeq(indexNumber, object) Calls asString on object and inserts the string at position indexNumber. Returns self. */ size_t n = IoMessage_locals_sizetArgAt_(m, locals, 0); IoSeq *otherSeq = IoMessage_locals_valueAsStringArgAt_(m, locals, 1); IO_ASSERT_NOT_SYMBOL(self); IOASSERT(n <= UArray_size(DATA(self)), "insert index out of sequence bounds"); UArray_at_putAll_(DATA(self), n, DATA(otherSeq)); return self; }
void UArray_replaceAnyCase_with_(UArray *self, const UArray *a1, const UArray *a2) { long i; size_t start = 0; UArray visible = UArray_stackRange(self, start, self->size); while ((i = UArray_findAnyCase_(&visible, a1)) != -1) { size_t index = start + i; UArray_removeRange(self, index, a1->size); UArray_at_putAll_(self, index, a2); start = index + a2->size; visible = UArray_stackRange(self, start, self->size - start); } UArray_changed(self); }
void UArray_prepend_(UArray *self, const UArray *other) { UArray_at_putAll_(self, 0, other); }
void UArray_append_(UArray *self, const UArray *other) { UArray_at_putAll_(self, self->size, other); }